Commit 02bd75b1 authored by webchick's avatar webchick

Issue #2151109 by akalata, Cottser, joelpittet, jcnventura, lauriii, derheap:...

Issue #2151109 by akalata, Cottser, joelpittet, jcnventura, lauriii, derheap: Convert theme_system_modules_details() to Twig
parent e55a7d8d
......@@ -170,11 +170,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#title' => $this->t($package),
'#open' => TRUE,
'#theme' => 'system_modules_details',
'#header' => array(
array('data' => $this->t('Installed'), 'class' => array('checkbox', 'visually-hidden')),
array('data' => $this->t('Name'), 'class' => array('name', 'visually-hidden')),
array('data' => $this->t('Description'), 'class' => array('description', 'visually-hidden', RESPONSIVE_PRIORITY_LOW)),
),
'#attributes' => array('class' => array('package-listing')),
// Ensure that the "Core" package comes first.
'#weight' => $package == 'Core' ? -10 : NULL,
......@@ -226,7 +221,6 @@ protected function buildRow(array $modules, Extension $module, $distribution) {
// Generate link for module's help page. Assume that if a hook_help()
// implementation exists then the module provides an overview page, rather
// than checking to see if the page exists, which is costly.
$row['links']['help'] = array();
if ($this->moduleHandler->moduleExists('help') && $module->status && in_array($module->getName(), $this->moduleHandler->getImplementations('help'))) {
$row['links']['help'] = array(
'#type' => 'link',
......@@ -237,7 +231,6 @@ protected function buildRow(array $modules, Extension $module, $distribution) {
}
// Generate link for module's permission, if the user has access to it.
$row['links']['permissions'] = array();
if ($module->status && $this->currentUser->hasPermission('administer permissions') && $this->permissionHandler->moduleProvidesPermissions($module->getName())) {
$row['links']['permissions'] = array(
'#type' => 'link',
......@@ -248,7 +241,6 @@ protected function buildRow(array $modules, Extension $module, $distribution) {
}
// Generate link for module's configuration page, if it has one.
$row['links']['configure'] = array();
if ($module->status && isset($module->info['configure'])) {
$route_parameters = isset($module->info['configure_parameters']) ? $module->info['configure_parameters'] : array();
if ($this->accessManager->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser)) {
......
......@@ -49,6 +49,11 @@ 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 the Testing module's machine name is printed. Testing module
// is used because its machine name is different than its human readable
// name.
$this->assertText('simpletest');
}
}
......@@ -170,110 +170,81 @@ 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.
* - 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: A description of the module.
* - version: The version of the module.
* - links: Administration links provided by the module.
* - #requires: A list of modules that the project requires.
* - #required_by: A list of modules that require the project.
* - #attributes: A list of attributes for the module wrapper.
*
* @ingroup themeable
* @see \Drupal\system\Form\ModulesListForm
*/
function theme_system_modules_details($variables) {
function template_preprocess_system_modules_details(&$variables) {
$form = $variables['form'];
// 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' => '<label id="{{ id }}" for="{{ enable_id }}" class="module-name table-filter-text-source">{{ module_name }}</label>',
'#context' => [
'id' => $id,
'enable_id' => $module['enable']['#id'],
'module_name' => $module['name'],
],
];
$row[] = ['class' => ['module'], 'data' => $col2];
$module['id'] = $id;
$module['enable_id'] = $module['enable']['#id'];
// Add the description, along with any modules it requires.
$description = '';
$description .= '<div class="requirements">';
// @todo Remove early rendering and use safe_join in the Twig template once
// https://www.drupal.org/node/2579091 is fixed.
$renderer = \Drupal::service('renderer');
$machine_name_render = [
'#prefix' => '<span dir="ltr" class="table-filter-text-source">',
'#plain_text' => $key,
'#suffix' => '</span'
'#suffix' => '</span>',
];
$description .= '<div class="admin-requirements">' . t('Machine name: @machine-name', array('@machine-name' => $renderer->render($machine_name_render))) . '</div>';
if ($version) {
$description .= '<div class="admin-requirements">' . t('Version: @module-version', array('@module-version' => $renderer->render($module['version']))) . '</div>';
}
if ($requires) {
$module['machine_name'] = $renderer->render($machine_name_render);
if (!empty($module['#requires'])) {
$requires = [
'#theme' => 'item_list',
'#items' => $module['#requires'],
'#context' => ['list_style' => 'comma-list'],
];
$description .= '<div class="admin-requirements">' . t('Requires: @module-list', array('@module-list' => $renderer->render($requires))) . '</div>';
$module['requires'] = $renderer->render($requires);
}
if ($required_by) {
if (!empty($module['#required_by'])) {
$required_by = [
'#theme' => 'item_list',
'#items' => $module['#required_by'],
'#context' => ['list_style' => 'comma-list'],
];
$description .= '<div class="admin-requirements">' . t('Required by: @module-list', array('@module-list' => $renderer->render($required_by))) . '</div>';
$module['required_by'] = $renderer->render($required_by);
}
$description .= '</div>';
$links = '';
foreach (array('help', 'permissions', 'configure') as $link_type) {
$links .= drupal_render($module['links'][$link_type]);
}
if ($links) {
$description .= ' <div class="links">';
$description .= $links;
$description .= '</div>';
if (!empty($module['version'])) {
$module['version'] = $renderer->render($module['version']);
}
$title = [
'#type' => 'inline_template',
'#template' => '<span class="text module-description">{{ module_description }}</span>',
'#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];
$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);
}
/**
......
......@@ -187,7 +187,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',
......
{#
/**
* @file
* Default theme implementation for the modules listing page.
*
* Displays a list of all packages in a project.
*
* Available variables:
* - 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 unique identifier for interacting with the details element.
* - enable_id: A unique identifier for interacting with the checkbox element.
* - description: The description of the module.
* - machine_name: The module's machine name.
* - version: Information about the module version.
* - requires: A list of modules that this module requires.
* - required_by: A list of modules that require this module.
* - links: A list of administration links provided by the module.
*
* @see template_preprocess_system_modules_details()
*
* @ingroup themeable
*/
#}
<table class="responsive-enabled" data-striping="1">
<thead>
<tr>
<th class="checkbox visually-hidden">{{ 'Installed'|t }}</th>
<th class="name visually-hidden">{{ 'Name'|t }}</th>
<th class="description visually-hidden priority-low">{{ 'Description'|t }}</th>
</tr>
</thead>
<tbody>
{% for module in modules %}
{% set zebra = cycle(['odd', 'even'], loop.index0) %}
<tr{{ module.attributes.addClass(zebra) }}>
<td class="checkbox">
{{ module.checkbox }}
</td>
<td class="module">
<label id="{{ module.id }}" for="{{ module.enable_id }}" class="module-name table-filter-text-source">{{ module.name }}</label>
</td>
<td class="description expand priority-low">
<details class="js-form-wrapper form-wrapper" id="{{ module.enable_id }}-description">
<summary aria-controls="{{ module.enable_id }}-description" role="button" aria-expanded="false"><span class="text module-description">{{ module.description }}</span></summary>
<div class="details-wrapper">
<div class="details-description">
<div class="requirements">
<div class="admin-requirements">{{ 'Machine name: <span dir="ltr" class="table-filter-text-source">@machine-name</span>'|t({'@machine-name': module.machine_name }) }}</div>
{% if module.version %}
<div class="admin-requirements">{{ 'Version: @module-version'|t({'@module-version': module.version }) }}</div>
{% endif %}
{% if module.requires %}
<div class="admin-requirements">{{ 'Requires: @module-list'|t({'@module-list': module.requires }) }}</div>
{% endif %}
{% if module.required_by %}
<div class="admin-requirements">{{ 'Required by: @module-list'|t({'@module-list': module.required_by }) }}</div>
{% endif %}
</div>
{% if module.links %}
<div class="links">
{% for link_type in ['help', 'permissions', 'configure'] %}
{{ module.links[link_type] }}
{% endfor %}
</div>
{% endif %}
</div>
</div>
</details>
</td>
</tr>
{% endfor %}
</tbody>
</table>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment