reverted: --- b/core/lib/Drupal/Core/Config/ConfigCollectionInfoEvent.php +++ /dev/null @@ -1,82 +0,0 @@ - 0) { - $collections_to_add = array_combine($collections, array_fill(0, count($collections), $override_service)); - $this->collections = array_merge($this->collections, $collections_to_add); - } - } - - /** - * Adds a collection to the list of possible collections. - * - * @param string $collection - * Collection name to add. - * @param \Drupal\Core\Config\ConfigFactoryOverrideInterface - * (optional) The configuration factory override service responsible for the - * collection. - */ - public function addCollection($collection, ConfigFactoryOverrideInterface $override_service = NULL) { - $this->addCollections(array($collection), $override_service); - } - - /** - * Gets the list of possible collection names. - * - * @return array - * The list of possible collection names. - */ - public function getCollectionNames($include_default = TRUE) { - $collection_names = array_keys($this->collections); - sort($collection_names); - if ($include_default) { - array_unshift($collection_names, StorageInterface::DEFAULT_COLLECTION); - } - return $collection_names; - } - - /** - * Gets the config factory override service responsible for the collection. - * - * @param string $collection - * The configuration collection. - * - * @return \Drupal\Core\Config\ConfigFactoryOverrideInterface|NULL - * The override service responsible for the collection if one exists. NULL - * if not. - */ - public function getOverrideService($collection) { - return isset($this->collections[$collection]) ? $this->collections[$collection] : NULL; - } - -} diff -u b/core/lib/Drupal/Core/Config/ConfigEvents.php b/core/lib/Drupal/Core/Config/ConfigEvents.php --- b/core/lib/Drupal/Core/Config/ConfigEvents.php +++ b/core/lib/Drupal/Core/Config/ConfigEvents.php @@ -51,9 +51,10 @@ const IMPORT = 'config.importer.import'; /** - * Name of event fired to discover all the possible configuration collections. + * Name of event fired to collect information on all collections. * - * @see \Drupal\Core\Config\ConfigInstaller::installDefaultConfig() + * @see \Drupal\Core\Config\ConfigManager::getConfigCollectionInfo() + * @see \Drupal\Core\Config\ConfigCollectionInfo */ const COLLECTION_INFO = 'config.collection_info'; diff -u b/core/lib/Drupal/Core/Config/ConfigFactoryOverrideInterface.php b/core/lib/Drupal/Core/Config/ConfigFactoryOverrideInterface.php --- b/core/lib/Drupal/Core/Config/ConfigFactoryOverrideInterface.php +++ b/core/lib/Drupal/Core/Config/ConfigFactoryOverrideInterface.php @@ -44,5 +44,5 @@ * The configuration object for the provided name and collection. */ - public function getConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION); + public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION); } diff -u b/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php --- b/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -896,13 +896,7 @@ * The name of the configuration to process. */ protected function importConfig($collection, $op, $name) { - $overrider = $this->configManager->getConfigCollectionInfo()->getOverrideService($collection); - if ($overrider) { - $config = $overrider->getConfigObject($name, $collection); - } - else { - $config = new Config($name, $this->storageComparer->getTargetStorage($collection), $this->eventDispatcher, $this->typedConfigManager); - } + $config = $this->configManager->createConfigObject($name, $collection); if ($op == 'delete') { $config->delete(); } diff -u b/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php --- b/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -111,7 +111,7 @@ foreach ($collection_info->getCollectionNames(TRUE) as $collection) { $config_to_install = $this->listDefaultConfigCollection($collection, $type, $name, $enabled_extensions); if (!empty($config_to_install)) { - $this->createConfiguration($collection, $config_to_install, $collection_info); + $this->createConfiguration($collection, $config_to_install); } } $this->configFactory->setOverrideState($old_state); @@ -167,10 +167,8 @@ * The configuration collection. * @param array $config_to_install * A list of configuration object names to create. - * @param \Drupal\Core\Config\ConfigCollectionInfoEvent $collection_info - * The configuration collection information. */ - protected function createConfiguration($collection, array $config_to_install, ConfigCollectionInfoEvent $collection_info) { + protected function createConfiguration($collection, array $config_to_install) { // Order the configuration to install in the order of dependencies. $data = $this->getSourceStorage($collection)->readMultiple($config_to_install); $config_entity_support = $this->configManager->supportsConfigurationEntities($collection); @@ -185,13 +183,7 @@ $config_to_install = array_diff($config_to_install, $this->getActiveStorage($collection)->listAll()); foreach ($config_to_install as $name) { - $overrider = $collection_info->getOverrideService($collection); - if ($overrider) { - $new_config = $overrider->getConfigObject($name, $collection); - } - else { - $new_config = new Config($name, $this->getActiveStorage($collection), $this->eventDispatcher, $this->typedConfig); - } + $new_config = $this->configManager->createConfigObject($name, $collection); if ($data[$name] !== FALSE) { $new_config->setData($data[$name]); } @@ -244,11 +236,9 @@ return in_array($provider, $enabled_extensions); }); if (!empty($config_to_install)) { - // Gather information about all the configuration collections. - $collection_info = $this->configManager->getConfigCollectionInfo(); $old_state = $this->configFactory->getOverrideState(); $this->configFactory->setOverrideState(FALSE); - $this->createConfiguration($collection, $config_to_install, $collection_info); + $this->createConfiguration($collection, $config_to_install); $this->configFactory->setOverrideState($old_state); // Reset all the static caches and list caches. $this->configFactory->reset(); diff -u b/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php --- b/core/lib/Drupal/Core/Config/ConfigManager.php +++ b/core/lib/Drupal/Core/Config/ConfigManager.php @@ -64,11 +64,18 @@ /** * The configuration collection info. * - * @var \Drupal\Core\Config\ConfigCollectionInfoEvent + * @var \Drupal\Core\Config\ConfigCollectionInfo */ protected $configCollectionInfo; /** + * The configuration storages keyed by collection name. + * + * @var \Drupal\Core\Config\StorageInterface[] + */ + protected $storages; + + /** * Creates ConfigManager objects. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -79,7 +86,10 @@ * The typed config manager. * @param \Drupal\Core\StringTranslation\TranslationManager $string_translation * The string translation service. - * * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher + * @param \Drupal\Core\Config\StorageInterface $active_storage + * The active configuration storage. + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher + * The event dispatcher. */ public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, TypedConfigManager $typed_config_manager, TranslationManager $string_translation, StorageInterface $active_storage, EventDispatcherInterface $event_dispatcher) { $this->entityManager = $entity_manager; @@ -271,8 +281,42 @@ if (!isset($this->configCollectionInfo)) { - $this->configCollectionInfo = new ConfigCollectionInfoEvent(); + $this->configCollectionInfo = new ConfigCollectionInfo(); $this->eventDispatcher->dispatch(ConfigEvents::COLLECTION_INFO, $this->configCollectionInfo); } return $this->configCollectionInfo; } + /** + * {$inheritdoc} + */ + public function createConfigObject($name, $collection) { + $overrider = $this->getConfigCollectionInfo()->getOverrideService($collection); + if ($overrider) { + $config = $overrider->createConfigObject($name, $collection); + } + else { + $config = new Config($name, $this->getStorageCollection($collection), $this->eventDispatcher, $this->typedConfigManager); + } + return $config; + } + + /** + * Gets the configuration storage that provides the active configuration. + * + * @param string $collection + * The configuration collection. + * + * @return \Drupal\Core\Config\StorageInterface + * The configuration storage for the provided collection. + */ + protected function getStorageCollection($collection) { + if (!isset($this->storages[$collection])) { + if ($this->activeStorage->getCollectionName() == $collection) { + $this->storages[$collection] = $this->activeStorage; + } + else { + $this->storages[$collection] = $this->activeStorage->createCollection($collection); + } + } + return $this->storages[$collection]; + } } diff -u b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php --- b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php +++ b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php @@ -126,9 +126,22 @@ /** - * Gets available collection information using the event. + * Gets available collection information using the event system. * - * @return \Drupal\Core\Config\ConfigCollectionInfoEvent - * The event which collects information about all the available collections. + * @return \Drupal\Core\Config\ConfigCollectionInfo + * The object which contains information about the available collections. */ public function getConfigCollectionInfo(); + /** + * Creates a StorableConfigBase object according to the needs of the collection. + * + * @param string $name + * The configuration object name. + * @param string $collection + * The configuration collection. + * + * @return \Drupal\Core\Config\StorableConfigBase + * The configuration object. + */ + public function createConfigObject($name, $collection); + } diff -u b/core/modules/config/tests/config_collection_install_test/lib/Drupal/config_collection_install_test/EventSubscriber.php b/core/modules/config/tests/config_collection_install_test/lib/Drupal/config_collection_install_test/EventSubscriber.php --- b/core/modules/config/tests/config_collection_install_test/lib/Drupal/config_collection_install_test/EventSubscriber.php +++ b/core/modules/config/tests/config_collection_install_test/lib/Drupal/config_collection_install_test/EventSubscriber.php @@ -7,7 +7,7 @@ namespace Drupal\config_collection_install_test; -use Drupal\Core\Config\ConfigCollectionInfoEvent; +use Drupal\Core\Config\ConfigCollectionInfo; use Drupal\Core\Config\ConfigEvents; use Drupal\Core\State\StateInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -34,11 +34,14 @@ /** * Reacts to the ConfigEvents::COLLECTION_NAMES event. * - * @param \Drupal\Core\Config\ConfigCollectionInfoEvent $event + * @param \Drupal\Core\Config\ConfigCollectionInfo $collection_info * The configuration collection names event. */ - public function addCollections(ConfigCollectionInfoEvent $event) { - $event->addCollections($this->state->get('config_collection_install_test.collection_names', array())); + public function addCollections(ConfigCollectionInfo $collection_info) { + $collections = $this->state->get('config_collection_install_test.collection_names', array()); + foreach ($collections as $collection) { + $collection_info->addCollection($collection); + } } /** diff -u b/core/modules/config/tests/config_override/lib/Drupal/config_override/ConfigOverrider.php b/core/modules/config/tests/config_override/lib/Drupal/config_override/ConfigOverrider.php --- b/core/modules/config/tests/config_override/lib/Drupal/config_override/ConfigOverrider.php +++ b/core/modules/config/tests/config_override/lib/Drupal/config_override/ConfigOverrider.php @@ -44,7 +44,7 @@ /** * {@inheritdoc} */ - public function getConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { + public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { return NULL; } diff -u b/core/modules/config/tests/config_override/lib/Drupal/config_override/ConfigOverriderLowPriority.php b/core/modules/config/tests/config_override/lib/Drupal/config_override/ConfigOverriderLowPriority.php --- b/core/modules/config/tests/config_override/lib/Drupal/config_override/ConfigOverriderLowPriority.php +++ b/core/modules/config/tests/config_override/lib/Drupal/config_override/ConfigOverriderLowPriority.php @@ -8,6 +8,7 @@ namespace Drupal\config_override; use Drupal\Core\Config\ConfigFactoryOverrideInterface; +use Drupal\Core\Config\StorageInterface; /** * Tests module overrides for configuration. @@ -44,7 +45,7 @@ /** * {@inheritdoc} */ - public function getConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { + public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { return NULL; } diff -u b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverride.php b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverride.php --- b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverride.php +++ b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverride.php @@ -8,7 +8,7 @@ namespace Drupal\language\Config; use Drupal\Component\Utility\String; -use Drupal\Core\Config\ConfigCollectionInfoEvent; +use Drupal\Core\Config\ConfigCollectionInfo; use Drupal\Core\Config\ConfigEvents; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\TypedConfigManagerInterface; @@ -152,7 +152,7 @@ /** * {@inheritdoc} */ - public function getConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { + public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { $langcode = $this->getLangcodeFromCollectionName($collection); return $this->getOverride($langcode, $name); } @@ -173,7 +173,7 @@ /** * Converts a configuration collection name to a langcode. * - * @param $collection + * @param string $collection * The configuration collection name. * * @return string @@ -196,15 +196,13 @@ /** * Reacts to the ConfigEvents::COLLECTION_INFO event. * - * @param \Drupal\Core\Config\ConfigCollectionInfoEvent $event + * @param \Drupal\Core\Config\ConfigCollectionInfo $collection_info * The configuration collection names event. */ - public function addCollections(ConfigCollectionInfoEvent $event) { - $collections = array(); + public function addCollections(ConfigCollectionInfo $collection_info) { foreach (\Drupal::languageManager()->getLanguages() as $language) { - $collections[] = $this->createConfigCollectionName($language->getId()); + $collection_info->addCollection($this->createConfigCollectionName($language->getId()), $this); } - $event->addCollections($collections, $this); } /** diff -u b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverrideInterface.php b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverrideInterface.php --- b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverrideInterface.php +++ b/core/modules/language/lib/Drupal/language/Config/LanguageConfigFactoryOverrideInterface.php @@ -63,8 +63,8 @@ * @param string $langcode * Language code. * - * @return \Drupal\language\Config\LanguageOverrideStorageInterface - * The language override storage object. + * @return \Drupal\Core\Config\StorageInterface + * The storage instance for a particular langcode. */ public function getStorage($langcode); diff -u b/core/modules/language/lib/Drupal/language/ConfigurableLanguageManagerInterface.php b/core/modules/language/lib/Drupal/language/ConfigurableLanguageManagerInterface.php --- b/core/modules/language/lib/Drupal/language/ConfigurableLanguageManagerInterface.php +++ b/core/modules/language/lib/Drupal/language/ConfigurableLanguageManagerInterface.php @@ -102,7 +102,7 @@ * @param string $langcode * The language code for the override. * - * @param \Drupal\Core\Config\StorageInterface $storage + * @return \Drupal\Core\Config\StorageInterface $storage * A storage object to use for reading and writing the * configuration override. */ diff -u b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigOverrideImportTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigOverrideImportTest.php --- b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigOverrideImportTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigOverrideImportTest.php @@ -7,10 +7,12 @@ namespace Drupal\language\Tests; -use Drupal\Core\Config\FileStorage; use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; +/** + * Tests synchronization of language configuration overrides. + */ class LanguageConfigOverrideImportTest extends WebTestBase { /** @@ -29,7 +31,7 @@ } /** - * Tests that language can be enabled and overrides created during a sync. + * Tests that language can be enabled and overrides are created during a sync. */ public function testConfigOverrideImport() { language_save(new Language(array( @@ -94,7 +96,7 @@ $this->rebuildContainer(); \Drupal::service('router.builder')->rebuild(); - // Test that no config save event has been fired during the import becuase + // Test that no config save event has been fired during the import because // language configuration overrides do not fire events. $event_recorder = \Drupal::state()->get('config_events_test.event', FALSE); $this->assertFalse($event_recorder); diff -u b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigOverrideInstallTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigOverrideInstallTest.php --- b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigOverrideInstallTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigOverrideInstallTest.php @@ -9,6 +9,9 @@ use Drupal\Core\Language\Language; use Drupal\simpletest\KernelTestBase; +/** + * Tests language config override installation. + */ class LanguageConfigOverrideInstallTest extends KernelTestBase { /** @@ -20,8 +23,8 @@ public static function getInfo() { return array( - 'name' => 'Language config override synchronize', - 'description' => 'Ensures the language config overrides can be synchronized.', + 'name' => 'Language config override installation', + 'description' => 'Ensures the language config overrides can be installed.', 'group' => 'Language', ); } diff -u b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php --- b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php @@ -12,7 +12,6 @@ use Drupal\Core\Config\TypedConfigManager; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\language\Config\LanguageConfigFactoryOverrideInterface; use Drupal\language\ConfigurableLanguageManagerInterface; /** only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigCollectionInfo.php @@ -0,0 +1,79 @@ +collections[$collection] = $override_service; + } + + /** + * Gets the list of possible collection names. + * + * @param bool $include_default + * (Optional) Include the default collection. Defaults to TRUE. + * + * @return array + * The list of possible collection names. + */ + public function getCollectionNames($include_default = TRUE) { + $collection_names = array_keys($this->collections); + sort($collection_names); + if ($include_default) { + array_unshift($collection_names, StorageInterface::DEFAULT_COLLECTION); + } + return $collection_names; + } + + /** + * Gets the config factory override service responsible for the collection. + * + * @param string $collection + * The configuration collection. + * + * @return \Drupal\Core\Config\ConfigFactoryOverrideInterface|NULL + * The override service responsible for the collection if one exists. NULL + * if not. + */ + public function getOverrideService($collection) { + return isset($this->collections[$collection]) ? $this->collections[$collection] : NULL; + } + +}