diff --git a/core/modules/system/src/Tests/Form/ModulesListFormWebTest.php b/core/modules/system/src/Tests/Form/ModulesListFormWebTest.php index 489f6ff..94c4656 100644 --- a/core/modules/system/src/Tests/Form/ModulesListFormWebTest.php +++ b/core/modules/system/src/Tests/Form/ModulesListFormWebTest.php @@ -49,6 +49,10 @@ public function testModuleListForm() { // Check that system_test's help link was rendered correctly. $this->assertFieldByXPath("//a[contains(@href, '/admin/help/system_test') and @title='Help']"); + + // Ensure that Testing modules machine name is printed. Testing module is + // used because its machine name is different than its human readable name. + $this->assertText('simpletest'); } } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 11b72a5..fd818da3 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -170,110 +170,63 @@ function template_preprocess_status_report(&$variables) { } /** - * Returns HTML for the modules form. + * Prepares variables for the module details templates. + * + * Default template: system-modules-details.html.twig. * * @param $variables * An associative array containing: - * - form: A render element representing the form. - * - * @ingroup themeable + * - form: A render element representing the form. The main form element + * represents a package, and child elements of the form are individual + * projects. Each project (or module) is an associative array containing the + * following elements: + * - name: The name of the module. + * - enable: A checkbox for enabling the module. + * - description: (optional) A description of the module. + * - version: (optional) The version of the module. + * - links: (optional) Administration links provided by the module. + * - requires: (optional) A list of modules that the project requires. + * - required_by: (optional) A list of modules that require the project. */ -function theme_system_modules_details($variables) { +function template_preprocess_system_modules_details(&$variables) { $form = $variables['form']; + $variables['header'] = [ + 'installed' => $form['#header'][0]['data'], + 'name' => $form['#header'][1]['data'], + 'description' => $form['#header'][2]['data'], + ]; - // Individual table headers. - $rows = array(); + $variables['modules'] = []; // Iterate through all the modules, which are children of this element. foreach (Element::children($form) as $key) { // Stick the key into $module for easier access. $module = $form[$key]; - // Create the row for the table. - $row = array(); - // Add the checkbox into the first cell. unset($module['enable']['#title']); - $module['#requires'] = array_filter($module['#requires']); - $module['#required_by'] = array_filter($module['#required_by']); - - $requires = !empty($module['#requires']); - $required_by = !empty($module['#required_by']); - $version = !empty($module['version']['#markup']); - - $row[] = array('class' => array('checkbox'), 'data' => drupal_render($module['enable'])); + // Add the checkbox to allow installing new modules and to show the + // installation status of the module. + $module['checkbox'] = $module['enable']; // Add the module label and expand/collapse functionality. $id = Html::getUniqueId('module-' . $key); - $col2 = [ - '#type' => 'inline_template', - '#template' => '', - '#context' => [ - 'id' => $id, - 'enable_id' => $module['enable']['#id'], - 'module_name' => $module['name'], - ], - ]; - $row[] = ['class' => ['module'], 'data' => $col2]; - - // Add the description, along with any modules it requires. - $description = ''; - $description .= '
'; - $renderer = \Drupal::service('renderer'); - $machine_name_render = [ - '#prefix' => '', - '#plain_text' => $key, - '#suffix' => ' $renderer->render($machine_name_render))) . '
'; - if ($version) { - $description .= '
' . t('Version: @module-version', array('@module-version' => $renderer->render($module['version']))) . '
'; - } - if ($requires) { - $requires = [ - '#theme' => 'item_list', - '#items' => $module['#requires'], - '#context' => ['list_style' => 'comma-list'], - ]; - $description .= '
' . t('Requires: @module-list', array('@module-list' => $renderer->render($requires))) . '
'; + $module['id'] = $id; + $module['enable_id'] = $module['enable']['#id']; + $module['machine_name'] = $key; + if (empty($module['version']['#markup'])) { + unset($module['version']); } - if ($required_by) { - $required_by = [ - '#theme' => 'item_list', - '#items' => $module['#required_by'], - '#context' => ['list_style' => 'comma-list'], - ]; - $description .= '
' . t('Required by: @module-list', array('@module-list' => $renderer->render($required_by))) . '
'; - } - $description .= ''; - $links = ''; - foreach (array('help', 'permissions', 'configure') as $link_type) { - $links .= drupal_render($module['links'][$link_type]); - } - if ($links) { - $description .= ' '; + + $module['requires'] = array_filter($module['#requires']); + $module['required_by'] = array_filter($module['#required_by']); + + $links = []; + foreach (['help', 'permissions', 'configure'] as $link_type) { + $links[] = $module['links'][$link_type]; } - $title = [ - '#type' => 'inline_template', - '#template' => '{{ module_description }}', - '#context' => ['module_description' => $module['description']], - ]; - $details = array( - '#type' => 'details', - '#title' => $title, - '#attributes' => array('id' => $module['enable']['#id'] . '-description'), - '#description' => $description, - ); - $row[] = ['class' => ['description', 'expand'], 'data' => $details]; + $module['links'] = $links; - $rows[] = $module['#attributes'] + array('data' => $row); + $module['attributes'] = new Attribute($module['#attributes']); + $variables['modules'][] = $module; } - - $table = array( - '#type' => 'table', - '#header' => $form['#header'], - '#rows' => $rows, - ); - return drupal_render($table); } /** @@ -305,8 +258,8 @@ function theme_system_modules_uninstall($variables) { $disabled_header = ''; $disabled_reasons = ''; // Add the modules requiring the module in question as a validation reason. - if (!empty($form['modules'][$module]['#required_by'])) { - $form['modules'][$module]['#validation_reasons'][] = \Drupal::translation()->translate('Required by: @modules', array('@modules' => implode(', ',$form['modules'][$module]['#required_by']))); + if (!empty($form['modules'][$module]['required_by'])) { + $form['modules'][$module]['#validation_reasons'][] = \Drupal::translation()->translate('Required by: @modules', array('@modules' => implode(', ',$form['modules'][$module]['required_by']))); } if (!empty($form['modules'][$module]['#validation_reasons'])) { $disabled_reasons = [ diff --git a/core/modules/system/system.module b/core/modules/system/system.module index a8477d3..9be5618 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -186,7 +186,6 @@ function system_theme() { 'system_modules_details' => array( 'render element' => 'form', 'file' => 'system.admin.inc', - 'function' => 'theme_system_modules_details', ), 'system_modules_uninstall' => array( 'render element' => 'form', diff --git a/core/modules/system/templates/system-modules-details.html.twig b/core/modules/system/templates/system-modules-details.html.twig new file mode 100644 index 0000000..8e02684 --- /dev/null +++ b/core/modules/system/templates/system-modules-details.html.twig @@ -0,0 +1,86 @@ +{# +/** + * @file + * Default theme implementation for the modules listing page. + * + * Displays a list of all packages in a project. + * + * Available variables: + * - header: Table header containing the following cells: + * - installed: A localized string for the title of the Installed column. + * - namet: A localized string for the title of the Name column. + * - description: A localized string for the title of the Description column. + * - modules: Contains multiple module instances. Each module contains: + * - attributes: Attributes on the row. + * - checkbox: A checkbox for enabling the module. + * - name: The human-readable name of the module. + * - id: A unqiue id for interacting with the details element. + * - enable_id: A unique id for interacting with the checkbox element. + * - description: The description of the module. + * - machine_name: The module's machine name. + * - version: (optional) Information about the module version. + * - requires: (optional) A list of modules that this module requires. + * - required_by: (optional) A list of modules that require this module. + * - links: (optional) A list of administration links provided by the module. + * + * @see template_preprocess_system_modules_details() + * + * @ingroup themeable + */ +#} + + + + + + + + + + {% for module in modules %} + {% set zebra = cycle(['odd', 'even'], loop.index0) %} + + + + + + {% endfor %} + +
+ {{ header.installed }} + + {{ header.name }} + + {{ header.description }} +
+ {{ module.checkbox }} + + + +
+ + {{ module.description }} + +
+
+
{{ 'Machine name:'|t }} {{ module.machine_name }}
+ {% if module.version %} +
{{ 'Version:'|t }} {{ module.version }}
+ {% endif %} + {% if module.requires %} +
{{ 'Requires:'|t }} {{ module.requires|safe_join(', ') }}
+ {% endif %} + {% if module.required_by %} +
{{ 'Required by:'|t }} {{ module.required_by|safe_join(', ') }}
+ {% endif %} + {% if module.links %} + + {% endif %} +
+
+
+