diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index d702b26..9d0f81d 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\Core\Config\Entity\ConfigDependencyManager; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Site\Settings; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -71,8 +72,6 @@ class ConfigInstaller implements ConfigInstallerInterface { */ protected $isSyncing = FALSE; - protected $isInstalling = FALSE; - /** * Constructs the configuration installer. * @@ -102,7 +101,6 @@ public function __construct(ConfigFactoryInterface $config_factory, StorageInter * {@inheritdoc} */ public function installDefaultConfig($type, $name) { - $this->isInstalling = TRUE; $extension_path = drupal_get_path($type, $name); // Refresh the schema cache if the extension provides configuration schema // or is a theme. @@ -119,9 +117,9 @@ public function installDefaultConfig($type, $name) { } else { // The configuration importer sets the source storage on the config - // installer. The configuration importer handles all of the configuration - // entity imports. We only need to ensure that simple configuration is - // created when the extension is installed. + // installer. The configuration importer handles all of the + // configuration entity imports. We only need to ensure that simple + // configuration is created when the extension is installed. $prefix = $name; } @@ -145,15 +143,17 @@ public function installDefaultConfig($type, $name) { // Install any optional configuration entities whose type this extension // provides. This searches all the installed modules config/optional // directories. - // @todo consider optimising this by checking if the extension provides - // any configuration entities. - $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE); - $this->setSourceStorage($storage); - $this->installOptionalConfig($name); + $provides_config_entity_type = array_reduce($this->configManager->getEntityManager()->getDefinitions(), function ($return, EntityTypeInterface $entity_type) use ($name) { + return $return ?: $entity_type->getProvider() && $entity_type->getConfigPrefix(); + }, FALSE); + if ($provides_config_entity_type) { + $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE); + $this->setSourceStorage($storage); + $this->installOptionalConfig($name); + } } // Reset all the static caches and list caches. - $this->isInstalling = FALSE; $this->configFactory->reset(); $this->resetSourceStorage(); } @@ -308,26 +308,18 @@ protected function createConfiguration($collection, array $data) { * {@inheritdoc} */ public function installCollectionDefaultConfig($collection) { - // We're in the middle of a config install any collections will be picked up - // later? - // @todo is this really correct. - if ($this->isInstalling) { - return; - } - $this->setSourceStorage(new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_INSTALL_DIRECTORY, $collection, drupal_installation_attempted())); - $config_to_install = $this->getSourceStorage($collection)->listAll(); - // @todo is this right? + $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_INSTALL_DIRECTORY, $collection, drupal_installation_attempted()); + // Only install configuration for enabled extensions. $enabled_extensions = $this->getEnabledExtensions(); - $config_to_install = array_filter($config_to_install, function ($config_name) use ($enabled_extensions) { + $config_to_install = array_filter($storage->listAll(), function ($config_name) use ($enabled_extensions) { $provider = Unicode::substr($config_name, 0, strpos($config_name, '.')); return in_array($provider, $enabled_extensions); }); if (!empty($config_to_install)) { - $this->createConfiguration($collection, $this->getSourceStorage($collection)->readMultiple($config_to_install)); + $this->createConfiguration($collection, $storage->readMultiple($config_to_install)); // Reset all the static caches and list caches. $this->configFactory->reset(); } - $this->resetSourceStorage(); } /**