Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Administration functions for language.module.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Core\Render\Element;
|
Chris@0
|
9 use Drupal\Core\Template\Attribute;
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Prepares variables for language negotiation configuration form.
|
Chris@0
|
13 *
|
Chris@0
|
14 * Default template: language-content-configuration-form.html.twig.
|
Chris@0
|
15 *
|
Chris@0
|
16 * @param array $variables
|
Chris@0
|
17 * An associative array containing:
|
Chris@0
|
18 * - form: A render element representing the form.
|
Chris@0
|
19 */
|
Chris@0
|
20 function template_preprocess_language_negotiation_configure_form(&$variables) {
|
Chris@0
|
21 $form =& $variables['form'];
|
Chris@0
|
22 $variables['language_types'] = [];
|
Chris@0
|
23
|
Chris@0
|
24 foreach ($form['#language_types'] as $type) {
|
Chris@0
|
25 $header = [
|
Chris@0
|
26 t('Detection method'),
|
Chris@0
|
27 t('Description'),
|
Chris@0
|
28 t('Enabled'),
|
Chris@0
|
29 t('Weight'),
|
Chris@0
|
30 ];
|
Chris@0
|
31
|
Chris@0
|
32 // If there is at least one operation enabled show the operation column.
|
Chris@0
|
33 if ($form[$type]['#show_operations']) {
|
Chris@0
|
34 $header[] = t('Operations');
|
Chris@0
|
35 }
|
Chris@0
|
36
|
Chris@0
|
37 $table = [
|
Chris@0
|
38 '#type' => 'table',
|
Chris@0
|
39 '#header' => $header,
|
Chris@0
|
40 '#attributes' => ['id' => 'language-negotiation-methods-' . $type],
|
Chris@0
|
41 '#tabledrag' => [
|
Chris@0
|
42 [
|
Chris@0
|
43 'action' => 'order',
|
Chris@0
|
44 'relationship' => 'sibling',
|
Chris@0
|
45 'group' => 'language-method-weight-' . $type,
|
Chris@0
|
46 ],
|
Chris@0
|
47 ],
|
Chris@0
|
48 ];
|
Chris@0
|
49
|
Chris@0
|
50 foreach ($form[$type]['title'] as $id => $element) {
|
Chris@0
|
51 // Do not take form control structures.
|
Chris@0
|
52 if (is_array($element) && Element::child($id)) {
|
Chris@0
|
53 $table[$id]['#attributes']['class'][] = 'draggable';
|
Chris@0
|
54 $table[$id]['#weight'] = $element['#weight'];
|
Chris@0
|
55
|
Chris@0
|
56 $table[$id]['title'] = [
|
Chris@0
|
57 '#prefix' => '<strong>',
|
Chris@0
|
58 $form[$type]['title'][$id],
|
Chris@0
|
59 '#suffix' => '</strong>',
|
Chris@0
|
60 ];
|
Chris@0
|
61 $table[$id]['description'] = $form[$type]['description'][$id];
|
Chris@0
|
62 $table[$id]['enabled'] = $form[$type]['enabled'][$id];
|
Chris@0
|
63 $table[$id]['weight'] = $form[$type]['weight'][$id];
|
Chris@0
|
64 if ($form[$type]['#show_operations']) {
|
Chris@0
|
65 $table[$id]['operation'] = $form[$type]['operation'][$id];
|
Chris@0
|
66 }
|
Chris@0
|
67 // Unset to prevent rendering along with children.
|
Chris@0
|
68 unset($form[$type]['title'][$id]);
|
Chris@0
|
69 unset($form[$type]['description'][$id]);
|
Chris@0
|
70 unset($form[$type]['enabled'][$id]);
|
Chris@0
|
71 unset($form[$type]['weight'][$id]);
|
Chris@0
|
72 unset($form[$type]['operation'][$id]);
|
Chris@0
|
73 }
|
Chris@0
|
74 }
|
Chris@0
|
75
|
Chris@0
|
76 // Unset configurable to prevent rendering twice with children.
|
Chris@0
|
77 $configurable = isset($form[$type]['configurable']) ? $form[$type]['configurable'] : NULL;
|
Chris@0
|
78 unset($form[$type]['configurable']);
|
Chris@0
|
79
|
Chris@0
|
80 $variables['language_types'][] = [
|
Chris@0
|
81 'type' => $type,
|
Chris@0
|
82 'title' => $form[$type]['#title'],
|
Chris@0
|
83 'description' => $form[$type]['#description'],
|
Chris@0
|
84 'configurable' => $configurable,
|
Chris@0
|
85 'table' => $table,
|
Chris@0
|
86 'children' => $form[$type],
|
Chris@0
|
87 'attributes' => new Attribute(),
|
Chris@0
|
88 ];
|
Chris@0
|
89 // Prevent the type from rendering with the remaining form child elements.
|
Chris@0
|
90 unset($form[$type]);
|
Chris@0
|
91 }
|
Chris@0
|
92
|
Chris@0
|
93 $variables['children'] = $form;
|
Chris@0
|
94 }
|
Chris@0
|
95
|
Chris@0
|
96 /**
|
Chris@0
|
97 * Prepares variables for language content settings table templates.
|
Chris@0
|
98 *
|
Chris@0
|
99 * Default template: language-content-settings-table.html.twig.
|
Chris@0
|
100 *
|
Chris@0
|
101 * @param array $variables
|
Chris@0
|
102 * An associative array containing:
|
Chris@0
|
103 * - element: An associative array containing the properties of the element.
|
Chris@0
|
104 * Properties used: #bundle_label, #title.
|
Chris@0
|
105 */
|
Chris@0
|
106 function template_preprocess_language_content_settings_table(&$variables) {
|
Chris@0
|
107 // Add a render element representing the bundle language settings table.
|
Chris@0
|
108 $element = $variables['element'];
|
Chris@0
|
109
|
Chris@0
|
110 $header = [
|
Chris@0
|
111 [
|
Chris@0
|
112 'data' => $element['#bundle_label'],
|
Chris@0
|
113 'class' => ['bundle'],
|
Chris@0
|
114 ],
|
Chris@0
|
115 [
|
Chris@0
|
116 'data' => t('Configuration'),
|
Chris@0
|
117 'class' => ['operations'],
|
Chris@0
|
118 ],
|
Chris@0
|
119 ];
|
Chris@0
|
120
|
Chris@0
|
121 $rows = [];
|
Chris@0
|
122 foreach (Element::children($element) as $bundle) {
|
Chris@0
|
123 $rows[$bundle] = [
|
Chris@0
|
124 'data' => [
|
Chris@0
|
125 [
|
Chris@0
|
126 'data' => [
|
Chris@0
|
127 '#prefix' => '<label>',
|
Chris@0
|
128 '#suffix' => '</label>',
|
Chris@0
|
129 '#plain_text' => $element[$bundle]['settings']['#label'],
|
Chris@0
|
130 ],
|
Chris@0
|
131 'class' => ['bundle'],
|
Chris@0
|
132 ],
|
Chris@0
|
133 [
|
Chris@0
|
134 'data' => $element[$bundle]['settings'],
|
Chris@0
|
135 'class' => ['operations'],
|
Chris@0
|
136 ],
|
Chris@0
|
137 ],
|
Chris@0
|
138 'class' => ['bundle-settings'],
|
Chris@0
|
139 ];
|
Chris@0
|
140 }
|
Chris@0
|
141
|
Chris@0
|
142 $variables['title'] = $element['#title'];
|
Chris@0
|
143 $variables['build'] = [
|
Chris@0
|
144 '#header' => $header,
|
Chris@0
|
145 '#rows' => $rows,
|
Chris@0
|
146 '#type' => 'table',
|
Chris@0
|
147 ];
|
Chris@0
|
148 }
|