You are here

function template_preprocess_shrinktheweb_modules_fieldset in ShrinkTheWeb 8

Prepares variables for the module details templates.

Default template: shrinktheweb-modules-fieldset.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

./shrinktheweb.module, line 463

Code

function template_preprocess_shrinktheweb_modules_fieldset(&$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']);
    $module['link_types'] = array_filter(array_keys($module['links']), '_shrinktheweb_link_check');
    $variables['modules'][] = $module;
  }
}