By design, Drupal allows multiple copies of a module in different directory spaces (eg one in /core/modules, one in /modules, one in sites/all/modules).

However, if duplicate copies exist in the same space, this works too, though I assume this is by accident rather than by design. So for example if I have:

- sites/all/modules/foo
- sites/all/modules/contrib/foo

then the first one is taken by Drupal, and the second one is simply ignored.

However, because this behaviour is undocumented, it effectively puts the codebase in an unstable state: a developer doesn't know which module is being used by Drupal without inspecting the system table.

Having two copies like this is therefore a code error, and it would be better if discovery of a second module with the same name within the same directory space caused an exception on module discovery.

In other words, ExtensionDiscovery::scanDirectory() should keep an array indexed by just the extension name to track uniqueness, and throw an exception if it finds a second copy of the same extension name. The exception message should clearly state which module is already registered, if any, to allow a developer to know which one to remove in the case that the two are different.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim created an issue. See original summary.

joachim’s picture

Status: Active » Needs work
FileSize
1.43 KB

Quick attempt at what I mean.

Not sure what class of exception to throw though.

Anishnirmal’s picture

Displayed a Warning message on finding duplicate modules. Hope this helps.

warning message

swentel’s picture

Hmm, I've sometimes used this behavior to override core modules in a different directory and not having to patch core itself. And I think it was handy to override a module specifically for a site having it in sites/sitename/modules. Whether it's a good thing is debatable of course, and I don't really mind removing it. Throwing an exception seems a little harsh though.

However, some kind of warning, or least telling the user, or simply core knowing there are duplicates might become interesting for including new modules in core, e.g. #2296423: Implement layout plugin type in core or #2469431: BigPipe for auth users: first send+render the cheap parts of the page, then the expensive parts during minor releases and having at least an easy mechanism to find two modules.

(also, in the latest patch, we can't put drupal_set_message there, discovery shouldn't throw it there.

joachim’s picture

Thanks for looking at this!

However, I'm not sure it's suitable for this component to use drupal_set_message(), as it should be usable as an API, and not necessarily from the Drupal UI.

Also, if we merely set a message here, then we've gone ahead and enabled one of the duplicate modules, and the user doesn't know which. This puts the site in an unclear state, and I don't think that should be allowed.

> Hmm, I've sometimes used this behavior to override core modules in a different directory and not having to patch core itself.

I assume you mean something like having sites/all/modules/node to override core/modules/node?

That's legitimate, and wouldn't be affected here. This issue is about duplicates in the same space, eg both in sites/all/modules, or both in /modules, or both in the same profile.

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

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

SKAUGHT’s picture

If this is not documented behaviour or is lost documentation, @poor_document_discovery_on_d.org, it is (dare i say) 'common knowledge'. historically, same with module weight. Which i also assume still exists in 8.

Is it not still the case that the higher version number of the module will 'win out'? i've not tested this in D8, i would expect this to be true still.
ie: https://www.drupal.org/project/contact <-- sometimes we just want to completely override a core module

#4 -- yes, multisite/profile projects allow for updates to modules by a /sites/[domain]/modules installations.

Of course, due to possible hook_update()'s done by higher modules; downgrading probably shouldn't/can't be done.

  • It might general be better if durpal had a report page (ie: admin/modules/status OR admin/config/system/module-status) that reported the known module version and last hook_update_N that was run.
  • Even current active install path of each module on the /admin/modules list.

if this issue was to be continued you should be able to use drupal_set_message(). however, as that same person installing may install 'a bunch of things' at once. The notice may be better off with each module, and just a general message at the top of the page. @UX

I would have to say.. In a 'one off' site, if a dev has messed up:
- sites/all/modules/foo
- sites/all/modules/contrib/foo
Certainly they have created their own issue. it was a sloppy installation by that dev (or said person who shouldn't have been installing anything..)

joachim’s picture

> Hmm, I've sometimes used this behavior to override core modules in a different directory and not having to patch core itself. And I think it was handy to override a module specifically for a site having it in sites/sitename/modules.

This issue isn't proposing to remove that behaviour.

Just to make it illegal to have modules with the same name in the *same* area.

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

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now 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.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.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.

Pasqualle’s picture

This should definitely be an exception, not a warning.

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.