diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index 43969d4380..6a3383778b 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -150,7 +150,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['modules']['#tree'] = TRUE; foreach ($modules as $filename => $module) { if (empty($module->info['hidden'])) { - $package = $module->info['package']; + $package = $module->status ? 'Installed modules' : $module->info['package']; $form['modules'][$package][$filename] = $this->buildRow($modules, $module, $distribution); $form['modules'][$package][$filename]['#parents'] = ['modules', $filename]; } @@ -164,20 +164,36 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#open' => TRUE, '#theme' => 'system_modules_details', '#attributes' => ['class' => ['package-listing']], - // Ensure that the "Core" package comes first. - '#weight' => $package == 'Core' ? -10 : NULL, ]; + // Ensure that the "Installed modules" and "Core" packages come first. + $weight = NULL; + switch ($package) { + case 'Core': + $weight = -10; + break; + + case 'Installed modules': + $weight = -11; + break; + } + $form['modules'][$package]['#weight'] = $weight; } - // If testing modules are shown, collapse the corresponding package by - // default. + // If enabled or testing modules are shown, collapse the corresponding + // packages by default. if (isset($form['modules']['Testing'])) { $form['modules']['Testing']['#open'] = FALSE; } + if (isset($form['modules']['Installed modules'])) { + $form['modules']['Installed modules']['#open'] = FALSE; + } // Lastly, sort all packages by title. uasort($form['modules'], ['\Drupal\Component\Utility\SortArray', 'sortByTitleProperty']); + + $form['modules']['Installed modules']['#description'] = t('Some modules may be uninstalled on the Uninstall page.', [':url' => \Drupal::url('system.modules_uninstall')]); + $form['#attached']['library'][] = 'system/drupal.system.modules'; $form['actions'] = ['#type' => 'actions']; $form['actions']['submit'] = [ @@ -251,17 +267,16 @@ protected function buildRow(array $modules, Extension $module, $distribution) { } // Present a checkbox for installing and indicating the status of a module. - $row['enable'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Install'), - '#default_value' => (bool) $module->status, - '#disabled' => (bool) $module->status, - ]; + if (!$module->status && empty($module->info['required'])) { + $row['enable'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Install'), + ]; + } // Disable the checkbox for required modules. if (!empty($module->info['required'])) { // Used when displaying modules that are required by the installation profile - $row['enable']['#disabled'] = TRUE; $row['#required_by'][] = $distribution . (!empty($module->info['explanation']) ? ' (' . $module->info['explanation'] . ')' : ''); } @@ -293,7 +308,9 @@ protected function buildRow(array $modules, Extension $module, $distribution) { // If this module is not compatible, disable the checkbox. if (!$compatible) { $status = implode(' ', $reasons); - $row['enable']['#disabled'] = TRUE; + if (!empty($row['enable'])) { + $row['enable']['#disabled'] = TRUE; + } $row['description']['#markup'] = $status; $row['#attributes']['class'][] = 'incompatible'; } @@ -302,7 +319,9 @@ protected function buildRow(array $modules, Extension $module, $distribution) { foreach ($module->requires as $dependency => $version) { if (!isset($modules[$dependency])) { $row['#requires'][$dependency] = $this->t('@module (missing)', ['@module' => Unicode::ucfirst($dependency)]); - $row['enable']['#disabled'] = TRUE; + if (!empty($row['enable'])) { + $row['enable']['#disabled'] = TRUE; + } } // Only display visible modules. elseif (empty($modules[$dependency]->hidden)) { @@ -314,7 +333,9 @@ protected function buildRow(array $modules, Extension $module, $distribution) { '@module' => $name . $incompatible_version, '@version' => $modules[$dependency]->info['version'], ]); - $row['enable']['#disabled'] = TRUE; + if (!empty($row['enable'])) { + $row['enable']['#disabled'] = TRUE; + } } // Disable the checkbox if the dependency is incompatible with this // version of Drupal core. @@ -322,7 +343,9 @@ protected function buildRow(array $modules, Extension $module, $distribution) { $row['#requires'][$dependency] = $this->t('@module (incompatible with this version of Drupal core)', [ '@module' => $name, ]); - $row['enable']['#disabled'] = TRUE; + if (!empty($row['enable'])) { + $row['enable']['#disabled'] = TRUE; + } } elseif ($modules[$dependency]->status) { $row['#requires'][$dependency] = $this->t('@module', ['@module' => $name]); @@ -339,7 +362,9 @@ protected function buildRow(array $modules, Extension $module, $distribution) { if (isset($modules[$dependent]) && empty($modules[$dependent]->info['hidden'])) { if ($modules[$dependent]->status == 1 && $module->status == 1) { $row['#required_by'][$dependent] = $this->t('@module', ['@module' => $modules[$dependent]->info['name']]); - $row['enable']['#disabled'] = TRUE; + if (!empty($row['enable'])) { + $row['enable']['#disabled'] = TRUE; + } } else { $row['#required_by'][$dependent] = $this->t('@module (disabled)', ['@module' => $modules[$dependent]->info['name']]); diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 799869bbc3..2b78ac154a 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -117,7 +117,7 @@ function template_preprocess_system_admin_index(&$variables) { * 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. + * - enable: (optional) 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. @@ -135,17 +135,23 @@ function template_preprocess_system_modules_details(&$variables) { foreach (Element::children($form) as $key) { // Stick the key into $module for easier access. $module = $form[$key]; - unset($module['enable']['#title']); + if (!empty($module['enable'])) { + 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']; + if (!empty($module['enable'])) { + $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']; + if (!empty($module['enable'])) { + $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. diff --git a/core/modules/system/templates/system-modules-details.html.twig b/core/modules/system/templates/system-modules-details.html.twig index e431c8e722..3051b82dd7 100644 --- a/core/modules/system/templates/system-modules-details.html.twig +++ b/core/modules/system/templates/system-modules-details.html.twig @@ -36,11 +36,19 @@ {% for module in modules %} {% set zebra = cycle(['odd', 'even'], loop.index0) %} + {% if module.checkbox %} {{ module.checkbox }} + {% else %} + + {% endif %} + {% if module.checkbox %} + {% else %} + {{ module.name }} + {% endif %}
diff --git a/core/modules/system/templates/system-modules-details.html.twig b/core/themes/seven/templates/system-modules-details.html.twig similarity index 92% copy from core/modules/system/templates/system-modules-details.html.twig copy to core/themes/seven/templates/system-modules-details.html.twig index e431c8e722..d6d9b598ef 100644 --- a/core/modules/system/templates/system-modules-details.html.twig +++ b/core/themes/seven/templates/system-modules-details.html.twig @@ -36,11 +36,19 @@ {% for module in modules %} {% set zebra = cycle(['odd', 'even'], loop.index0) %} + {% if module.checkbox %} {{ module.checkbox }} + {% else %} + + {% endif %} + {% if module.checkbox %} + {% else %} + + {% endif %}