5 * Admin page callbacks for the system module.
8 use Drupal\Component\Utility\Html;
9 use Drupal\Core\Render\Element;
10 use Drupal\Core\Template\Attribute;
13 * Prepares variables for administrative content block templates.
15 * Default template: admin-block-content.html.twig.
18 * An associative array containing:
19 * - content: An array containing information about the block. Each element
20 * of the array represents an administrative menu item, and must at least
21 * contain the keys 'title', 'link_path', and 'localized_options', which are
22 * passed to l(). A 'description' key may also be provided.
24 function template_preprocess_admin_block_content(&$variables) {
25 if (!empty($variables['content'])) {
26 $variables['compact'] = system_admin_compact_mode();
27 foreach ($variables['content'] as $key => $item) {
28 $variables['content'][$key]['link'] = \Drupal::l($item['title'], $item['url']);
29 if (!$variables['compact'] && isset($item['description'])) {
30 $variables['content'][$key]['description'] = ['#markup' => $item['description']];
33 $variables['content'][$key]['description'] = FALSE;
40 * Prepares variables for administrative index page templates.
42 * Default template: admin-page.html.twig.
45 * An associative array containing:
46 * - blocks: An array of blocks to display. Each array should include a
47 * 'title', a 'description', a formatted 'content' and a 'position' which
48 * will control which container it will be in. This is usually 'left' or
51 function template_preprocess_admin_page(&$variables) {
52 $variables['system_compact_link'] = [
53 '#type' => 'system_compact_link',
55 $variables['containers'] = [];
57 foreach ($variables['blocks'] as $block) {
58 if (!empty($block['content']['#content'])) {
59 if (empty($block['position'])) {
60 // Perform automatic striping.
61 $block['position'] = ++$stripe % 2 ? 'left' : 'right';
63 $variables['containers'][$block['position']]['blocks'][] = [
64 '#theme' => 'admin_block',
72 * Prepares variables for admin index templates.
74 * Default template: system-admin-index.html.twig.
77 * An associative array containing:
78 * - menu_items: An array of modules to be displayed.
80 function template_preprocess_system_admin_index(&$variables) {
81 $variables['system_compact_link'] = [
82 '#type' => 'system_compact_link',
84 $variables['containers'] = [];
86 // Iterate over all modules.
87 foreach ($variables['menu_items'] as $module => $block) {
88 list($description, $items) = $block;
89 $position = ++$stripe % 2 ? 'left' : 'right';
92 $variables['containers'][$position][] = [
93 '#theme' => 'admin_block',
95 'position' => $position,
98 '#theme' => 'admin_block_content',
101 'description' => t($description),
109 * Prepares variables for the module details templates.
111 * Default template: system-modules-details.html.twig.
114 * An associative array containing:
115 * - form: A render element representing the form. The main form element
116 * represents a package, and child elements of the form are individual
117 * projects. Each project (or module) is an associative array containing the
118 * following elements:
119 * - name: The name of the module.
120 * - enable: A checkbox for enabling the module.
121 * - description: A description of the module.
122 * - version: The version of the module.
123 * - links: Administration links provided by the module.
124 * - #requires: A list of modules that the project requires.
125 * - #required_by: A list of modules that require the project.
126 * - #attributes: A list of attributes for the module wrapper.
128 * @see \Drupal\system\Form\ModulesListForm
130 function template_preprocess_system_modules_details(&$variables) {
131 $form = $variables['form'];
133 $variables['modules'] = [];
134 // Iterate through all the modules, which are children of this element.
135 foreach (Element::children($form) as $key) {
136 // Stick the key into $module for easier access.
137 $module = $form[$key];
138 unset($module['enable']['#title']);
139 $module['#requires'] = array_filter($module['#requires']);
140 $module['#required_by'] = array_filter($module['#required_by']);
141 // Add the checkbox to allow installing new modules and to show the
142 // installation status of the module.
143 $module['checkbox'] = $module['enable'];
145 // Add the module label and expand/collapse functionality.
146 $id = Html::getUniqueId('module-' . $key);
148 $module['enable_id'] = $module['enable']['#id'];
150 // @todo Remove early rendering and use safe_join in the Twig template once
151 // https://www.drupal.org/node/2579091 is fixed.
152 $renderer = \Drupal::service('renderer');
153 $machine_name_render = [
154 '#prefix' => '<span dir="ltr" class="table-filter-text-source">',
155 '#plain_text' => $key,
156 '#suffix' => '</span>',
158 $module['machine_name'] = $renderer->render($machine_name_render);
160 if (!empty($module['#requires'])) {
162 '#theme' => 'item_list',
163 '#items' => $module['#requires'],
164 '#context' => ['list_style' => 'comma-list'],
166 $module['requires'] = $renderer->render($requires);
168 if (!empty($module['#required_by'])) {
170 '#theme' => 'item_list',
171 '#items' => $module['#required_by'],
172 '#context' => ['list_style' => 'comma-list'],
174 $module['required_by'] = $renderer->render($required_by);
177 if (!empty($module['version'])) {
178 $module['version'] = $renderer->render($module['version']);
181 $module['attributes'] = new Attribute($module['#attributes']);
182 $variables['modules'][] = $module;
187 * Prepares variables for module uninstall templates.
189 * Default template: system-modules-uninstall.html.twig.
192 * An associative array containing:
193 * - form: A render element representing the form. Child elements of the form
194 * are individual modules. Each module is an associative array containing
195 * the following elements:
196 * - #module_name: The name of the module as a string.
197 * - name: The name of the module in a renderable array.
198 * - description: A description of the module.
199 * - #required_by: (optional) A list of modules that require the module.
200 * - #validation_reasons: (optional) Additional reasons why the module
201 * cannot be uninstalled.
202 * - #attributes: A list of attributes for the module wrapper.
206 function template_preprocess_system_modules_uninstall(&$variables) {
207 $form = $variables['form'];
208 $variables['modules'] = [];
210 // Iterate through all the modules, which are children of this element.
211 foreach (Element::children($form['modules']) as $key) {
212 $module = $form['modules'][$key];
213 $module['module_name'] = $module['#module_name'];
214 $module['checkbox'] = $form['uninstall'][$key];
215 $module['checkbox_id'] = $form['uninstall'][$key]['#id'];
217 if (!empty($module['#validation_reasons'])) {
218 $module['validation_reasons'] = $module['#validation_reasons'];
219 $module['reasons_count'] = count($module['validation_reasons']);
222 $module['reasons_count'] = 0;
224 if (!empty($module['#required_by'])) {
225 $module['required_by'] = $module['#required_by'];
226 $module['reasons_count'] = $module['reasons_count'] + 1;
228 $module['attributes'] = new Attribute($module['#attributes']);
229 $variables['modules'][] = $module;
234 * Prepares variables for appearance page templates.
236 * Default template: system-themes-page.html.twig.
239 * An associative array containing:
240 * - theme_groups: An associative array containing groups of themes.
241 * - theme_group_titles: An associative array containing titles of themes.
243 function template_preprocess_system_themes_page(&$variables) {
245 $theme_groups = $variables['theme_groups'];
246 $variables['attributes']['id'] = 'system-themes-page';
248 foreach ($variables['theme_group_titles'] as $state => $title) {
249 if (!count($theme_groups[$state])) {
250 // Skip this group of themes if no theme is there.
253 // Start new theme group.
255 $theme_group['state'] = $state;
256 $theme_group['title'] = $title;
257 $theme_group['themes'] = [];
258 $theme_group['attributes'] = new Attribute();
260 foreach ($theme_groups[$state] as $theme) {
263 // Screenshot depicting the theme.
264 if ($theme->screenshot) {
265 $current_theme['screenshot'] = [
267 '#uri' => $theme->screenshot['uri'],
268 '#alt' => $theme->screenshot['alt'],
269 '#title' => $theme->screenshot['title'],
270 '#attributes' => $theme->screenshot['attributes'],
274 $current_theme['screenshot'] = [
276 '#uri' => drupal_get_path('module', 'system') . '/images/no_screenshot.png',
277 '#alt' => t('No screenshot'),
278 '#title' => t('No screenshot'),
279 '#attributes' => new Attribute(['class' => ['no-screenshot']]),
283 // Localize the theme description.
284 $current_theme['description'] = t($theme->info['description']);
286 $current_theme['attributes'] = new Attribute();
287 $current_theme['name'] = $theme->info['name'];
288 $current_theme['version'] = isset($theme->info['version']) ? $theme->info['version'] : '';
289 $current_theme['notes'] = $theme->notes;
290 $current_theme['is_default'] = $theme->is_default;
291 $current_theme['is_admin'] = $theme->is_admin;
293 // Make sure to provide feedback on compatibility.
294 $current_theme['incompatible'] = '';
295 if (!empty($theme->incompatible_core)) {
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]);
298 elseif (!empty($theme->incompatible_region)) {
299 $current_theme['incompatible'] = t("This theme is missing a 'content' region.");
301 elseif (!empty($theme->incompatible_php)) {
302 if (substr_count($theme->info['php'], '.') < 2) {
303 $theme->info['php'] .= '.*';
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()]);
307 elseif (!empty($theme->incompatible_base)) {
308 $current_theme['incompatible'] = t('This theme requires the base theme @base_theme to operate correctly.', ['@base_theme' => $theme->info['base theme']]);
310 elseif (!empty($theme->incompatible_engine)) {
311 $current_theme['incompatible'] = t('This theme requires the theme engine @theme_engine to operate correctly.', ['@theme_engine' => $theme->info['engine']]);
314 // Build operation links.
315 $current_theme['operations'] = [
317 '#links' => $theme->operations,
319 'class' => ['operations', 'clearfix'],
322 $theme_group['themes'][] = $current_theme;
324 $groups[] = $theme_group;
326 $variables['theme_groups'] = $groups;