only in patch2: unchanged: --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -250,7 +250,8 @@ public function reset($name = NULL) { * {@inheritdoc} */ public function rename($old_name, $new_name) { - Cache::invalidateTags($this->get($old_name)->getCacheTags()); + $old_config = $this->get($old_name); + Cache::invalidateTags($old_config->getCacheTags()); $this->storage->rename($old_name, $new_name); // Clear out the static cache of any references to the old name. @@ -260,7 +261,7 @@ public function rename($old_name, $new_name) { // Prime the cache and load the configuration with the correct overrides. $config = $this->get($new_name); - $this->eventDispatcher->dispatch(ConfigEvents::RENAME, new ConfigRenameEvent($config, $old_name)); + $this->eventDispatcher->dispatch(ConfigEvents::RENAME, new ConfigRenameEvent($config, $old_name, $old_config)); return $this; } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Config/ConfigRenameEvent.php +++ b/core/lib/Drupal/Core/Config/ConfigRenameEvent.php @@ -14,6 +14,13 @@ class ConfigRenameEvent extends ConfigCrudEvent { */ protected $oldName; + /** + * Configuration object before it has been renamed. + * + * @var \Drupal\Core\Config\Config + */ + protected $oldConfig; + /** * Constructs the config rename event. * @@ -21,10 +28,13 @@ class ConfigRenameEvent extends ConfigCrudEvent { * The configuration that has been renamed. * @param string $old_name * The old configuration object name. + * @param \Drupal\Core\Config\Config $old_config + * (optional) The configuration before it has been renamed. */ - public function __construct(Config $config, $old_name) { - $this->config = $config; + public function __construct(Config $config, $old_name, $old_config = NULL) { + parent::__construct($config); $this->oldName = $old_name; + $this->oldConfig = $old_config; } /** @@ -37,4 +47,14 @@ public function getOldName() { return $this->oldName; } + /** + * Gets the old configuration object. + * + * @return \Drupal\Core\Config\Config + * The configuration object the renaming of which caused the event to fire. + */ + public function getOldConfig() { + return $this->oldConfig; + } + } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php @@ -7,6 +7,7 @@ use Drupal\Core\Config\ConfigEvents; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigManagerInterface; +use Drupal\Core\Config\ConfigRenameEvent; use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Query\QueryBase; @@ -231,6 +232,26 @@ public function onConfigSave(ConfigCrudEvent $event) { } } + /** + * Updates configuration entity in the key store. + * + * @param \Drupal\Core\Config\ConfigRenameEvent $event + * The configuration event. + */ + public function onConfigRename(ConfigRenameEvent $event) { + $saved_config = $event->getConfig(); + $entity_type_id = $this->configManager->getEntityTypeIdByName($saved_config->getName()); + if ($entity_type_id) { + $entity_type = $this->configManager->getEntityManager()->getDefinition($entity_type_id); + // Delete the config key store for the old config. + if ($old_config = $event->getOldConfig()) { + $this->deleteConfigKeyStore($entity_type, $old_config); + } + // Update the config key store for the new config. + $this->updateConfigKeyStore($entity_type, $saved_config); + } + } + /** * Removes configuration entity from key store. * @@ -251,6 +272,7 @@ public function onConfigDelete(ConfigCrudEvent $event) { */ public static function getSubscribedEvents() { $events[ConfigEvents::SAVE][] = ['onConfigSave', 128]; + $events[ConfigEvents::RENAME][] = ['onConfigRename', 128]; $events[ConfigEvents::DELETE][] = ['onConfigDelete', 128]; return $events; }