Chris@0: $item) { Chris@0: $variables['content'][$key]['link'] = \Drupal::l($item['title'], $item['url']); Chris@0: if (!$variables['compact'] && isset($item['description'])) { Chris@0: $variables['content'][$key]['description'] = ['#markup' => $item['description']]; Chris@0: } Chris@0: else { Chris@0: $variables['content'][$key]['description'] = FALSE; Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for administrative index page templates. Chris@0: * Chris@0: * Default template: admin-page.html.twig. Chris@0: * Chris@0: * @param $variables Chris@0: * An associative array containing: Chris@0: * - blocks: An array of blocks to display. Each array should include a Chris@0: * 'title', a 'description', a formatted 'content' and a 'position' which Chris@0: * will control which container it will be in. This is usually 'left' or Chris@0: * 'right'. Chris@0: */ Chris@0: function template_preprocess_admin_page(&$variables) { Chris@0: $variables['system_compact_link'] = [ Chris@0: '#type' => 'system_compact_link', Chris@0: ]; Chris@0: $variables['containers'] = []; Chris@0: $stripe = 0; Chris@0: foreach ($variables['blocks'] as $block) { Chris@0: if (!empty($block['content']['#content'])) { Chris@0: if (empty($block['position'])) { Chris@0: // Perform automatic striping. Chris@0: $block['position'] = ++$stripe % 2 ? 'left' : 'right'; Chris@0: } Chris@0: $variables['containers'][$block['position']]['blocks'][] = [ Chris@0: '#theme' => 'admin_block', Chris@0: '#block' => $block, Chris@0: ]; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for admin index templates. Chris@0: * Chris@0: * Default template: system-admin-index.html.twig. Chris@0: * Chris@0: * @param $variables Chris@0: * An associative array containing: Chris@0: * - menu_items: An array of modules to be displayed. Chris@0: */ Chris@0: function template_preprocess_system_admin_index(&$variables) { Chris@0: $variables['system_compact_link'] = [ Chris@0: '#type' => 'system_compact_link', Chris@0: ]; Chris@0: $variables['containers'] = []; Chris@0: $stripe = 0; Chris@0: // Iterate over all modules. Chris@0: foreach ($variables['menu_items'] as $module => $block) { Chris@0: list($description, $items) = $block; Chris@0: $position = ++$stripe % 2 ? 'left' : 'right'; Chris@0: // Output links. Chris@0: if (count($items)) { Chris@0: $variables['containers'][$position][] = [ Chris@0: '#theme' => 'admin_block', Chris@0: '#block' => [ Chris@0: 'position' => $position, Chris@0: 'title' => $module, Chris@0: 'content' => [ Chris@0: '#theme' => 'admin_block_content', Chris@0: '#content' => $items, Chris@0: ], Chris@0: 'description' => t($description), Chris@0: ], Chris@0: ]; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for the module details templates. Chris@0: * Chris@0: * Default template: system-modules-details.html.twig. Chris@0: * Chris@0: * @param $variables Chris@0: * An associative array containing: Chris@0: * - form: A render element representing the form. The main form element Chris@0: * represents a package, and child elements of the form are individual Chris@0: * projects. Each project (or module) is an associative array containing the Chris@0: * following elements: Chris@0: * - name: The name of the module. Chris@0: * - enable: A checkbox for enabling the module. Chris@0: * - description: A description of the module. Chris@0: * - version: The version of the module. Chris@0: * - links: Administration links provided by the module. Chris@0: * - #requires: A list of modules that the project requires. Chris@0: * - #required_by: A list of modules that require the project. Chris@0: * - #attributes: A list of attributes for the module wrapper. Chris@0: * Chris@0: * @see \Drupal\system\Form\ModulesListForm Chris@0: */ Chris@0: function template_preprocess_system_modules_details(&$variables) { Chris@0: $form = $variables['form']; Chris@0: Chris@0: $variables['modules'] = []; Chris@0: // Iterate through all the modules, which are children of this element. Chris@0: foreach (Element::children($form) as $key) { Chris@0: // Stick the key into $module for easier access. Chris@0: $module = $form[$key]; Chris@0: unset($module['enable']['#title']); Chris@0: $module['#requires'] = array_filter($module['#requires']); Chris@0: $module['#required_by'] = array_filter($module['#required_by']); Chris@0: // Add the checkbox to allow installing new modules and to show the Chris@0: // installation status of the module. Chris@0: $module['checkbox'] = $module['enable']; Chris@0: Chris@0: // Add the module label and expand/collapse functionality. Chris@0: $id = Html::getUniqueId('module-' . $key); Chris@0: $module['id'] = $id; Chris@0: $module['enable_id'] = $module['enable']['#id']; Chris@0: Chris@0: // @todo Remove early rendering and use safe_join in the Twig template once Chris@0: // https://www.drupal.org/node/2579091 is fixed. Chris@0: $renderer = \Drupal::service('renderer'); Chris@0: $machine_name_render = [ Chris@0: '#prefix' => '', Chris@0: '#plain_text' => $key, Chris@0: '#suffix' => '', Chris@0: ]; Chris@0: $module['machine_name'] = $renderer->render($machine_name_render); Chris@0: Chris@0: if (!empty($module['#requires'])) { Chris@0: $requires = [ Chris@0: '#theme' => 'item_list', Chris@0: '#items' => $module['#requires'], Chris@0: '#context' => ['list_style' => 'comma-list'], Chris@0: ]; Chris@0: $module['requires'] = $renderer->render($requires); Chris@0: } Chris@0: if (!empty($module['#required_by'])) { Chris@0: $required_by = [ Chris@0: '#theme' => 'item_list', Chris@0: '#items' => $module['#required_by'], Chris@0: '#context' => ['list_style' => 'comma-list'], Chris@0: ]; Chris@0: $module['required_by'] = $renderer->render($required_by); Chris@0: } Chris@0: Chris@0: if (!empty($module['version'])) { Chris@0: $module['version'] = $renderer->render($module['version']); Chris@0: } Chris@0: Chris@0: $module['attributes'] = new Attribute($module['#attributes']); Chris@0: $variables['modules'][] = $module; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for module uninstall templates. Chris@0: * Chris@0: * Default template: system-modules-uninstall.html.twig. Chris@0: * Chris@0: * @param $variables Chris@0: * An associative array containing: Chris@0: * - form: A render element representing the form. Child elements of the form Chris@0: * are individual modules. Each module is an associative array containing Chris@0: * the following elements: Chris@0: * - #module_name: The name of the module as a string. Chris@0: * - name: The name of the module in a renderable array. Chris@0: * - description: A description of the module. Chris@0: * - #required_by: (optional) A list of modules that require the module. Chris@0: * - #validation_reasons: (optional) Additional reasons why the module Chris@0: * cannot be uninstalled. Chris@0: * - #attributes: A list of attributes for the module wrapper. Chris@0: * Chris@0: * @ingroup themeable Chris@0: */ Chris@0: function template_preprocess_system_modules_uninstall(&$variables) { Chris@0: $form = $variables['form']; Chris@0: $variables['modules'] = []; Chris@0: Chris@0: // Iterate through all the modules, which are children of this element. Chris@0: foreach (Element::children($form['modules']) as $key) { Chris@0: $module = $form['modules'][$key]; Chris@0: $module['module_name'] = $module['#module_name']; Chris@0: $module['checkbox'] = $form['uninstall'][$key]; Chris@0: $module['checkbox_id'] = $form['uninstall'][$key]['#id']; Chris@0: Chris@0: if (!empty($module['#validation_reasons'])) { Chris@0: $module['validation_reasons'] = $module['#validation_reasons']; Chris@0: $module['reasons_count'] = count($module['validation_reasons']); Chris@0: } Chris@0: else { Chris@0: $module['reasons_count'] = 0; Chris@0: } Chris@0: if (!empty($module['#required_by'])) { Chris@0: $module['required_by'] = $module['#required_by']; Chris@0: $module['reasons_count'] = $module['reasons_count'] + 1; Chris@0: } Chris@0: $module['attributes'] = new Attribute($module['#attributes']); Chris@0: $variables['modules'][] = $module; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for appearance page templates. Chris@0: * Chris@0: * Default template: system-themes-page.html.twig. Chris@0: * Chris@0: * @param $variables Chris@0: * An associative array containing: Chris@0: * - theme_groups: An associative array containing groups of themes. Chris@0: * - theme_group_titles: An associative array containing titles of themes. Chris@0: */ Chris@0: function template_preprocess_system_themes_page(&$variables) { Chris@0: $groups = []; Chris@0: $theme_groups = $variables['theme_groups']; Chris@0: $variables['attributes']['id'] = 'system-themes-page'; Chris@0: Chris@0: foreach ($variables['theme_group_titles'] as $state => $title) { Chris@0: if (!count($theme_groups[$state])) { Chris@0: // Skip this group of themes if no theme is there. Chris@0: continue; Chris@0: } Chris@0: // Start new theme group. Chris@0: $theme_group = []; Chris@0: $theme_group['state'] = $state; Chris@0: $theme_group['title'] = $title; Chris@0: $theme_group['themes'] = []; Chris@0: $theme_group['attributes'] = new Attribute(); Chris@0: Chris@0: foreach ($theme_groups[$state] as $theme) { Chris@0: $current_theme = []; Chris@0: Chris@0: // Screenshot depicting the theme. Chris@0: if ($theme->screenshot) { Chris@0: $current_theme['screenshot'] = [ Chris@0: '#theme' => 'image', Chris@0: '#uri' => $theme->screenshot['uri'], Chris@0: '#alt' => $theme->screenshot['alt'], Chris@0: '#title' => $theme->screenshot['title'], Chris@0: '#attributes' => $theme->screenshot['attributes'], Chris@0: ]; Chris@0: } Chris@0: else { Chris@0: $current_theme['screenshot'] = [ Chris@0: '#theme' => 'image', Chris@0: '#uri' => drupal_get_path('module', 'system') . '/images/no_screenshot.png', Chris@0: '#alt' => t('No screenshot'), Chris@0: '#title' => t('No screenshot'), Chris@0: '#attributes' => new Attribute(['class' => ['no-screenshot']]), Chris@0: ]; Chris@0: } Chris@0: Chris@0: // Localize the theme description. Chris@0: $current_theme['description'] = t($theme->info['description']); Chris@0: Chris@0: $current_theme['attributes'] = new Attribute(); Chris@0: $current_theme['name'] = $theme->info['name']; Chris@0: $current_theme['version'] = isset($theme->info['version']) ? $theme->info['version'] : ''; Chris@0: $current_theme['notes'] = $theme->notes; Chris@0: $current_theme['is_default'] = $theme->is_default; Chris@0: $current_theme['is_admin'] = $theme->is_admin; Chris@0: Chris@0: // Make sure to provide feedback on compatibility. Chris@0: $current_theme['incompatible'] = ''; Chris@0: if (!empty($theme->incompatible_core)) { Chris@0: $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: } Chris@0: elseif (!empty($theme->incompatible_region)) { Chris@0: $current_theme['incompatible'] = t("This theme is missing a 'content' region."); Chris@0: } Chris@0: elseif (!empty($theme->incompatible_php)) { Chris@0: if (substr_count($theme->info['php'], '.') < 2) { Chris@0: $theme->info['php'] .= '.*'; Chris@0: } Chris@0: $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: } Chris@0: elseif (!empty($theme->incompatible_base)) { Chris@0: $current_theme['incompatible'] = t('This theme requires the base theme @base_theme to operate correctly.', ['@base_theme' => $theme->info['base theme']]); Chris@0: } Chris@0: elseif (!empty($theme->incompatible_engine)) { Chris@0: $current_theme['incompatible'] = t('This theme requires the theme engine @theme_engine to operate correctly.', ['@theme_engine' => $theme->info['engine']]); Chris@0: } Chris@0: Chris@0: // Build operation links. Chris@0: $current_theme['operations'] = [ Chris@0: '#theme' => 'links', Chris@0: '#links' => $theme->operations, Chris@0: '#attributes' => [ Chris@0: 'class' => ['operations', 'clearfix'], Chris@0: ], Chris@0: ]; Chris@0: $theme_group['themes'][] = $current_theme; Chris@0: } Chris@0: $groups[] = $theme_group; Chris@0: } Chris@0: $variables['theme_groups'] = $groups; Chris@0: }