diff --git a/core/core.services.yml b/core/core.services.yml index 402d6ee..f34afcd 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -84,6 +84,10 @@ services: config.installer: class: Drupal\Core\Config\ConfigInstaller arguments: ['@config.factory', '@config.storage', '@config.typed', '@entity.manager', '@event_dispatcher'] + config.preload_subscriber: + class: Drupal\Core\Config\ConfigPreloadSubscriber + tags: + - { name: event_subscriber } config.storage.staging: class: Drupal\Core\Config\FileStorage factory_class: Drupal\Core\Config\FileStorageFactory diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index 9d9d767..a40ebc7 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -9,6 +9,8 @@ use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageDefault; +use Drupal\Core\Config\ConfigPreloadEvent; +use Drupal\Core\Config\ConfigModuleOverridesEvent; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -71,6 +73,13 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface protected $typedConfigManager; /** + * Whether or not the preload event has fired yet. + * + * @var boolean + */ + protected $preloadEventFired; + + /** * Constructs the Config factory. * * @param \Drupal\Core\Config\StorageInterface $storage @@ -84,6 +93,7 @@ public function __construct(StorageInterface $storage, EventDispatcherInterface $this->storage = $storage; $this->eventDispatcher = $event_dispatcher; $this->typedConfigManager = $typed_config; + $this->preloadEventFired = FALSE; } /** @@ -154,6 +164,11 @@ public function get($name) { public function loadMultiple(array $names) { global $conf; + if (!$this->preloadEventFired) { + $this->preloadEventFired = TRUE; + $names = array_unique($names + $this->getPreloadNames()); + } + $list = array(); foreach ($names as $key => $name) { @@ -232,6 +247,18 @@ protected function loadModuleOverrides(array $names) { } /** + * Get a list of configuration object names to preload. + * + * @return array + * An array of configuration object names to preload. + */ + protected function getPreloadNames() { + $config_preload_event = new ConfigPreloadEvent(); + $this->eventDispatcher->dispatch('config.preload.names', $config_preload_event); + return $config_preload_event->getNames(); + } + + /** * {@inheritdoc} */ public function reset($name = NULL) { diff --git a/core/lib/Drupal/Core/Config/ConfigPreloadEvent.php b/core/lib/Drupal/Core/Config/ConfigPreloadEvent.php new file mode 100644 index 0000000..e314786 --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigPreloadEvent.php @@ -0,0 +1,65 @@ +names; + } + + /** + * Adds configuration object names to preload. + * + * @param array $names + * The configuration object names to preload. + * + * @return self + * The ConfigPreloadEvent object. + */ + public function addNames(array $names) { + $this->names += $names; + $this->names = array_unique($this->names); + return $this; + } + + /** + * Removes configuration object names to preload. + * + * @param array $names_to_remove + * The configuration object names remove preload. + * + * @return self + * The ConfigPreloadEvent object. + */ + public function removeNames(array $names_to_remove) { + $this->names = array_diff($this->names, $names_to_remove); + return $this; + } + +} + diff --git a/core/lib/Drupal/Core/Config/ConfigPreloadSubscriber.php b/core/lib/Drupal/Core/Config/ConfigPreloadSubscriber.php new file mode 100644 index 0000000..959d568 --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigPreloadSubscriber.php @@ -0,0 +1,40 @@ +get('config_preload_names', array()); + if ($settings_config_names) { + $event->addNames($settings_config_names); + } + } + + /** + * Implements EventSubscriberInterface::getSubscribedEvents(). + */ + static function getSubscribedEvents() { + $events['config.preload.names'][] = array('onConfigPreloadNamesGetSettingsNames', 48); + return $events; + } +} + diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index 616f260..e772089 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -278,6 +278,14 @@ $settings['update_free_access'] = FALSE; /** + * Configuration preload. + * + * The core configuration system will preload any configuration objects named + * in this array. + */ +#$settings['config_preload_names'] = array(); + +/** * Twig debugging: * * When debugging is enabled: