Unverified Commit 7c9a05d8 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3270378 by andregp, murilohp, Rinku Jacob 13, AaronMcHale, dww,...

Issue #3270378 by andregp, murilohp, Rinku Jacob 13, AaronMcHale, dww, alexpott, smustgrave: Promote non-stable modules to the top of the list at admin/modules/uninstall form

(cherry picked from commit 642c614b)
(cherry picked from commit 157ebea1)
parent 6e276ee2
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -146,8 +146,22 @@ public function buildForm(array $form, FormStateInterface $form_state) {
      return $form;
    }

    // Sort all modules by their name.
    uasort($uninstallable, [ModuleExtensionList::class, 'sortByName']);
    // Deprecated and obsolete modules should appear at the top of the
    // uninstallation list.
    $unstable_lifecycle = array_flip([
      ExtensionLifecycle::DEPRECATED,
      ExtensionLifecycle::OBSOLETE,
    ]);

    // Sort all modules by their lifecycle identifier and name.
    uasort($uninstallable, function ($a, $b) use ($unstable_lifecycle) {
      $lifecycle_a = isset($unstable_lifecycle[$a->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER]]) ? -1 : 1;
      $lifecycle_b = isset($unstable_lifecycle[$b->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER]]) ? -1 : 1;
      if ($lifecycle_a === $lifecycle_b) {
        return ModuleExtensionList::sortByName($a, $b);
      }
      return $lifecycle_a <=> $lifecycle_b;
    });
    $validation_reasons = $this->moduleInstaller->validateUninstall(array_keys($uninstallable));

    $form['uninstall'] = ['#tree' => TRUE];
+14 −0
Original line number Diff line number Diff line
@@ -82,6 +82,20 @@ public function testUninstallPage() {
    $this->assertSession()->elementExists('xpath', "//a[contains(@aria-label, 'View information on the Obsolete status of the module System obsolete status test')]");
    $this->assertSession()->elementExists('xpath', "//a[contains(@href, 'https://example.com/obsolete')]");

    $form = $this->assertSession()->elementExists('xpath', "//form[@id='system-modules-uninstall']");
    $form_html = $form->getOuterHtml();

    // Select the first stable module on the uninstall list.
    $module_stable = $this->assertSession()->elementExists('xpath', "//label[contains(@class, 'module-name') and not(./a[contains(@class, 'module-link--non-stable')])]")->getOuterHtml();

    // Select the unstable modules (deprecated, and obsolete).
    $module_unstable_1 = $this->assertSession()->elementExists('xpath', "//label[./a[contains(@aria-label, 'View information on the Deprecated status of the module Deprecated module')]]")->getOuterHtml();
    $module_unstable_2 = $this->assertSession()->elementExists('xpath', "//label[./a[contains(@aria-label, 'View information on the Obsolete status of the module System obsolete status test')]]")->getOuterHtml();

    // Check that all unstable modules appear before the first stable module.
    $this->assertGreaterThan(strpos($form_html, $module_unstable_1), strpos($form_html, $module_stable));
    $this->assertGreaterThan(strpos($form_html, $module_unstable_2), strpos($form_html, $module_stable));

    foreach (\Drupal::service('extension.list.module')->getAllInstalledInfo() as $module => $info) {
      $field_name = "uninstall[$module]";
      if (!empty($info['required'])) {