function template_preprocess_system_modules_details in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/system.admin.inc \template_preprocess_system_modules_details()
Prepares variables for the module details templates.
Default template: system-modules-details.html.twig.
Parameters
$variables: An associative array containing:
- 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.
See also
\Drupal\system\Form\ModulesListForm
File
- core/
modules/ system/ system.admin.inc, line 190 - Admin page callbacks for the system module.
Code
function template_preprocess_system_modules_details(&$variables) {
$form = $variables['form'];
$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];
unset($module['enable']['#title']);
$module['#requires'] = array_filter($module['#requires']);
$module['#required_by'] = array_filter($module['#required_by']);
// 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);
$module['id'] = $id;
$module['enable_id'] = $module['enable']['#id'];
// @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>',
];
$module['machine_name'] = $renderer
->render($machine_name_render);
if (!empty($module['#requires'])) {
$requires = [
'#theme' => 'item_list',
'#items' => $module['#requires'],
'#context' => [
'list_style' => 'comma-list',
],
];
$module['requires'] = $renderer
->render($requires);
}
if (!empty($module['#required_by'])) {
$required_by = [
'#theme' => 'item_list',
'#items' => $module['#required_by'],
'#context' => [
'list_style' => 'comma-list',
],
];
$module['required_by'] = $renderer
->render($required_by);
}
if (!empty($module['version'])) {
$module['version'] = $renderer
->render($module['version']);
}
$module['attributes'] = new Attribute($module['#attributes']);
$variables['modules'][] = $module;
}
}