Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Admin page callbacks for the system module.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Component\Utility\Html;
|
Chris@0
|
9 use Drupal\Core\Render\Element;
|
Chris@0
|
10 use Drupal\Core\Template\Attribute;
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * Prepares variables for administrative content block templates.
|
Chris@0
|
14 *
|
Chris@0
|
15 * Default template: admin-block-content.html.twig.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @param $variables
|
Chris@0
|
18 * An associative array containing:
|
Chris@0
|
19 * - content: An array containing information about the block. Each element
|
Chris@0
|
20 * of the array represents an administrative menu item, and must at least
|
Chris@0
|
21 * contain the keys 'title', 'link_path', and 'localized_options', which are
|
Chris@0
|
22 * passed to l(). A 'description' key may also be provided.
|
Chris@0
|
23 */
|
Chris@0
|
24 function template_preprocess_admin_block_content(&$variables) {
|
Chris@0
|
25 if (!empty($variables['content'])) {
|
Chris@0
|
26 $variables['compact'] = system_admin_compact_mode();
|
Chris@0
|
27 foreach ($variables['content'] as $key => $item) {
|
Chris@0
|
28 $variables['content'][$key]['link'] = \Drupal::l($item['title'], $item['url']);
|
Chris@0
|
29 if (!$variables['compact'] && isset($item['description'])) {
|
Chris@0
|
30 $variables['content'][$key]['description'] = ['#markup' => $item['description']];
|
Chris@0
|
31 }
|
Chris@0
|
32 else {
|
Chris@0
|
33 $variables['content'][$key]['description'] = FALSE;
|
Chris@0
|
34 }
|
Chris@0
|
35 }
|
Chris@0
|
36 }
|
Chris@0
|
37 }
|
Chris@0
|
38
|
Chris@0
|
39 /**
|
Chris@0
|
40 * Prepares variables for administrative index page templates.
|
Chris@0
|
41 *
|
Chris@0
|
42 * Default template: admin-page.html.twig.
|
Chris@0
|
43 *
|
Chris@0
|
44 * @param $variables
|
Chris@0
|
45 * An associative array containing:
|
Chris@0
|
46 * - blocks: An array of blocks to display. Each array should include a
|
Chris@0
|
47 * 'title', a 'description', a formatted 'content' and a 'position' which
|
Chris@0
|
48 * will control which container it will be in. This is usually 'left' or
|
Chris@0
|
49 * 'right'.
|
Chris@0
|
50 */
|
Chris@0
|
51 function template_preprocess_admin_page(&$variables) {
|
Chris@0
|
52 $variables['system_compact_link'] = [
|
Chris@0
|
53 '#type' => 'system_compact_link',
|
Chris@0
|
54 ];
|
Chris@0
|
55 $variables['containers'] = [];
|
Chris@0
|
56 $stripe = 0;
|
Chris@0
|
57 foreach ($variables['blocks'] as $block) {
|
Chris@0
|
58 if (!empty($block['content']['#content'])) {
|
Chris@0
|
59 if (empty($block['position'])) {
|
Chris@0
|
60 // Perform automatic striping.
|
Chris@0
|
61 $block['position'] = ++$stripe % 2 ? 'left' : 'right';
|
Chris@0
|
62 }
|
Chris@0
|
63 $variables['containers'][$block['position']]['blocks'][] = [
|
Chris@0
|
64 '#theme' => 'admin_block',
|
Chris@0
|
65 '#block' => $block,
|
Chris@0
|
66 ];
|
Chris@0
|
67 }
|
Chris@0
|
68 }
|
Chris@0
|
69 }
|
Chris@0
|
70
|
Chris@0
|
71 /**
|
Chris@0
|
72 * Prepares variables for admin index templates.
|
Chris@0
|
73 *
|
Chris@0
|
74 * Default template: system-admin-index.html.twig.
|
Chris@0
|
75 *
|
Chris@0
|
76 * @param $variables
|
Chris@0
|
77 * An associative array containing:
|
Chris@0
|
78 * - menu_items: An array of modules to be displayed.
|
Chris@0
|
79 */
|
Chris@0
|
80 function template_preprocess_system_admin_index(&$variables) {
|
Chris@0
|
81 $variables['system_compact_link'] = [
|
Chris@0
|
82 '#type' => 'system_compact_link',
|
Chris@0
|
83 ];
|
Chris@0
|
84 $variables['containers'] = [];
|
Chris@0
|
85 $stripe = 0;
|
Chris@0
|
86 // Iterate over all modules.
|
Chris@0
|
87 foreach ($variables['menu_items'] as $module => $block) {
|
Chris@0
|
88 list($description, $items) = $block;
|
Chris@0
|
89 $position = ++$stripe % 2 ? 'left' : 'right';
|
Chris@0
|
90 // Output links.
|
Chris@0
|
91 if (count($items)) {
|
Chris@0
|
92 $variables['containers'][$position][] = [
|
Chris@0
|
93 '#theme' => 'admin_block',
|
Chris@0
|
94 '#block' => [
|
Chris@0
|
95 'position' => $position,
|
Chris@0
|
96 'title' => $module,
|
Chris@0
|
97 'content' => [
|
Chris@0
|
98 '#theme' => 'admin_block_content',
|
Chris@0
|
99 '#content' => $items,
|
Chris@0
|
100 ],
|
Chris@0
|
101 'description' => t($description),
|
Chris@0
|
102 ],
|
Chris@0
|
103 ];
|
Chris@0
|
104 }
|
Chris@0
|
105 }
|
Chris@0
|
106 }
|
Chris@0
|
107
|
Chris@0
|
108 /**
|
Chris@0
|
109 * Prepares variables for the module details templates.
|
Chris@0
|
110 *
|
Chris@0
|
111 * Default template: system-modules-details.html.twig.
|
Chris@0
|
112 *
|
Chris@0
|
113 * @param $variables
|
Chris@0
|
114 * An associative array containing:
|
Chris@0
|
115 * - form: A render element representing the form. The main form element
|
Chris@0
|
116 * represents a package, and child elements of the form are individual
|
Chris@0
|
117 * projects. Each project (or module) is an associative array containing the
|
Chris@0
|
118 * following elements:
|
Chris@0
|
119 * - name: The name of the module.
|
Chris@0
|
120 * - enable: A checkbox for enabling the module.
|
Chris@0
|
121 * - description: A description of the module.
|
Chris@0
|
122 * - version: The version of the module.
|
Chris@0
|
123 * - links: Administration links provided by the module.
|
Chris@0
|
124 * - #requires: A list of modules that the project requires.
|
Chris@0
|
125 * - #required_by: A list of modules that require the project.
|
Chris@0
|
126 * - #attributes: A list of attributes for the module wrapper.
|
Chris@0
|
127 *
|
Chris@0
|
128 * @see \Drupal\system\Form\ModulesListForm
|
Chris@0
|
129 */
|
Chris@0
|
130 function template_preprocess_system_modules_details(&$variables) {
|
Chris@0
|
131 $form = $variables['form'];
|
Chris@0
|
132
|
Chris@0
|
133 $variables['modules'] = [];
|
Chris@0
|
134 // Iterate through all the modules, which are children of this element.
|
Chris@0
|
135 foreach (Element::children($form) as $key) {
|
Chris@0
|
136 // Stick the key into $module for easier access.
|
Chris@0
|
137 $module = $form[$key];
|
Chris@0
|
138 unset($module['enable']['#title']);
|
Chris@0
|
139 $module['#requires'] = array_filter($module['#requires']);
|
Chris@0
|
140 $module['#required_by'] = array_filter($module['#required_by']);
|
Chris@0
|
141 // Add the checkbox to allow installing new modules and to show the
|
Chris@0
|
142 // installation status of the module.
|
Chris@0
|
143 $module['checkbox'] = $module['enable'];
|
Chris@0
|
144
|
Chris@0
|
145 // Add the module label and expand/collapse functionality.
|
Chris@0
|
146 $id = Html::getUniqueId('module-' . $key);
|
Chris@0
|
147 $module['id'] = $id;
|
Chris@0
|
148 $module['enable_id'] = $module['enable']['#id'];
|
Chris@0
|
149
|
Chris@0
|
150 // @todo Remove early rendering and use safe_join in the Twig template once
|
Chris@0
|
151 // https://www.drupal.org/node/2579091 is fixed.
|
Chris@0
|
152 $renderer = \Drupal::service('renderer');
|
Chris@0
|
153 $machine_name_render = [
|
Chris@0
|
154 '#prefix' => '<span dir="ltr" class="table-filter-text-source">',
|
Chris@0
|
155 '#plain_text' => $key,
|
Chris@0
|
156 '#suffix' => '</span>',
|
Chris@0
|
157 ];
|
Chris@0
|
158 $module['machine_name'] = $renderer->render($machine_name_render);
|
Chris@0
|
159
|
Chris@0
|
160 if (!empty($module['#requires'])) {
|
Chris@0
|
161 $requires = [
|
Chris@0
|
162 '#theme' => 'item_list',
|
Chris@0
|
163 '#items' => $module['#requires'],
|
Chris@0
|
164 '#context' => ['list_style' => 'comma-list'],
|
Chris@0
|
165 ];
|
Chris@0
|
166 $module['requires'] = $renderer->render($requires);
|
Chris@0
|
167 }
|
Chris@0
|
168 if (!empty($module['#required_by'])) {
|
Chris@0
|
169 $required_by = [
|
Chris@0
|
170 '#theme' => 'item_list',
|
Chris@0
|
171 '#items' => $module['#required_by'],
|
Chris@0
|
172 '#context' => ['list_style' => 'comma-list'],
|
Chris@0
|
173 ];
|
Chris@0
|
174 $module['required_by'] = $renderer->render($required_by);
|
Chris@0
|
175 }
|
Chris@0
|
176
|
Chris@0
|
177 if (!empty($module['version'])) {
|
Chris@0
|
178 $module['version'] = $renderer->render($module['version']);
|
Chris@0
|
179 }
|
Chris@0
|
180
|
Chris@0
|
181 $module['attributes'] = new Attribute($module['#attributes']);
|
Chris@0
|
182 $variables['modules'][] = $module;
|
Chris@0
|
183 }
|
Chris@0
|
184 }
|
Chris@0
|
185
|
Chris@0
|
186 /**
|
Chris@0
|
187 * Prepares variables for module uninstall templates.
|
Chris@0
|
188 *
|
Chris@0
|
189 * Default template: system-modules-uninstall.html.twig.
|
Chris@0
|
190 *
|
Chris@0
|
191 * @param $variables
|
Chris@0
|
192 * An associative array containing:
|
Chris@0
|
193 * - form: A render element representing the form. Child elements of the form
|
Chris@0
|
194 * are individual modules. Each module is an associative array containing
|
Chris@0
|
195 * the following elements:
|
Chris@0
|
196 * - #module_name: The name of the module as a string.
|
Chris@0
|
197 * - name: The name of the module in a renderable array.
|
Chris@0
|
198 * - description: A description of the module.
|
Chris@0
|
199 * - #required_by: (optional) A list of modules that require the module.
|
Chris@0
|
200 * - #validation_reasons: (optional) Additional reasons why the module
|
Chris@0
|
201 * cannot be uninstalled.
|
Chris@0
|
202 * - #attributes: A list of attributes for the module wrapper.
|
Chris@0
|
203 *
|
Chris@0
|
204 * @ingroup themeable
|
Chris@0
|
205 */
|
Chris@0
|
206 function template_preprocess_system_modules_uninstall(&$variables) {
|
Chris@0
|
207 $form = $variables['form'];
|
Chris@0
|
208 $variables['modules'] = [];
|
Chris@0
|
209
|
Chris@0
|
210 // Iterate through all the modules, which are children of this element.
|
Chris@0
|
211 foreach (Element::children($form['modules']) as $key) {
|
Chris@0
|
212 $module = $form['modules'][$key];
|
Chris@0
|
213 $module['module_name'] = $module['#module_name'];
|
Chris@0
|
214 $module['checkbox'] = $form['uninstall'][$key];
|
Chris@0
|
215 $module['checkbox_id'] = $form['uninstall'][$key]['#id'];
|
Chris@0
|
216
|
Chris@0
|
217 if (!empty($module['#validation_reasons'])) {
|
Chris@0
|
218 $module['validation_reasons'] = $module['#validation_reasons'];
|
Chris@0
|
219 $module['reasons_count'] = count($module['validation_reasons']);
|
Chris@0
|
220 }
|
Chris@0
|
221 else {
|
Chris@0
|
222 $module['reasons_count'] = 0;
|
Chris@0
|
223 }
|
Chris@0
|
224 if (!empty($module['#required_by'])) {
|
Chris@0
|
225 $module['required_by'] = $module['#required_by'];
|
Chris@0
|
226 $module['reasons_count'] = $module['reasons_count'] + 1;
|
Chris@0
|
227 }
|
Chris@0
|
228 $module['attributes'] = new Attribute($module['#attributes']);
|
Chris@0
|
229 $variables['modules'][] = $module;
|
Chris@0
|
230 }
|
Chris@0
|
231 }
|
Chris@0
|
232
|
Chris@0
|
233 /**
|
Chris@0
|
234 * Prepares variables for appearance page templates.
|
Chris@0
|
235 *
|
Chris@0
|
236 * Default template: system-themes-page.html.twig.
|
Chris@0
|
237 *
|
Chris@0
|
238 * @param $variables
|
Chris@0
|
239 * An associative array containing:
|
Chris@0
|
240 * - theme_groups: An associative array containing groups of themes.
|
Chris@0
|
241 * - theme_group_titles: An associative array containing titles of themes.
|
Chris@0
|
242 */
|
Chris@0
|
243 function template_preprocess_system_themes_page(&$variables) {
|
Chris@0
|
244 $groups = [];
|
Chris@0
|
245 $theme_groups = $variables['theme_groups'];
|
Chris@0
|
246 $variables['attributes']['id'] = 'system-themes-page';
|
Chris@0
|
247
|
Chris@0
|
248 foreach ($variables['theme_group_titles'] as $state => $title) {
|
Chris@0
|
249 if (!count($theme_groups[$state])) {
|
Chris@0
|
250 // Skip this group of themes if no theme is there.
|
Chris@0
|
251 continue;
|
Chris@0
|
252 }
|
Chris@0
|
253 // Start new theme group.
|
Chris@0
|
254 $theme_group = [];
|
Chris@0
|
255 $theme_group['state'] = $state;
|
Chris@0
|
256 $theme_group['title'] = $title;
|
Chris@0
|
257 $theme_group['themes'] = [];
|
Chris@0
|
258 $theme_group['attributes'] = new Attribute();
|
Chris@0
|
259
|
Chris@0
|
260 foreach ($theme_groups[$state] as $theme) {
|
Chris@0
|
261 $current_theme = [];
|
Chris@0
|
262
|
Chris@0
|
263 // Screenshot depicting the theme.
|
Chris@0
|
264 if ($theme->screenshot) {
|
Chris@0
|
265 $current_theme['screenshot'] = [
|
Chris@0
|
266 '#theme' => 'image',
|
Chris@0
|
267 '#uri' => $theme->screenshot['uri'],
|
Chris@0
|
268 '#alt' => $theme->screenshot['alt'],
|
Chris@0
|
269 '#title' => $theme->screenshot['title'],
|
Chris@0
|
270 '#attributes' => $theme->screenshot['attributes'],
|
Chris@0
|
271 ];
|
Chris@0
|
272 }
|
Chris@0
|
273 else {
|
Chris@0
|
274 $current_theme['screenshot'] = [
|
Chris@0
|
275 '#theme' => 'image',
|
Chris@0
|
276 '#uri' => drupal_get_path('module', 'system') . '/images/no_screenshot.png',
|
Chris@0
|
277 '#alt' => t('No screenshot'),
|
Chris@0
|
278 '#title' => t('No screenshot'),
|
Chris@0
|
279 '#attributes' => new Attribute(['class' => ['no-screenshot']]),
|
Chris@0
|
280 ];
|
Chris@0
|
281 }
|
Chris@0
|
282
|
Chris@0
|
283 // Localize the theme description.
|
Chris@0
|
284 $current_theme['description'] = t($theme->info['description']);
|
Chris@0
|
285
|
Chris@0
|
286 $current_theme['attributes'] = new Attribute();
|
Chris@0
|
287 $current_theme['name'] = $theme->info['name'];
|
Chris@0
|
288 $current_theme['version'] = isset($theme->info['version']) ? $theme->info['version'] : '';
|
Chris@0
|
289 $current_theme['notes'] = $theme->notes;
|
Chris@0
|
290 $current_theme['is_default'] = $theme->is_default;
|
Chris@0
|
291 $current_theme['is_admin'] = $theme->is_admin;
|
Chris@0
|
292
|
Chris@0
|
293 // Make sure to provide feedback on compatibility.
|
Chris@0
|
294 $current_theme['incompatible'] = '';
|
Chris@0
|
295 if (!empty($theme->incompatible_core)) {
|
Chris@0
|
296 $current_theme['incompatible'] = t("This theme is not compatible with Drupal @core_version. Check that the .info.yml file contains the correct 'core' value.", ['@core_version' => \Drupal::CORE_COMPATIBILITY]);
|
Chris@0
|
297 }
|
Chris@0
|
298 elseif (!empty($theme->incompatible_region)) {
|
Chris@0
|
299 $current_theme['incompatible'] = t("This theme is missing a 'content' region.");
|
Chris@0
|
300 }
|
Chris@0
|
301 elseif (!empty($theme->incompatible_php)) {
|
Chris@0
|
302 if (substr_count($theme->info['php'], '.') < 2) {
|
Chris@0
|
303 $theme->info['php'] .= '.*';
|
Chris@0
|
304 }
|
Chris@0
|
305 $current_theme['incompatible'] = t('This theme requires PHP version @php_required and is incompatible with PHP version @php_version.', ['@php_required' => $theme->info['php'], '@php_version' => phpversion()]);
|
Chris@0
|
306 }
|
Chris@0
|
307 elseif (!empty($theme->incompatible_base)) {
|
Chris@0
|
308 $current_theme['incompatible'] = t('This theme requires the base theme @base_theme to operate correctly.', ['@base_theme' => $theme->info['base theme']]);
|
Chris@0
|
309 }
|
Chris@0
|
310 elseif (!empty($theme->incompatible_engine)) {
|
Chris@0
|
311 $current_theme['incompatible'] = t('This theme requires the theme engine @theme_engine to operate correctly.', ['@theme_engine' => $theme->info['engine']]);
|
Chris@0
|
312 }
|
Chris@0
|
313
|
Chris@0
|
314 // Build operation links.
|
Chris@0
|
315 $current_theme['operations'] = [
|
Chris@0
|
316 '#theme' => 'links',
|
Chris@0
|
317 '#links' => $theme->operations,
|
Chris@0
|
318 '#attributes' => [
|
Chris@0
|
319 'class' => ['operations', 'clearfix'],
|
Chris@0
|
320 ],
|
Chris@0
|
321 ];
|
Chris@0
|
322 $theme_group['themes'][] = $current_theme;
|
Chris@0
|
323 }
|
Chris@0
|
324 $groups[] = $theme_group;
|
Chris@0
|
325 }
|
Chris@0
|
326 $variables['theme_groups'] = $groups;
|
Chris@0
|
327 }
|