function template_preprocess_system_modules_uninstall

Same name in other branches
  1. 9 core/modules/system/system.admin.inc \template_preprocess_system_modules_uninstall()
  2. 8.9.x core/modules/system/system.admin.inc \template_preprocess_system_modules_uninstall()
  3. 11.x core/modules/system/system.admin.inc \template_preprocess_system_modules_uninstall()

Prepares variables for module uninstall templates.

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

Parameters

$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/system.admin.inc, line 223

Code

function template_preprocess_system_modules_uninstall(&$variables) {
    $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.