diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index ba2ece6..edfdf58 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -291,23 +291,19 @@ protected function importInvokeOwner() { // to handle dependencies correctly. foreach (array('delete', 'create', 'update') as $op) { foreach ($this->getUnprocessed($op) as $name) { - // Call to the configuration entity's storage controller to handle the - // configuration change. $handled_by_module = FALSE; - // Validate the configuration object name before importing it. - // Config::validateName($name); if ($entity_type = config_get_entity_type_by_name($name)) { - $old_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->context); - $old_config->load(); - - $data = $this->storageComparer->getSourceStorage()->read($name); - $new_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->context); - if ($data !== FALSE) { - $new_config->setData($data); + switch ($op) { + case 'delete': + $handled_by_module = $this->importInvokeOwnerDelete($name, $entity_type); + break; + case 'create': + $handled_by_module = $this->importInvokeOwnerCreate($name, $entity_type); + break; + case 'update': + $handled_by_module = $this->importInvokeOwnerUpdate($name, $entity_type); + break; } - - $method = 'import' . ucfirst($op); - $handled_by_module = $this->entityManager->getStorageController($entity_type)->$method($name, $new_config, $old_config); } if (!empty($handled_by_module)) { $this->setProcessed($op, $name); @@ -317,6 +313,60 @@ protected function importInvokeOwner() { } /** + * Invokes importUpdate methods on configuration entity storage controllers. + * + * @param string $name + * The name of the configuration object. + * @param string $entity_type + * The machine name of the entity type for this configuration object. + * + * @return boolean + * Whether this configuration object was handled by the owning module. + */ + protected function importInvokeOwnerUpdate($name, $entity_type) { + $old_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->context); + $old_config->load(); + + $data = $this->storageComparer->getSourceStorage()->read($name); + $new_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->context); + return $this->entityManager->getStorageController($entity_type)->importUpdate($name, $new_config, $old_config); + } + + /** + * Invokes importDelete methods on configuration entity storage controllers. + * + * @param string $name + * The name of the configuration object. + * @param string $entity_type + * The machine name of the entity type for this configuration object. + * + * @return boolean + * Whether this configuration object was handled by the owning module. + */ + protected function importInvokeOwnerDelete($name, $entity_type) { + $config = new Config($name, $this->storageComparer->getTargetStorage(), $this->context); + $data = $this->storageComparer->getTargetStorage()->read($name); + return $this->entityManager->getStorageController($entity_type)->importDelete($name, $config); + } + + /** + * Invokes importCreate methods on configuration entity storage controllers. + * + * @param string $name + * The name of the configuration object. + * @param string $entity_type + * The machine name of the entity type for this configuration object. + * + * @return boolean + * Whether this configuration object was handled by the owning module. + */ + protected function importInvokeOwnerCreate($name, $entity_type) { + $data = $this->storageComparer->getSourceStorage()->read($name); + $config = new Config($name, $this->storageComparer->getTargetStorage(), $this->context); + return $this->entityManager->getStorageController($entity_type)->importCreate($name, $config); + } + + /** * Dispatches a config importer event. * * @param string $event_name diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 2fd44c4..d417d80 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -477,13 +477,11 @@ public function getQueryServicename() { * * @param string $name * The name of the configuration object. - * @param \Drupal\Core\Config\Config $new_config + * @param \Drupal\Core\Config\Config $config * A configuration object containing the new configuration data. - * @param \Drupal\Core\Config\Config $old_config - * A configuration object containing the old configuration data. */ - public function importCreate($name, Config $new_config, Config $old_config) { - $entity = $this->create($new_config->get()); + public function importCreate($name, Config $config) { + $entity = $this->create($config->get()); $entity->save(); return TRUE; } @@ -526,12 +524,10 @@ public function importUpdate($name, Config $new_config, Config $old_config) { * * @param string $name * The name of the configuration object. - * @param \Drupal\Core\Config\Config $new_config + * @param \Drupal\Core\Config\Config $config * A configuration object containing the new configuration data. - * @param \Drupal\Core\Config\Config $old_config - * A configuration object containing the old configuration data. */ - public function importDelete($name, Config $new_config, Config $old_config) { + public function importDelete($name, Config $config) { $id = static::getIDFromConfigName($name, $this->entityInfo['config_prefix']); $entity = $this->load($id); $entity->delete(); diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestStorageController.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestStorageController.php index a73cffb..6155899 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestStorageController.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestStorageController.php @@ -18,11 +18,11 @@ class ConfigTestStorageController extends ConfigStorageController { /** * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::importCreate(). */ - public function importCreate($name, Config $new_config, Config $old_config) { + public function importCreate($name, Config $config) { // Set a global value we can check in test code. $GLOBALS['hook_config_import'] = __METHOD__; - return parent::importCreate($name, $new_config, $old_config); + return parent::importCreate($name, $config); } /** @@ -38,11 +38,11 @@ public function importUpdate($name, Config $new_config, Config $old_config) { /** * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::importDelete(). */ - public function importDelete($name, Config $new_config, Config $old_config) { + public function importDelete($name, Config $config) { // Set a global value we can check in test code. $GLOBALS['hook_config_import'] = __METHOD__; - return parent::importDelete($name, $new_config, $old_config); + return parent::importDelete($name, $config); } } diff --git a/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php b/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php index d74db76..f4af3f7 100644 --- a/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php +++ b/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php @@ -98,14 +98,14 @@ public static function createInstance(ContainerInterface $container, $entity_typ /** * {@inheritdoc} */ - public function importDelete($name, Config $new_config, Config $old_config) { + public function importDelete($name, Config $config) { // If the field has been deleted in the same import, the instance will be // deleted by then, and there is nothing left to do. Just return TRUE so // that the file does not get written to active store. - if (!$old_config->get()) { + if (!$config->get()) { return TRUE; } - return parent::importDelete($name, $new_config, $old_config); + return parent::importDelete($name, $config); } /**