Problem/Motivation

Having modules and themes with duplicate names enabled is not supported and should not be allowed in the first place.

Form LibraryDiscoveryParser::buildByExtension()

      if ($this->moduleHandler->moduleExists($extension)) {
        $extension_type = 'module';
      }
      else {
        $extension_type = 'theme';
      }

Above code always parse $modulename.libraries.yml if module and theme has same name. This also occurs if install profile has same name as theme name.

Proposed resolution

Throw an exception if this is attempted.

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Comments

lauriii’s picture

That is definitely related to this. Should we even mark it as a duplicate for this?

berdir’s picture

Having a module and a theme with the same name is not supported and will result in a completely broken site.

http://drupal.stackexchange.com/questions/152809/install-a-custom-empty-...

Instead of trying to do something about that here, we should just check for that and prevent that from happening in the first place.

dawehner’s picture

Right, both the theme installer and the module installer could check whether there is some other extensions with the same name available and throw an exception or something else, in case that happens.

jibran’s picture

+1 for #3

berdir’s picture

Title: LibraryDiscoveryParser::buildByExtension always pick module library if theme and module has a same name. » Prevent that a theme and module can have the same name

Yes, lets change it to that then.

cilefen’s picture

Title: Prevent that a theme and module can have the same name » Prevent identical names across extension types (profiles, themes, and modules)
cilefen’s picture

Status: Active » Needs review
StatusFileSize
new2.79 KB
cilefen’s picture

Title: Prevent identical names across extension types (profiles, themes, and modules) » Extension installers allow extensions with duplicate names to be enabled
cilefen’s picture

Issue summary: View changes
cilefen’s picture

StatusFileSize
new1.91 KB
new4.7 KB

I added a test on the ThemeInstaller. We will need a test of the module installer.

Status: Needs review » Needs work

The last submitted patch, 10: extension_installers-2472119-10.patch, failed testing.

joshi.rohit100’s picture

  1. +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
    @@ -81,6 +81,13 @@ public function addUninstallValidator(ModuleUninstallValidatorInterface $uninsta
    +    $installed_themes = $extension_config->get('theme') ?: array();
    +    $duplicates = array_intersect(array_keys($installed_themes), $module_list);
    +    if ($duplicates) {
    +      throw new ExtensionDuplicateNameException($duplicates);
    

    And

  2. +++ b/core/lib/Drupal/Core/Extension/ThemeInstaller.php
    @@ -104,6 +104,11 @@ public function __construct(ThemeHandlerInterface $theme_handler, ConfigFactoryI
    +    $installed_modules = $extension_config->get('module') ?: array();
    +    $duplicates = array_intersect(array_keys($installed_modules), $theme_list);
    +    if ($duplicates) {
    +      throw new ExtensionDuplicateNameException($duplicates);
    +    }
    

    ---

  3. Doesn't it look like we are duplicating samething (I know that its one for theme and another for module) ?

cilefen’s picture

We may want to implement a trait or something.

jibran’s picture

I don't think it's worth it as long as we have tests to cover both the cases.

heddn’s picture

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

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

stefan.r’s picture

Status: Needs work » Needs review

Tests seem to fatal on testClassLoading, re-triggering testbot.

Status: Needs review » Needs work

The last submitted patch, 10: extension_installers-2472119-10.patch, failed testing.

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.

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.

andypost’s picture

Version: 8.6.x-dev » 8.8.x-dev
andypost’s picture

Issue tags: +Needs reroll

needs reroll & fix

+++ b/core/modules/system/src/Tests/Extension/ThemeInstallerTest.php
@@ -141,6 +142,22 @@ function testInstallNameTooLong() {
+  function testInstallDuplicateName() {
...
+    try {
...
+      $this->themeInstaller()->install(array($name));
+      $this->fail($message);
+    }
+    catch (ExtensionDuplicateNameException $e) {
+      $this->pass(get_class($e) . ': ' . $e->getMessage());

Better to use @expectedException

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.

Adev22’s picture

Status: Needs work » Needs review
StatusFileSize
new5.15 KB

Rerolled and fix the patch #26 but without test

mparker17’s picture

@adev apparently the patch in #28 is failing with the error core/modules/system/src/Tests/Extension/ThemeInstallerTest.php: No such file or directory... it's possible that test was moved between 8.8.x and 8.9.x. git log --follow -- 'core/modules/system/src/Tests/Extension/ThemeInstallerTest.php' might help track down what happened to it.

Your patch also includes several older patch files from this issue, which aren't necessary to include. If you're interested, I wrote my best practices for generating patches and interdiffs a few years back: I apologize in advance for its verbosity, but I still refer to it when writing patches myself.

lulzsec’s picture

StatusFileSize
new1.34 KB

Trying to fix #28

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.

hardik_patel_12’s picture

StatusFileSize
new1.1 KB
new311 bytes

Re-roll for 9.1.x-dev

jofitz’s picture

Issue tags: -Needs reroll
StatusFileSize
new4.97 KB

Returned to #10 to re-roll for D9.1.x

Returning to Needs Work to address comments in #26.

jofitz’s picture

Status: Needs review » Needs work

Returning to Needs Work to address comments in #26.

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new2.98 KB
new4.69 KB

* Address comments in #26.
* Fixed coding standards violations highlighted in #33.

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.

danflanagan8’s picture

The current work on this issue is very much a duplicate of the work on #371375: Do not allow a module and theme to use the same name.. I'm new to both of these issues so I don't feel comfortable closing either of them.

I prefer the exception message on the other issue and I prefer the tests on the other issue.

Another difference in the patches is the location of the code block that checks for duplicates. In this issue the code block is near the beginning of the install function. In the other issue the code block is closer to the end of the install function. Not sure if that matters to anyone.

Neither issue appears to deal with profiles at this point.

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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new2.77 KB

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Akhil Yadav’s picture

StatusFileSize
new3.3 KB

Added patch against #35 in 10.1 version

bhanu951’s picture

Setting as need review for tests to run.

@Akhil Yadav Once you have uploaded the re-rolled patch, change the status to Need Review so the test-bot runs tests against the patch.

bhanu951’s picture

Missing core/lib/Drupal/Core/Extension/ExtensionDuplicateNameException.php

in the patch #43 present in #35 . Hiding patch #43.

sahil.goyal’s picture

#35 still applies to 10.1.x

acbramley’s picture

Status: Needs work » Closed (duplicate)
Issue tags: +Bug Smash Initiative

Closing this as a duplicate of #371375: Do not allow a module and theme to use the same name. there is a (at least at one point) green patch there with test coverage for both cases (module and theme)

I also can't see any code in this issues patch regarding profiles so maybe another issue should be opened just for that.

Triaged as part of Bug smash