diff --git a/core/core.services.yml b/core/core.services.yml index 07f17b9..10389d2 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -73,7 +73,7 @@ services: factory_method: getActive config.manager: class: Drupal\Core\Config\ConfigManager - arguments: ['@entity.manager', '@config.factory', '@config.typed', '@string_translation', '@config.storage'] + arguments: ['@entity.manager', '@config.factory', '@config.typed', '@string_translation', '@config.storage', '@module_handler', '@theme_handler'] config.storage: class: Drupal\Core\Config\CachedStorage arguments: ['@config.cachedstorage.storage', '@cache.config'] diff --git a/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php index 36238e8..75787ad 100644 --- a/core/lib/Drupal/Core/Config/ConfigManager.php +++ b/core/lib/Drupal/Core/Config/ConfigManager.php @@ -11,6 +11,8 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\StringTranslation\TranslationManager; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Extension\ThemeHandlerInterface; use Symfony\Component\Yaml\Dumper; /** @@ -54,6 +56,20 @@ class ConfigManager implements ConfigManagerInterface { protected $activeStorage; /** + * The module handler service. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** + * The theme handler service. + * + * @var \Drupal\Core\Extension\ThemeHandlerInterface + */ + protected $themeHandler; + + /** * Creates ConfigManager objects. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -65,12 +81,14 @@ class ConfigManager implements ConfigManagerInterface { * @param \Drupal\Core\StringTranslation\TranslationManager $string_translation * The string translation service. */ - public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, TypedConfigManager $typed_config_manager, TranslationManager $string_translation, StorageInterface $active_storage) { + public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, TypedConfigManager $typed_config_manager, TranslationManager $string_translation, StorageInterface $active_storage, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { $this->entityManager = $entity_manager; $this->configFactory = $config_factory; $this->typedConfigManager = $typed_config_manager; $this->stringTranslation = $string_translation; $this->activeStorage = $active_storage; + $this->moduleHandler = $module_handler; + $this->themeHandler = $theme_handler; } /** @@ -209,30 +227,17 @@ public function findConfigEntityDependentsAsEntities($type, array $names) { * {@inheritdoc} */ public function validateConfigEntityDependentsExistence(array $dependencies) { + $dependencies += array( + 'module' => array(), + 'theme' => array(), + 'entity' => array(), + ); // Run through all dependency types and check their existence. Fail as soon // as possible. - foreach ($dependencies as $type => $names) { - switch ($type) { - case 'module': - if (!$this->validateConfigEntityDependentModulesExistence($names)) { - return FALSE; - } - break; - case 'theme': - if (!$this->validateConfigEntityDependentThemesExistence($names)) { - return FALSE; - } - break; - case 'entity': - if (!$this->validateConfigEntityDependentEntitiesExistence($names)) { - return FALSE; - } - break; - } - } - - return TRUE; + return $this->validateConfigEntityDependentModulesExistence($dependencies['module']) && + $this->validateConfigEntityDependentThemesExistence($dependencies['theme']) && + $this->validateConfigEntityDependentEntitiesExistence($dependencies['entity']); } /** @@ -245,7 +250,7 @@ public function validateConfigEntityDependentsExistence(array $dependencies) { */ protected function validateConfigEntityDependentModulesExistence(array $names) { foreach ($names as $module_name) { - if (!\Drupal::moduleHandler()->moduleExists($module_name)) { + if (!$this->moduleHandler->moduleExists($module_name)) { return FALSE; } } @@ -262,7 +267,7 @@ protected function validateConfigEntityDependentModulesExistence(array $names) { * Whether or not all modules and themes are enabled. */ protected function validateConfigEntityDependentThemesExistence(array $names) { - $themes = \Drupal::service('theme_handler')->listInfo(); + $themes = $this->themeHandler->listInfo(); foreach ($names as $theme_name) { if (!isset($themes[$theme_name])) { return FALSE;