5 * Administration functions for language.module.
8 use Drupal\Core\Render\Element;
9 use Drupal\Core\Template\Attribute;
12 * Prepares variables for language negotiation configuration form.
14 * Default template: language-content-configuration-form.html.twig.
16 * @param array $variables
17 * An associative array containing:
18 * - form: A render element representing the form.
20 function template_preprocess_language_negotiation_configure_form(&$variables) {
21 $form =& $variables['form'];
22 $variables['language_types'] = [];
24 foreach ($form['#language_types'] as $type) {
26 t('Detection method'),
32 // If there is at least one operation enabled show the operation column.
33 if ($form[$type]['#show_operations']) {
34 $header[] = t('Operations');
40 '#attributes' => ['id' => 'language-negotiation-methods-' . $type],
44 'relationship' => 'sibling',
45 'group' => 'language-method-weight-' . $type,
50 foreach ($form[$type]['title'] as $id => $element) {
51 // Do not take form control structures.
52 if (is_array($element) && Element::child($id)) {
53 $table[$id]['#attributes']['class'][] = 'draggable';
54 $table[$id]['#weight'] = $element['#weight'];
56 $table[$id]['title'] = [
57 '#prefix' => '<strong>',
58 $form[$type]['title'][$id],
59 '#suffix' => '</strong>',
61 $table[$id]['description'] = $form[$type]['description'][$id];
62 $table[$id]['enabled'] = $form[$type]['enabled'][$id];
63 $table[$id]['weight'] = $form[$type]['weight'][$id];
64 if ($form[$type]['#show_operations']) {
65 $table[$id]['operation'] = $form[$type]['operation'][$id];
67 // Unset to prevent rendering along with children.
68 unset($form[$type]['title'][$id]);
69 unset($form[$type]['description'][$id]);
70 unset($form[$type]['enabled'][$id]);
71 unset($form[$type]['weight'][$id]);
72 unset($form[$type]['operation'][$id]);
76 // Unset configurable to prevent rendering twice with children.
77 $configurable = isset($form[$type]['configurable']) ? $form[$type]['configurable'] : NULL;
78 unset($form[$type]['configurable']);
80 $variables['language_types'][] = [
82 'title' => $form[$type]['#title'],
83 'description' => $form[$type]['#description'],
84 'configurable' => $configurable,
86 'children' => $form[$type],
87 'attributes' => new Attribute(),
89 // Prevent the type from rendering with the remaining form child elements.
93 $variables['children'] = $form;
97 * Prepares variables for language content settings table templates.
99 * Default template: language-content-settings-table.html.twig.
101 * @param array $variables
102 * An associative array containing:
103 * - element: An associative array containing the properties of the element.
104 * Properties used: #bundle_label, #title.
106 function template_preprocess_language_content_settings_table(&$variables) {
107 // Add a render element representing the bundle language settings table.
108 $element = $variables['element'];
112 'data' => $element['#bundle_label'],
113 'class' => ['bundle'],
116 'data' => t('Configuration'),
117 'class' => ['operations'],
122 foreach (Element::children($element) as $bundle) {
127 '#prefix' => '<label>',
128 '#suffix' => '</label>',
129 '#plain_text' => $element[$bundle]['settings']['#label'],
131 'class' => ['bundle'],
134 'data' => $element[$bundle]['settings'],
135 'class' => ['operations'],
138 'class' => ['bundle-settings'],
142 $variables['title'] = $element['#title'];
143 $variables['build'] = [
144 '#header' => $header,