#2080823: Create API to discover config entities' soft dependencies and use this to present a confirm form on module uninstall added a method getDependentEntities() to \Drupal\Core\Config\Entity\ConfigDependencyManager. The documentation for this method simply says that it "gets dependencies". The implication is that it returns the list of forward dependencies for a given configuration entity. For instance, if I pass it a field instance config, I would expect it to return just the storage config as a dependency. If I pass the field storage config, I would expect it to usually return nothing.

However, the actual behavior seems to be to return the entire dependency tree, including reverse dependencies. In other words, if I pass it a field storage config, I get the field instance config and everything that depends on that config (for instance, views) all the way back up the dependency tree. This is because the method in turn calls createGraphConfigEntityDependencies(), which returns the reverse paths for the dependency graph.

This is problematic because Features relies on this method to return the dependencies for a given config (#2533844: Use ConfigDependencyManager for determining config dependency), but since it's actually returning dependencies and dependent configs, dependencies are erroneously included, causing #2720167: Config dependency detection logic.

At the least, the documentation for this method needs to be updated to clarify the intended behavior. If the method is behaving as intended, then Features is probably using it incorrectly and needs to find a new method of building dependencies trees. If the method is not behaving as intended, then it needs to be patched.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dane Powell created an issue. See original summary.

Dane Powell’s picture

Issue summary: View changes
Dane Powell’s picture

Issue summary: View changes
Wim Leers’s picture

Wim Leers’s picture

Title: Poorly defined behavior for getDependentEntities » ConfigDependencyManager::getDependentEntities() is poorly documented
Issue tags: +DX (Developer Experience), +Documentation, +Contributed project soft blocker
  /**
   * Gets dependencies.
   *
   * @param string $type
   *   The type of dependency
   * @param string $name
   *  …
   *
   * @return \Drupal\Core\Config\Entity\ConfigEntityDependency[]
   *   An array of config entity dependency objects that are dependent.
   */
  public function getDependentEntities($type, $name) {

We see:

  1. dependencies
  2. dependency
  3. dependency objects that are dependent
  4. dependent entities

This is indeed very confusing at best.

Furthermore:

  1. the CR at https://www.drupal.org/node/2220437 doesn't cover this at all.
  2. the extensive documentation on \Drupal\Core\Config\Entity\ConfigDependencyManager does not even mention this public API method
Salif’s picture

Assigned: Unassigned » Salif
Issue tags: +DrupalNorth2016

I'm working on this in Drupal North code sprint

Salif’s picture

Assigned: Salif » Unassigned
Status: Active » Needs review
FileSize
2.29 KB

Thank you to check my first patch

Dane Powell’s picture

Status: Needs review » Reviewed & tested by the community

This patch satisfies my curiosity. I'm not entirely familiar with the intended behavior of the function, but it seems to describe the actual behavior well enough.

Wim Leers’s picture

Assigned: Unassigned » alexpott

Assigning to @alexpott since he's both a committer and maintainer of this subsystem, so he's best able to review this.

(There are whitespace problems in this patch, but that's less important for now — what matters most is whether the content is accurate.)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
    @@ -136,18 +136,30 @@ class ConfigDependencyManager {
    +   * Given a configuration name and type, returns a graph of its dependencies.
    

    It doesn't return the graph anymore. It returns a list of ConfigEntityDependency objects in the order of the nearest to the thing you passed in. So if you pass in Node module you get node_type -> field_storage -> field -> entity view displays.

  2. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
    @@ -136,18 +136,30 @@ class ConfigDependencyManager {
    +   * If the given entity is a configuration entity, this function simply calls
    +   * $this->createGraphConfigEntityDependencies() on it.
    +   * ¶
    +   * If given entity is a module, theme or content entity, this function looks
    +   * through this configDependencyManager's configuration entities and calls
    +   * $this->createGraphConfigEntityDependencies() on each of them.
    +   * ¶
    +   * If the given entity isn't a configuration, module, theme or content entity
    +   * then this function returns just an empty array.
    

    This is too much about implementation and not what is being calculated. See the issue summary of #2754477: Unexpected config entity delete due to dependency calculations which has some pictures that explain what is going on here.

  3. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
    @@ -136,18 +136,30 @@ class ConfigDependencyManager {
    +   * ¶
    ...
    +   * ¶
    

    Lines have spaces.

  4. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
    @@ -136,18 +136,30 @@ class ConfigDependencyManager {
    +   *   The specific configuration name to check. If $type equals 'module' or
    +   *   'theme' then it should be a module name or theme name. Otherwise it
    +   *   should be the full configuration object name.
    

    We should probably add an @see to \Drupal\Core\Entity\EntityInterface::getConfigDependencyName()

  5. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
    @@ -136,18 +136,30 @@ class ConfigDependencyManager {
    +   *   An array of forward and reverse config entity dependency objects in a
    +   *   graph.
    

    I'm not sure this is better.

Salif’s picture

Assigned: alexpott » Salif
Category: Bug report » Task
Status: Needs work » Active

As per @Alexpott review in comment #10
An Interdiff for patch 2724835-ConfigDependencyManager-documentation-7

Salif’s picture

Assigned: Salif » Unassigned
Category: Task » Bug report
Status: Active » Needs review
FileSize
2.33 KB
2.1 KB

Sorry about #11 without files.

As per @Alexpott review in comment #10
An Interdiff-2724835-ConfigDependencyManager-documentation-7-12

mparker17’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #12 seems to address all of @alexpott's comments; and contains no whitespace errors. +1 to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
    @@ -136,18 +136,29 @@ class ConfigDependencyManager {
    +   * return [node_type, field_storage, field, entity view displays, ...].
    

    I'm not sure about this formatting. Also, if we use an ellipsis we should use the proper unicode character.

  2. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
    @@ -136,18 +136,29 @@ class ConfigDependencyManager {
    -   *   or 'content'.
    +   *   or 'content'; anything else will return an empty array.
    

    I don't think this change is necessary. We could add documentation to the return to say if nothing is dependent it'll be empty.

deepakaryan1988’s picture

Assigned: Unassigned » deepakaryan1988
deepakaryan1988’s picture

Assigned: deepakaryan1988 » Unassigned
Status: Needs work » Needs review
FileSize
2.06 KB
1.58 KB

Address the points in #14

Mile23’s picture

Status: Needs review » Needs work

Way more helpful than the current docs. :-)

Patch applies to 8.1.x, 8.2.x, 8.3.x.

+++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
@@ -136,18 +136,30 @@ class ConfigDependencyManager {
+   *   If nothing is dependent it'll be empty.

'Returns an empty array If there are no ancestors.'

mparker17’s picture

Status: Needs review » Needs work

The last submitted patch, 18: ConfigDependencyManager-documentation-2724835-18.patch, failed testing.

Mile23’s picture

Status: Needs work » Reviewed & tested by the community

Pretty sure the 8.1.x fail is unrelated, since this is a documentation change.

Looks good, thanks.

xjm’s picture

Title: ConfigDependencyManager::getDependentEntities() is poorly documented » Improve ConfigDependencyManager::getDependentEntities() documentation
Version: 8.3.x-dev » 8.1.x-dev
Category: Bug report » Task
Status: Reviewed & tested by the community » Needs work
Issue tags: +rc eligible
  1. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
    @@ -136,18 +136,30 @@ class ConfigDependencyManager {
    +   * ConfigEntityDependency objects in the order of the nearest to the entity
    +   * passed in. For example, if passed ('module', 'node'), this function will
    +   * return [node_type, field_storage, field, entity view displays].
    

    Isn't this hardcoding documentation of something that can change? I think we need to add a bit more context, or a simpler, made-up example.

  2. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
    @@ -136,18 +136,30 @@ class ConfigDependencyManager {
        * @param string $type
    -   *   The type of dependency being checked. Either 'module', 'theme', 'config'
    -   *   or 'content'.
    +   *   The type of dependency being checked. Either 'module', 'theme', 'config'.
    

    AFAIK we still have content dependencies, so why is that word being removed?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ashishdalvi’s picture

Issue tags: +DrupalMumbaiCodeSprint

Marking issue for Drupal Mumbai Code Sprint

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

benjifisher’s picture

Version: 8.9.x-dev » 9.2.x-dev
Assigned: Unassigned » benjifisher
Issue tags: -rc eligible, -DrupalMumbaiCodeSprint
FileSize
760 bytes
2.17 KB

Here is a reroll of the patch in #18. As the diff (not interdiff) shows, the only difference is a line of context. The patch in #18 was made before we switched to short array syntax.

I am removing the "rc eleigible" issue tag. I think it is out of date. I am also removing DrupalMumbaiCodeSprint, since it looks as though this issue was not touched at that event.

benjifisher’s picture

FileSize
651 bytes
2.08 KB

Oops, I forgot to revert the change I made in order to apply the patch from #18. Ignore the patch, diff attached to #30: new ones attached now.

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.