Commit 8bd7a50b authored by webchick's avatar webchick

Issue #2422481 by akalata, lokapujya, joelpittet: Convert language negotiation...

Issue #2422481 by akalata, lokapujya, joelpittet: Convert language negotiation theme table to table #type
parent 5a89e6af
......@@ -7,7 +7,6 @@
use Drupal\Core\Render\Element;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Url;
/**
* Prepares variables for language negotiation configuration form.
......@@ -94,55 +93,6 @@ function template_preprocess_language_negotiation_configure_form(&$variables) {
$variables['children'] = $form;
}
/**
* Theme browser configuration form as table.
*
* @param $variables
* An associative array containing:
* - form: A render element representing the form.
*
* @ingroup themeable
*/
function theme_language_negotiation_configure_browser_form_table($variables) {
$form = $variables['form'];
$rows = array();
foreach (Element::children($form, TRUE) as $key) {
$row = array();
$row[] = drupal_render($form[$key]['browser_langcode']);
$row[] = drupal_render($form[$key]['drupal_langcode']);
$links = array();
$links['delete'] = array(
'title' => t('Delete'),
'url' => Url::fromRoute('language.negotiation_browser_delete', ['browser_langcode' => $key]),
);
$row[] = array(
'data' => array(
'#type' => 'operations',
'#links' => $links,
),
);
$rows[] = $row;
}
$header = array(
t('Browser language code'),
t('Site language'),
t('Operations'),
);
$table = array(
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No browser language mappings available.'),
'#attributes' => array('id' => 'language-negotiation-browser'),
);
$output = drupal_render($table);
return $output;
}
/**
* Implements hook_preprocess_HOOK() for theme_language_content_settings_table().
*/
......
......@@ -105,11 +105,6 @@ function language_theme() {
'render element' => 'form',
'file' => 'language.admin.inc',
),
'language_negotiation_configure_browser_form_table' => array(
'render element' => 'form',
'file' => 'language.admin.inc',
'function' => 'theme_language_negotiation_configure_browser_form_table',
),
'language_content_settings_table' => array(
'render element' => 'element',
'file' => 'language.admin.inc',
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -87,10 +88,16 @@ public function buildForm(array $form, FormStateInterface $form_state) {
);
}
$form['mappings'] = array(
'#tree' => TRUE,
'#theme' => 'language_negotiation_configure_browser_form_table',
);
$form['mappings'] = [
'#type' => 'table',
'#header' => [
$this->t('Browser language code'),
$this->t('Site language'),
$this->t('Operations'),
],
'#attributes' => ['id' => 'language-negotiation-browser'],
'#empty' => $this->t('No browser language mappings available.'),
];
$mappings = $this->language_get_browser_drupal_langcode_mappings();
foreach ($mappings as $browser_langcode => $drupal_langcode) {
......@@ -112,6 +119,15 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#required' => TRUE,
),
);
// Operations column.
$form['mappings'][$browser_langcode]['operations'] = [
'#type' => 'operations',
'#links' => [],
];
$form['mappings'][$browser_langcode]['operations']['#links']['delete'] = [
'title' => $this->t('Delete'),
'url' => Url::fromRoute('language.negotiation_browser_delete', ['browser_langcode' => $browser_langcode]),
];
}
// Add empty row.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment