Problem/Motivation

Module list form does some dependency calculations to ascertain whether to disable the checkbox for enabling a module.

To pave the way for #3005229: Provide optional support for using composer.json for dependency metadata we should refactor it a bit.

Proposed resolution

At the moment we have a hunk with an if/elseif/elseif/elseif/else ie that's three elseifs.
Once we get to #3005229: Provide optional support for using composer.json for dependency metadata we'll need another for the different path between the composer and BC layer. One elseif is too many, and four is just plain ugmo.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3053832

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

larowlan created an issue. See original summary.

larowlan’s picture

Status: Active » Needs review
StatusFileSize
new13.59 KB
lendude’s picture

+++ b/core/lib/Drupal/Core/Extension/DependencyEvaluationResult.php
@@ -0,0 +1,120 @@
+  public function isHidden() {
+    return empty($this->description);
+  }

This seems a little magical, wouldn't it be clearer if it just had a $hidden setting?

Is the existing test coverage enough to not add any here? I'm assuming that we have plenty of coverage for the module page, but might be nice to check and confirm that we do.

Since this is an important page that tends to be fairly heavy to load, do we need a quick profiling run for this to make sure we are not regressing here (nothing in the code makes me think we might, but who knows)?

larowlan’s picture

#3
Fixed

Checked, we have tests in \Drupal\Tests\system\Functional\Module\DependencyTest

Profiling coming

larowlan’s picture

StatusFileSize
new13.74 KB
new1.02 KB
larowlan’s picture

Issue summary: View changes
StatusFileSize
new164.63 KB

Negligible difference when profiling, both HEAD and with this patch take 18s to load on my local (which has all the contrib modules I work on in it)

kim.pepper’s picture

Shuffle some deck-chairs so that its easier to insert a BC layer

I think we need a bit more info in the the issue summary. Why is this needed for #3005229: Provide optional support for using composer.json for dependency metadata? Can you expand on the changes a bit more? What are we doing to make a BC layer easier?

larowlan’s picture

Issue summary: View changes

Added

At the moment we have a hunk with an if/elseif/elseif/elseif/else ie that's three elseifs.
Once we get to #3005229: Provide optional support for using composer.json for dependency metadata we'll need another for the different path between the composer and BC layer. One elseif is too many, and four is just plain ugmo.

to issue summary

kim.pepper’s picture

Status: Needs review » Reviewed & tested by the community

I like the introduction of the value object, and the static methods make it's usage intuitive. Although we could add a unit test, it seems too trivial to me.

lendude’s picture

@larowlan thanks for doing the profiling/test check steps. RTBC++

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 5: 3053832-refactor-module-list-form-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kim.pepper’s picture

Status: Needs work » Reviewed & tested by the community

Random test fails.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

So much complexity.

The whole hidden thing is really really not nice. What's a hidden dependency?!?! The answer is one that doesn't count. And that's where I think this solution might do with a little finesse because it got very confusing trying to work out what

+++ b/core/lib/Drupal/Core/Extension/DependencyEvaluationResult.php
@@ -0,0 +1,128 @@
+  /**
+   * Factory method to build a result where the dependency is hidden.
+   *
+   * @param string $dependency
+   *   Dependency machine name.
+   *
+   * @return \Drupal\Core\Extension\DependencyEvaluationResult
+   *   Compatibility result.
+   */
+  public static function hidden($dependency) {
+    $instance = new static();
+    $instance->satisfied = FALSE;
+    $instance->dependency = $dependency;
+    $instance->hidden = TRUE;
+    return $instance;
+  }

The $instance->satisfied meant in this case.

It really means ignore so rather than creating a DependencyEvaluationResult how about returning FALSE. Meaning we've ignored the dependency. That way this whole hidden thing has no meaning outside this form - which it doesn't atm but this patch makes it suddenly have.

Also I always find it remarkable that some much logic about where something can be installed or uninstalled is buried in this form. Plus all the uninstall logic side of things is moot because that's not handled here any more.

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new3.44 KB
new12.96 KB

Also I always find it remarkable that some much logic about where something can be installed or uninstalled is buried in this form. Plus all the uninstall logic side of things is moot because that's not handled here any more.

Yep, this is a step towards untangling it. It is indeed frightening.

Made that change for hidden

kim.pepper’s picture

Status: Needs review » Reviewed & tested by the community

Feedback from #13 has been addressed to back to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. --- /dev/null
    +++ b/core/lib/Drupal/Core/Extension/DependencyEvaluationResult.php
    

    So the only thing I'm pondering now is the location of this class. It's not a really a generic class at all. Like Drush or Console couldn't use it to improve or re-use their dependency messages whilst enabling a module. The logic they'd need is still all in the form. For me this class really boils down to a nice way to return a multiple values (the message and whether or not the dependency is satisfied) from the new buildDependencyEvaluationResult method. So for me this thing probably ought to be in the same location or very near that form.

  2. +++ b/core/modules/system/src/Form/ModulesListForm.php
    @@ -350,16 +342,59 @@ protected function buildRow(array $modules, Extension $module, $distribution) {
    +  protected function buildDependencyEvaluationResult(array $modules, Dependency $dependency_object) {
    

    I think the arguments should be the other ways around. We're evaluating the dependency so it makes sense that it is the first argument.

mxr576’s picture

I am adding #3060241 as a related issue because both the ModuleListForm and the ModuleInstaller should use the same component to resolve and validate dependencies, when a dependency validation fails they should both handle it properly.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nicxvan’s picture

Component: base system » extension system

meeni_dhobale made their first commit to this issue’s fork.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.