From dbedb4202f036400843979a63b006327e13411af Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Mon, 9 Jun 2014 18:04:36 -0500 Subject: [PATCH] Issue #1898422 by joelpittet, lokapujya, Salah Messaoud, stevector, Les Lim, pplantinga, jenlampton, drupalninja99, tlattimore, johannez | c4rl: Language.module - Convert theme_ functions to Twig. --- core/modules/language/language.admin.inc | 100 ++++++++++-------- core/modules/language/language.module | 1 + ...guage-negotiation-configure-form.html.twig | 31 ++++++ 3 files changed, 87 insertions(+), 45 deletions(-) create mode 100644 core/modules/language/templates/language-negotiation-configure-form.html.twig diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index a2405dabe5c8..621ed8a3709e 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -9,77 +9,87 @@ use Drupal\Core\Render\Element; /** - * 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 = '<h2>' . $form[$type]['#title'] . '</h2>'; - $description = '<div class="description">' . $form[$type]['#description'] . '</div>'; - - foreach ($form[$type]['title'] as $id => $element) { - // Do not take form control structures. - if (is_array($element) && Element::child($id)) { - $row = array( - 'data' => array( - '<strong>' . drupal_render($form[$type]['title'][$id]) . '</strong>', - 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( + $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( 'action' => 'order', 'relationship' => 'sibling', - 'group' => "language-method-weight-$type", + 'group' => 'language-method-weight-' . $type, ), ), ); - $table = drupal_render($form[$type]['configurable']); - $table .= drupal_render($build); - $table .= drupal_render_children($form[$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' => '<strong>', + $form[$type]['title'][$id], + '#suffix' => '</strong>', + ); + $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 to prevent rendering along with children. + 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 .= '<div class="form-item table-language-group table-' . $type . '-wrapper">' . $title . $description . $table . '</div>'; + // Unset configurable to prevent rendering twice with children. + $configurable = isset($form[$type]['configurable']) ? $form[$type]['configurable'] : NULL; + unset($form[$type]['configurable']); + + $variables['language_types'][] = array( + 'type' => $type, + 'title' => $form[$type]['#title'], + 'description' => $form[$type]['#description'], + 'configurable' => $configurable, + 'table' => $table, + 'children' => $form[$type], + ); + // Prevent the type from rendering with the remaining form child elements. + unset($form[$type]); } - $output .= drupal_render_children($form); - return $output; + $variables['children'] = $form; } /** diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 3e7a04f5f809..ced686951955 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -118,6 +118,7 @@ function language_theme() { 'language_negotiation_configure_form' => array( 'render element' => 'form', 'file' => 'language.admin.inc', + 'template' => 'language-negotiation-configure-form', ), 'language_negotiation_configure_browser_form_table' => array( 'render element' => 'form', 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 000000000000..67ddda4e9f59 --- /dev/null +++ b/core/modules/language/templates/language-negotiation-configure-form.html.twig @@ -0,0 +1,31 @@ +{# +/** +* @file +* Default theme implementation for a language negotiation configuration form. +* +* Available variables: +* - language_types: A list of language negotiation types. Each language type +* contains the following: +* - type: The machine name for the negotation type. +* - title: The language negotation type name. +* - description: A description for how the language negotation type operates. +* - configurable: A radio element to toggle the table. +* - table: A draggable table for the language detection methods of this type. +* - children: Remaining form items for the group. +* - children: Remaining form items for all groups. +* +* @see template_preprocess_language_negotiation_configure_form() +* +* @ingroup themeable +*/ +#} +{% for language_type in language_types %} + <div class="form-item table-language-group table-{{ language_type.type }}-wrapper"> + <h2>{{ language_type.title }}</h2> + <div class="description">{{ language_type.description }}</div> + {{ language_type.configurable }} + {{ language_type.table }} + {{ language_type.children }} + </div> +{% endfor %} +{{ children }} -- GitLab