Verified Commit 72e7c019 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #371375 by Ammaletu, vasike, danflanagan8, KapilV, matt2000, Ryan...

Issue #371375 by Ammaletu, vasike, danflanagan8, KapilV, matt2000, Ryan Palmer, ZeiP, Andrew Answer, Madhu kumar, webchick, Berdir, kwinters, smustgrave, chx, cburschka, Jaza, moshe weitzman, zroger, zoo33, joachim, alexpott, ressa, dasj19, jlscott, quietone, blainelang, wturrell, tanc, MartysMind: Do not allow a module and theme to use the same name
parent 51b7955f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Extension;

/**
 * Exception thrown when the extension's name is already reserved.
 */
class ExtensionNameReservedException extends \Exception {}
+6 −0
Original line number Diff line number Diff line
@@ -190,6 +190,12 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
          throw new ExtensionNameLengthException("Module name '$module' is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters');
        }

        // Throw an exception if a theme with the same name is enabled.
        $installed_themes = $extension_config->get('theme') ?: [];
        if (isset($installed_themes[$module])) {
          throw new ExtensionNameReservedException("Module name $module is already in use by an installed theme.");
        }

        // Load a new config object for each iteration, otherwise changes made
        // in hook_install() are not reflected in $extension_config.
        $extension_config = \Drupal::configFactory()->getEditable('core.extension');
+3 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ interface ModuleInstallerInterface {
   *   Thrown when the extension's name is longer than
   *   DRUPAL_EXTENSION_NAME_MAX_LENGTH.
   *
   * @throws \Drupal\Core\Extension\ExtensionNameReservedException
   *   Thrown when a module's name is already used by an installed theme.
   *
   * @see hook_module_preinstall()
   * @see hook_install()
   * @see hook_modules_installed()
+6 −0
Original line number Diff line number Diff line
@@ -213,6 +213,12 @@ public function install(array $theme_list, $install_dependencies = TRUE) {
        throw new ExtensionNameLengthException("Theme name $key is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters.');
      }

      // Throw an exception if a module with the same name is enabled.
      $installed_modules = $extension_config->get('module') ?: [];
      if (isset($installed_modules[$key])) {
        throw new ExtensionNameReservedException("Theme name $key is already in use by an installed module.");
      }

      // Validate default configuration of the theme. If there is existing
      // configuration then stop installing.
      $this->configInstaller->checkConfigurationToInstall('theme', $key);
+5 −1
Original line number Diff line number Diff line
@@ -21,7 +21,11 @@ interface ThemeInstallerInterface {
   *   Whether any of the given themes have been installed.
   *
   * @throws \Drupal\Core\Extension\ExtensionNameLengthException
   *   Thrown when the theme name is to long.
   *   Thrown when a theme's name is longer than
   *   DRUPAL_EXTENSION_NAME_MAX_LENGTH.
   *
   * @throws \Drupal\Core\Extension\ExtensionNameReservedException
   *   Thrown when a theme's name is already used by an installed module.
   *
   * @throws \Drupal\Core\Extension\Exception\UnknownExtensionException
   *   Thrown when the theme does not exist.
Loading