function SystemAdminThemePreprocess::preprocessSystemModulesUninstall

Prepares variables for module uninstall templates.

Default template: system-modules-uninstall.html.twig.

Parameters

array $variables: An associative array containing:

  • form: A render element representing the form. Child elements of the form are individual modules. Each module is an associative array containing the following elements:

    • #module_name: The name of the module as a string.
    • name: The name of the module in a renderable array.
    • description: A description of the module.
    • #required_by: (optional) A list of modules that require the module.
    • #validation_reasons: (optional) Additional reasons why the module cannot be uninstalled.
    • #attributes: A list of attributes for the module wrapper.

Related topics

File

core/modules/system/src/Theme/SystemAdminThemePreprocess.php, line 242

Class

SystemAdminThemePreprocess
Hook implementations for system.

Namespace

Drupal\system\Theme

Code

public function preprocessSystemModulesUninstall(array &$variables) : void {
  $form = $variables['form'];
  $variables['modules'] = [];
  // Iterate through all the modules, which are children of this element.
  foreach (Element::children($form['modules']) as $key) {
    $module = $form['modules'][$key];
    $module['module_name'] = $module['#module_name'];
    $module['checkbox'] = $form['uninstall'][$key];
    $module['checkbox_id'] = $form['uninstall'][$key]['#id'];
    if (!empty($module['#validation_reasons'])) {
      $module['validation_reasons'] = $module['#validation_reasons'];
      $module['reasons_count'] = count($module['validation_reasons']);
    }
    else {
      $module['reasons_count'] = 0;
    }
    if (!empty($module['#required_by'])) {
      $module['required_by'] = $module['#required_by'];
      $module['reasons_count'] = $module['reasons_count'] + 1;
    }
    $module['attributes'] = new Attribute($module['#attributes']);
    $variables['modules'][] = $module;
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.