diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc
index e740342..cb83a58 100644
--- a/core/modules/language/language.admin.inc
+++ b/core/modules/language/language.admin.inc
@@ -6,6 +6,7 @@
*/
use Drupal\Core\Language\LanguageManager;
+use Drupal\Component\Utility\String;
/**
* Prepare a language code list for unused predefined languages.
@@ -165,71 +166,78 @@ function language_negotiation_configure_form_table(&$form, $type) {
}
/**
- * Returns HTML for the language negotiation configuration form.
+ * Prepares variables for language negotiation configuration form.
*
- * @param $variables
+ * Default template: language-content-configuration-form.html.twig.
+ *
+ * @param array $variables
* An associative array containing:
* - form: A render element representing the form.
- *
- * @ingroup themeable
*/
-function theme_language_negotiation_configure_form($variables) {
- $form = $variables['form'];
- $output = '';
+function template_preprocess_language_negotiation_configure_form(&$variables) {
+ $form =& $variables['form'];
+ $variables['language_types'] = array();
foreach ($form['#language_types'] as $type) {
- $rows = array();
- $title = '
' . $form[$type]['#title'] . '
';
- $description = '' . $form[$type]['#description'] . '
';
-
- foreach ($form[$type]['title'] as $id => $element) {
- // Do not take form control structures.
- if (is_array($element) && element_child($id)) {
- $row = array(
- 'data' => array(
- '' . drupal_render($form[$type]['title'][$id]) . '',
- drupal_render($form[$type]['description'][$id]),
- drupal_render($form[$type]['enabled'][$id]),
- drupal_render($form[$type]['weight'][$id]),
- ),
- 'class' => array('draggable'),
- );
- if ($form[$type]['#show_operations']) {
- $row['data'][] = drupal_render($form[$type]['operation'][$id]);
- }
- $rows[] = $row;
- }
- }
-
$header = array(
- array('data' => t('Detection method')),
- array('data' => t('Description')),
- array('data' => t('Enabled')),
- array('data' => t('Weight')),
+ t('Detection method'),
+ t('Description'),
+ t('Enabled'),
+ t('Weight'),
);
// If there is at least one operation enabled show the operation column.
if ($form[$type]['#show_operations']) {
- $header[] = array('data' => t('Operations'));
+ $header[] = t('Operations');
}
- $build = array(
- '#theme' => 'table',
+ $table = array(
+ '#type' => 'table',
'#header' => $header,
- '#rows' => $rows,
- '#attributes' => array('id' => "language-negotiation-methods-$type"),
+ '#attributes' => array('id' => 'language-negotiation-methods-' . $type),
+ '#tabledrag' => array(
+ array('order', 'sibling', 'language-method-weight-' . $type),
+ ),
);
- $table = drupal_render($form[$type]['configurable']);
- $table .= drupal_render($build);
- $table .= drupal_render_children($form[$type]);
- drupal_add_tabledrag("language-negotiation-methods-$type", 'order', 'sibling', "language-method-weight-$type");
+ foreach ($form[$type]['title'] as $id => $element) {
+ // Do not take form control structures.
+ if (is_array($element) && element_child($id)) {
+ $table[$id]['#attributes']['class'][] = 'draggable';
+ $table[$id]['#weight'] = $element['#weight'];
+
+ $table[$id]['title'] = array(
+ '#prefix' => '',
+ $form[$type]['title'][$id],
+ '#suffix' => '',
+ );
+ $table[$id]['description'] = $form[$type]['description'][$id];
+ $table[$id]['enabled'] = $form[$type]['enabled'][$id];
+ $table[$id]['weight'] = $form[$type]['weight'][$id];
+ if ($form[$type]['#show_operations']) {
+ $table[$id]['operation'] = $form[$type]['operation'][$id];
+ }
+ // Unset so we don't print them along with children as well.
+ unset($form[$type]['title'][$id]);
+ unset($form[$type]['description'][$id]);
+ unset($form[$type]['enabled'][$id]);
+ unset($form[$type]['weight'][$id]);
+ unset($form[$type]['operation'][$id]);
+ }
+ }
- $output .= '' . $title . $description . $table . '
';
+ $variables['language_types'][] = array(
+ 'type' => $type,
+ 'title' => $form[$type]['#title'],
+ 'description' => $form[$type]['#description'],
+ 'configurable' => isset($form[$type]['configurable']) ? $form[$type]['configurable'] : NULL,
+ 'table' => $table,
+ 'children' => $form[$type],
+ );
+ unset($form[$type]);
}
- $output .= drupal_render_children($form);
- return $output;
+ $variables['children'] = $form;
}
/**
@@ -286,57 +294,6 @@ function language_negotiation_configure_form_submit($form, &$form_state) {
}
/**
- * 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'),
- 'href' => "admin/config/regional/language/detection/browser/delete/$key",
- 'attributes' => array(
- 'class' => array('image-style-link'),
- ),
- );
- $row[] = array(
- 'data' => array(
- '#type' => 'operations',
- '#links' => $links,
- ),
- );
-
- $rows[] = $row;
- }
-
- $header = array(
- t('Browser language code'),
- t('Drupal language'),
- t('Operations'),
- );
-
- $table = array(
- '#theme' => 'table',
- '#header' => $header,
- '#rows' => $rows,
- '#attributes' => array('id' => 'lang-neg-browser'),
- );
- $output = drupal_render($table);
-
- return $output;
-}
-
-/**
* Returns the content language settings form.
*
* @deprecated Use \Drupal\language\Controller\LanguageController::contentSettings()
@@ -435,64 +392,45 @@ function language_content_settings_form(array $form, array $form_state, array $s
}
/**
- * Implements hook_preprocess_HOOK() for theme_language_content_settings_table().
+ * Prepares variables for language content settings table templates.
+ *
+ * Default template: language-content-settings-table.html.twig.
+ *
+ * @param array $variables
+ * An associative array containing:
+ * - @todo list variables.
*/
function template_preprocess_language_content_settings_table(&$variables) {
// Add a render element representing the bundle language settings table.
$element = $variables['element'];
- $header = array(
- array(
- 'data' => $element['#bundle_label'],
- 'class' => array('bundle'),
- ),
- array(
- 'data' => t('Configuration'),
- 'class' => array('operations'),
+ $variables['table'] = array(
+ '#type' => 'table',
+ '#header' => array(
+ array(
+ 'data' => $element['#bundle_label'],
+ 'class' => array('bundle'),
+ ),
+ array(
+ 'data' => t('Configuration'),
+ 'class' => array('operations'),
+ ),
),
);
- $rows = array();
foreach (element_children($element) as $bundle) {
- $rows[$bundle] = array(
- 'data' => array(
- array(
- 'data' => array(
- '#prefix' => '',
- '#markup' => check_plain($element[$bundle]['settings']['#label']),
- ),
- 'class' => array('bundle'),
- ),
- array(
- 'data' => $element[$bundle]['settings'],
- 'class' => array('operations'),
- ),
- ),
- 'class' => array('bundle-settings'),
+ $variables['table'][$bundle]['#attributes']['class'][] = 'bundle-settings';
+ $variables['table'][$bundle]['label'] = array(
+ '#wrapper_attributes' => array('class' => array('bundle')),
+ '#prefix' => 'test',
+ '#markup' => String::checkPlain($element[$bundle]['settings']['#label']),
);
- }
-
- $variables['build'] = array(
- '#title' => $element['#title'],
- '#header' => $header,
- '#rows' => $rows,
- '#theme' => 'table',
- );
-}
-/**
- * Returns HTML for an administration settings table.
- *
- * @param array $variables
- * An associative array containing:
- * - build: A render element representing a table of bundle content language
- * settings for a particular entity type.
- *
- * @ingroup themable
- */
-function theme_language_content_settings_table($variables) {
- return '' . $variables['build']['#title'] . '
' . drupal_render($variables['build']);
+ $variables['table'][$bundle]['operations'] = $element[$bundle]['settings'];
+ $variables['table'][$bundle]['operations']['#wrapper_attributes'] = array('class' => array('operations'));
+ }
+ $variables['title'] = $element['#title'];
}
/**
diff --git a/core/modules/language/language.module b/core/modules/language/language.module
index 05e3776..605c443 100644
--- a/core/modules/language/language.module
+++ b/core/modules/language/language.module
@@ -156,14 +156,12 @@ function language_theme() {
return array(
'language_negotiation_configure_form' => array(
'render element' => 'form',
- ),
- 'language_negotiation_configure_browser_form_table' => array(
- 'render element' => 'form',
- 'file' => 'language.admin.inc',
+ 'template' => 'language-negotiation-configure-form',
),
'language_content_settings_table' => array(
'render element' => 'element',
'file' => 'language.admin.inc',
+ 'template' => 'language-content-settings-table',
),
);
}
diff --git a/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php b/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php
index 5cc3c4b..5dfad09 100644
--- a/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php
+++ b/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php
@@ -84,11 +84,25 @@ public function buildForm(array $form, array &$form_state) {
$form['mappings'] = array(
'#tree' => TRUE,
- '#theme' => 'language_negotiation_configure_browser_form_table',
+ '#type' => 'table',
+ '#header' => array(
+ t('Browser language code'),
+ t('Drupal language'),
+ t('Operations'),
+ ),
+ '#attributes' => array('id' => 'lang-neg-browser'),
);
$mappings = $this->language_get_browser_drupal_langcode_mappings();
foreach ($mappings as $browser_langcode => $drupal_langcode) {
+ $links = array();
+ $links['delete'] = array(
+ 'title' => t('Delete'),
+ 'href' => 'admin/config/regional/language/detection/browser/delete/' . $browser_langcode,
+ 'attributes' => array(
+ 'class' => array('image-style-link'),
+ ),
+ );
$form['mappings'][$browser_langcode] = array(
'browser_langcode' => array(
'#type' => 'textfield',
@@ -102,6 +116,10 @@ public function buildForm(array $form, array &$form_state) {
'#default_value' => $drupal_langcode,
'#required' => TRUE,
),
+ 'operations' => array(
+ '#type' => 'operations',
+ '#links' => $links,
+ ),
);
}
diff --git a/core/modules/language/templates/language-content-settings-table.html.twig b/core/modules/language/templates/language-content-settings-table.html.twig
new file mode 100644
index 0000000..2c7a61a
--- /dev/null
+++ b/core/modules/language/templates/language-content-settings-table.html.twig
@@ -0,0 +1,18 @@
+{#
+/**
+* @file
+* Default theme implementation for an administration settings table.
+*
+* Available variables:
+* - title: A title for the table
+* - attributes: Remaining HTML attributes for the element.
+* - table: A render element representing a table of bundle content language
+* settings for a particular entity type.
+*
+* @see template_preprocess_language_content_settings_table()
+*
+* @ingroup themeable
+*/
+#}
+{{ title }}
+{{ table }}
diff --git a/core/modules/language/templates/language-negotiation-configure-form.html.twig b/core/modules/language/templates/language-negotiation-configure-form.html.twig
new file mode 100644
index 0000000..1da8a3e
--- /dev/null
+++ b/core/modules/language/templates/language-negotiation-configure-form.html.twig
@@ -0,0 +1,30 @@
+{#
+/**
+* @file
+* Default theme implementation for a language negotiation configuration form.
+*
+* Available variables:
+* - language_types: @todo.
+* - type: @todo.
+* - title: @todo.
+* - description: @todo.
+* - configurable: @todo.
+* - table: @todo.
+* - children: @todo.
+* - children: Remaining form items like the save button.
+*
+* @see template_preprocess_language_negotiation_configure_form()
+*
+* @ingroup themeable
+*/
+#}
+{% for language_type in language_types %}
+
+{% endfor %}
+{{ form }}