Verified Commit a9c9c3e5 authored by Dave Long's avatar Dave Long
Browse files

fix: #3612458 Show all dependent modules on module confirm form for each chosen module

By: quietone
By: akshay kashyap
By: nicxvan
parent 1ab223a5
Loading
Loading
Loading
Loading
Loading
+1 −0
Changes for core/modules/system/src/Form/ModulesListConfirmForm.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -146,6 +146,7 @@ protected function buildMessageList() {
      // Display a list of required modules that have to be installed as well
      // but were not manually selected.
      foreach ($this->modules['dependencies'] as $module => $dependencies) {
        asort($dependencies);
        $items[] = [
          [
            '#markup' => $this->formatPlural(
+6 −2
Changes for core/modules/system/src/Form/ModulesListForm.php: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -438,10 +438,14 @@ protected function buildModuleList(FormStateInterface $form_state) {
      }
    }

    // Add all dependencies to a list.
    // Add dependencies that need to be installed to the modules array. Only
    // modules that have not been requested will be added. That is, if a
    // dependent module has been selected on the form, it will not be listed
    // as needing to be installed.
    $original_install = $modules['install'];
    foreach ($modules['install'] as $module => $value) {
      foreach (array_keys($data[$module]->requires) as $dependency) {
        if (!isset($modules['install'][$dependency]) && !$this->moduleHandler->moduleExists($dependency)) {
        if (!isset($original_install[$dependency]) && !$this->moduleHandler->moduleExists($dependency)) {
          $dependency_info = $data[$dependency]->info;
          $modules['dependencies'][$module][$dependency] = $dependency_info['name'];
          $modules['install'][$dependency] = $dependency_info['name'];
+24 −1
Changes for core/modules/system/tests/src/Functional/Module/DependencyTest.php: 24 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -166,7 +166,30 @@ public function testModuleDependencyMessages(): void {
    $edit['modules[navigation][enable]'] = 'navigation';
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    $this->assertSession()->pageTextContains('You must install the following modules to install Navigation:BlockFileFieldLayout BuilderLayout DiscoveryContextual Links');
    $this->assertSession()->pageTextContains('You must install the following modules to install Navigation:BlockContextual LinksFieldFileLayout BuilderLayout Discovery');

    // Check the module install text with more than 2 module dependencies and
    // when the modules to be installed share a dependency.
    $edit = [];
    $edit['modules[block_content][enable]'] = 'block_content';
    $edit['modules[navigation][enable]'] = 'navigation';
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    $this->assertSession()->pageTextContains('You must install the following modules to install Block Content:BlockFieldFilterText');
    $this->assertSession()->pageTextContains('You must install the following modules to install Navigation:BlockContextual LinksFieldFileLayout BuilderLayout Discovery');

    // Same as above with a common dependent module, Block, also selected to be
    // installed. In this case, 'Block' should not be in the list of what must
    // be installed.
    $edit = [];
    $edit['modules[block][enable]'] = 'block';
    $edit['modules[block_content][enable]'] = 'block_content';
    $edit['modules[navigation][enable]'] = 'navigation';
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    $this->assertSession()->pageTextContains('You must install the following modules to install Block Content:FieldFilterText');
    $this->assertSession()->pageTextContains('You must install the following modules to install Navigation:Contextual LinksFieldFileLayout BuilderLayout Discovery');

  }

}