diff -u b/core/lib/Drupal/Core/Config/ConfigCollectionInfoEvent.php b/core/lib/Drupal/Core/Config/ConfigCollectionInfoEvent.php --- b/core/lib/Drupal/Core/Config/ConfigCollectionInfoEvent.php +++ b/core/lib/Drupal/Core/Config/ConfigCollectionInfoEvent.php @@ -10,7 +10,7 @@ use Symfony\Component\EventDispatcher\Event; /** - * Wraps a configuration event for event listeners. + * Gets information on all the possible configuration collections. */ class ConfigCollectionInfoEvent extends Event { @@ -22,7 +22,7 @@ protected $collections = array(); /** - * Adds names to the list of possible collections. + * Adds collections to the list of possible collections. * * @param array $collections * Collection names to add. @@ -30,7 +30,7 @@ * (optional) The configuration factory override service responsible for the * collection. */ - public function addCollectionNames(array $collections, ConfigFactoryOverrideInterface $override_service = NULL) { + public function addCollections(array $collections, ConfigFactoryOverrideInterface $override_service = NULL) { if (count($collections) > 0) { $collections_to_add = array_combine($collections, array_fill(0, count($collections), $override_service)); $this->collections = array_merge($this->collections, $collections_to_add); @@ -38,7 +38,7 @@ } /** - * Adds a name to the list of possible collections. + * Adds a collection to the list of possible collections. * * @param string $collection * Collection name to add. @@ -46,8 +46,8 @@ * (optional) The configuration factory override service responsible for the * collection. */ - public function addCollectionName($collection, ConfigFactoryOverrideInterface $override_service = NULL) { - $this->addCollectionNames(array($collection), $override_service); + public function addCollection($collection, ConfigFactoryOverrideInterface $override_service = NULL) { + $this->addCollections(array($collection), $override_service); } /** 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 @@ -156,13 +156,6 @@ protected $totalConfigurationToProcess = 0; /** - * The ConfigCollectionInfoEvent after dispatch. - * - * @var \Drupal\Core\Config\ConfigCollectionInfoEvent - */ - protected $configCollectionInfo; - - /** * Constructs a configuration import object. * * @param \Drupal\Core\Config\StorageComparerInterface $storage_comparer @@ -903,7 +896,7 @@ * The name of the configuration to process. */ protected function importConfig($collection, $op, $name) { - $overrider = $this->getConfigCollectionInfo()->getOverrideService($collection); + $overrider = $this->configManager->getConfigCollectionInfo()->getOverrideService($collection); if ($overrider) { $config = $overrider->getConfigObject($name, $collection); } @@ -1058,26 +1051,2 @@ - /** - * Gets available collection information using the event. - * - * @return \Drupal\Core\Config\ConfigCollectionInfoEvent - * The event which collects information about all the available collections. - */ - protected function getConfigCollectionInfo() { - if (!isset($this->configCollectionInfo)) { - $this->configCollectionInfo = new ConfigCollectionInfoEvent(); - $this->eventDispatcher->dispatch(ConfigEvents::COLLECTION_NAMES, $this->configCollectionInfo); - } - return $this->configCollectionInfo; - } - - /** - * {@inheritdoc} - */ - public function __sleep() { - // Unset the collection information since this can contain references to - // services. - $this->configCollectionInfo = NULL; - return parent::__sleep(); - } - } 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 @@ -96,10 +96,8 @@ $this->typedConfig->clearCachedDefinitions(); } - // Gather all the supported collection names. - $event = new ConfigCollectionInfoEvent(); - $this->eventDispatcher->dispatch(ConfigEvents::COLLECTION_NAMES, $event); - $collections = $event->getCollectionNames(); + // Gather information about all the supported collections. + $collection_info = $this->configManager->getConfigCollectionInfo(); $old_state = $this->configFactory->getOverrideState(); $this->configFactory->setOverrideState(FALSE); @@ -110,10 +108,10 @@ $enabled_extensions = array_keys((array) $extension_config->get('module')); $enabled_extensions += array_keys((array) $extension_config->get('theme')); - foreach ($collections as $collection) { + 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, $event); + $this->createConfiguration($collection, $config_to_install, $collection_info); } } $this->configFactory->setOverrideState($old_state); @@ -169,10 +167,10 @@ * The configuration collection. * @param array $config_to_install * A list of configuration object names to create. - * @param \Drupal\Core\Config\ConfigCollectionInfoEvent $event - * The event which holds information about configuration collections. + * @param \Drupal\Core\Config\ConfigCollectionInfoEvent $collection_info + * The configuration collection information. */ - protected function createConfiguration($collection, array $config_to_install, ConfigCollectionInfoEvent $event) { + protected function createConfiguration($collection, array $config_to_install, ConfigCollectionInfoEvent $collection_info) { // 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); @@ -187,7 +185,7 @@ $config_to_install = array_diff($config_to_install, $this->getActiveStorage($collection)->listAll()); foreach ($config_to_install as $name) { - $overrider = $event->getOverrideService($collection); + $overrider = $collection_info->getOverrideService($collection); if ($overrider) { $new_config = $overrider->getConfigObject($name, $collection); } @@ -246,13 +244,11 @@ return in_array($provider, $enabled_extensions); }); if (!empty($config_to_install)) { - // Gather information about all the collection names. - $event = new ConfigCollectionInfoEvent(); - $this->eventDispatcher->dispatch(ConfigEvents::COLLECTION_NAMES, $event); - + // 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, $event); + $this->createConfiguration($collection, $config_to_install, $collection_info); $this->configFactory->setOverrideState($old_state); // Reset all the static caches and list caches. $this->configFactory->reset(); 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 @@ -37,15 +37,15 @@ * @param \Drupal\Core\Config\ConfigCollectionInfoEvent $event * The configuration collection names event. */ - public function addCollectionNames(ConfigCollectionInfoEvent $event) { - $event->addCollectionNames($this->state->get('config_collection_install_test.collection_names', array())); + public function addCollections(ConfigCollectionInfoEvent $event) { + $event->addCollections($this->state->get('config_collection_install_test.collection_names', array())); } /** * {@inheritdoc} */ static function getSubscribedEvents() { - $events[ConfigEvents::COLLECTION_NAMES][] = array('addCollectionNames'); + $events[ConfigEvents::COLLECTION_INFO][] = array('addCollections'); return $events; } 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 @@ -194,24 +194,24 @@ } /** - * Reacts to the ConfigEvents::COLLECTION_NAMES event. + * Reacts to the ConfigEvents::COLLECTION_INFO event. * * @param \Drupal\Core\Config\ConfigCollectionInfoEvent $event * The configuration collection names event. */ - public function addCollectionNames(ConfigCollectionInfoEvent $event) { + public function addCollections(ConfigCollectionInfoEvent $event) { $collections = array(); foreach (\Drupal::languageManager()->getLanguages() as $language) { $collections[] = $this->createConfigCollectionName($language->getId()); } - $event->addCollectionNames($collections, $this); + $event->addCollections($collections, $this); } /** * {@inheritdoc} */ static function getSubscribedEvents() { - $events[ConfigEvents::COLLECTION_NAMES][] = array('addCollectionNames'); + $events[ConfigEvents::COLLECTION_INFO][] = array('addCollections'); return $events; } 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 @@ -72,7 +72,9 @@ * Tests that configuration events are not fired during a sync of overrides. */ public function testConfigOverrideImportEvents() { + // Enable the config_events_test module so we can record events occurring. \Drupal::moduleHandler()->install(array('config_events_test')); + $this->rebuildContainer(); language_save(new Language(array( 'name' => 'French', only in patch2: unchanged: --- a/core/core.services.yml +++ b/core/core.services.yml @@ -77,7 +77,7 @@ services: arguments: [discovery] 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', '@event_dispatcher'] config.factory: class: Drupal\Core\Config\ConfigFactory tags: only in patch2: unchanged: --- a/core/lib/Drupal/Core/Config/ConfigEvents.php +++ b/core/lib/Drupal/Core/Config/ConfigEvents.php @@ -55,6 +55,6 @@ * * @see \Drupal\Core\Config\ConfigInstaller::installDefaultConfig() */ - const COLLECTION_NAMES = 'config.collection_names'; + const COLLECTION_INFO = 'config.collection_info'; } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Config/ConfigManager.php +++ b/core/lib/Drupal/Core/Config/ConfigManager.php @@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\StringTranslation\TranslationManager; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * The ConfigManager provides helper functions for the configuration system. @@ -54,6 +55,20 @@ class ConfigManager implements ConfigManagerInterface { protected $activeStorage; /** + * The event dispatcher. + * + * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface + */ + protected $eventDispatcher; + + /** + * The configuration collection info. + * + * @var \Drupal\Core\Config\ConfigCollectionInfoEvent + */ + protected $configCollectionInfo; + + /** * Creates ConfigManager objects. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -64,13 +79,15 @@ class ConfigManager implements ConfigManagerInterface { * The typed config manager. * @param \Drupal\Core\StringTranslation\TranslationManager $string_translation * The string translation service. + * * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */ - 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, EventDispatcherInterface $event_dispatcher) { $this->entityManager = $entity_manager; $this->configFactory = $config_factory; $this->typedConfigManager = $typed_config_manager; $this->stringTranslation = $string_translation; $this->activeStorage = $active_storage; + $this->eventDispatcher = $event_dispatcher; } /** @@ -246,4 +263,16 @@ public function findConfigEntityDependentsAsEntities($type, array $names) { public function supportsConfigurationEntities($collection) { return $collection == StorageInterface::DEFAULT_COLLECTION; } + + /** + * {@inheritdoc} + */ + public function getConfigCollectionInfo() { + if (!isset($this->configCollectionInfo)) { + $this->configCollectionInfo = new ConfigCollectionInfoEvent(); + $this->eventDispatcher->dispatch(ConfigEvents::COLLECTION_INFO, $this->configCollectionInfo); + } + return $this->configCollectionInfo; + } + } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Config/ConfigManagerInterface.php +++ b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php @@ -123,4 +123,12 @@ public function findConfigEntityDependentsAsEntities($type, array $names); */ public function supportsConfigurationEntities($collection); + /** + * Gets available collection information using the event. + * + * @return \Drupal\Core\Config\ConfigCollectionInfoEvent + * The event which collects information about all the available collections. + */ + public function getConfigCollectionInfo(); + }