diff --git a/core/lib/Drupal/Core/Config/ConfigCachePrimeSubscriber.php b/core/lib/Drupal/Core/Config/ConfigCachePrimeSubscriber.php index fd5d2bd..4b38d30 100644 --- a/core/lib/Drupal/Core/Config/ConfigCachePrimeSubscriber.php +++ b/core/lib/Drupal/Core/Config/ConfigCachePrimeSubscriber.php @@ -32,8 +32,8 @@ public function onConfigCachePrimeGetSettingsNames(ConfigCachePrimeEvent $event) /** * {@inheritdoc} */ - static function getSubscribedEvents() { - $events['config.prime.cache'][] = array('onConfigCachePrimeGetSettingsNames'); + public static function getSubscribedEvents() { + $events[ConfigEvents::PRIME][] = array('onConfigCachePrimeGetSettingsNames'); return $events; } diff --git a/core/lib/Drupal/Core/Config/ConfigEvents.php b/core/lib/Drupal/Core/Config/ConfigEvents.php index 0b0bb3a..bcc95bc 100644 --- a/core/lib/Drupal/Core/Config/ConfigEvents.php +++ b/core/lib/Drupal/Core/Config/ConfigEvents.php @@ -57,4 +57,11 @@ */ const IMPORT = 'config.importer.import'; + /** + * Name of event fired when config cache is primed. + * @see \Drupal\Core\Config\ConfigFactory::getCachePrimeNames(). + * @see \Drupal\Core\Config\ConfigCachePrimeSubscriber::getSubscribedEvents(). + */ + const PRIME = 'config.prime.cache'; + } diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index 7d9f541..51d0680 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -158,7 +158,7 @@ public function get($name) { */ public function loadMultiple(array $names) { if (!$this->isCachePrimed) { - $names = array_unique($names + $this->getCachePrimeNames()); + $names = array_unique(array_merge($names, $this->getCachePrimeNames())); } $list = array(); @@ -251,7 +251,7 @@ protected function getCachePrimeNames() { // dispatching the event to avoid unintended recursion. $this->isCachePrimed = TRUE; $config_cache_prime_event = new ConfigCachePrimeEvent(); - $this->eventDispatcher->dispatch('config.cache.prime', $config_cache_prime_event); + $this->eventDispatcher->dispatch(ConfigEvents::PRIME, $config_cache_prime_event); return $config_cache_prime_event->getNames(); } diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigFactoryTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigFactoryTest.php new file mode 100644 index 0000000..8f2a1ec --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Config/ConfigFactoryTest.php @@ -0,0 +1,67 @@ + 'Config factoryt test', + 'description' => 'Tests the Config factory.', + 'group' => 'Configuration', + ); + } + + /** + * Tests loading multiple with prime config names. + */ + public function testLoadMultipleWithCachePrimeNames() { + + $storage = $this->getMock('Drupal\Core\Config\StorageInterface'); + + $config_data = array('test1' => array('config1'), 'prime1' => array('config2')); + $storage->expects($this->once()) + ->method('readMultiple') + ->with(array('test1', 'prime1', 'prime2', 'language1')) + ->will($this->returnValue($config_data)); + + $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $typed_config_manager = $this->getMockBuilder('\Drupal\Core\Config\TypedConfigManager') + ->disableOriginalConstructor() + ->getMock(); + + $config_factory = new TestConfigFactory($storage, $event_dispatcher, $typed_config_manager); + + $names = ['test1']; + + $configs = $config_factory->loadMultiple($names); + + } + +} + +class TestConfigFactory extends ConfigFactory { + + protected function getCachePrimeNames() { + return array('prime1', 'prime2'); + } + + public function getLanguageConfigNames(array $names) { + return array('language1'); + } +}