Commit 9f07ce48 authored by catch's avatar catch
Browse files

Issue #2218003 by tim.plunkett: ConfigImporter assumes that a ConfigEntity...

Issue #2218003 by tim.plunkett: ConfigImporter assumes that a ConfigEntity uses a storage controller that implements ConfigStorageControllerInterface.
parent 68322396
......@@ -7,8 +7,12 @@
namespace Drupal\Core\Config;
use Drupal\Component\Utility\String;
use Drupal\Core\Config\ConfigEvents;
use Drupal\Core\Config\Entity\ConfigStorageControllerInterface;
use Drupal\Core\Config\Entity\ImportableEntityStorageInterface;
use Drupal\Core\DependencyInjection\DependencySerialization;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Lock\LockBackendInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
......@@ -292,14 +296,15 @@ protected function importConfig($op, $name) {
* @param string $name
* The name of the configuration to process.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* Thrown if the data is owned by an entity type, but the entity storage
* does not support imports.
*
* @return bool
* TRUE if the configuration was imported as a configuration entity. FALSE
* otherwise.
*/
protected function importInvokeOwner($op, $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 = $this->configManager->getEntityTypeIdByName($name)) {
......@@ -315,9 +320,13 @@ protected function importInvokeOwner($op, $name) {
}
$method = 'import' . ucfirst($op);
$handled_by_module = $this->configManager->getEntityManager()->getStorageController($entity_type)->$method($name, $new_config, $old_config);
}
if (!empty($handled_by_module)) {
$entity_storage = $this->configManager->getEntityManager()->getStorageController($entity_type);
// Call to the configuration entity's storage controller to handle the
// configuration change.
if (!($entity_storage instanceof ImportableEntityStorageInterface)) {
throw new EntityStorageException(String::format('The entity storage "@storage" for the "@entity_type" entity type does not support imports', array('@storage' => get_class($entity_storage), '@entity_type' => $entity_type)));
}
$entity_storage->$method($name, $new_config, $old_config);
$this->setProcessed($op, $name);
return TRUE;
}
......
......@@ -35,7 +35,7 @@
* after the config_prefix in a config name forms the entity ID. Additional or
* custom suffixes are not possible.
*/
class ConfigStorageController extends EntityStorageControllerBase implements ConfigStorageControllerInterface {
class ConfigStorageController extends EntityStorageControllerBase implements ConfigStorageControllerInterface, ImportableEntityStorageInterface {
/**
* The UUID service.
......
......@@ -15,51 +15,6 @@
*/
interface ConfigStorageControllerInterface extends EntityStorageControllerInterface {
/**
* Create configuration upon synchronizing configuration changes.
*
* This callback is invoked when configuration is synchronized between storages
* and allows a module to take over the synchronization of configuration data.
*
* @param string $name
* The name of the configuration object.
* @param \Drupal\Core\Config\Config $new_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);
/**
* Updates configuration upon synchronizing configuration changes.
*
* This callback is invoked when configuration is synchronized between storages
* and allows a module to take over the synchronization of configuration data.
*
* @param string $name
* The name of the configuration object.
* @param \Drupal\Core\Config\Config $new_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 importUpdate($name, Config $new_config, Config $old_config);
/**
* Delete configuration upon synchronizing configuration changes.
*
* This callback is invoked when configuration is synchronized between storages
* and allows a module to take over the synchronization of configuration data.
*
* @param string $name
* The name of the configuration object.
* @param \Drupal\Core\Config\Config $new_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);
/**
* Returns the config prefix used by the configuration entity type.
*
......
<?php
/**
* @file
* Contains \Drupal\Core\Config\Entity\ImportableEntityStorageInterface.
*/
namespace Drupal\Core\Config\Entity;
use Drupal\Core\Config\Config;
/**
* Provides an interface for responding to configuration imports.
*
* When configuration is synchronized between storages, the entity storage must
* handle the synchronization of configuration data for its entity.
*/
interface ImportableEntityStorageInterface {
/**
* Creates entities upon synchronizing configuration changes.
*
* @param string $name
* The name of the configuration object.
* @param \Drupal\Core\Config\Config $new_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);
/**
* Updates entities upon synchronizing configuration changes.
*
* @param string $name
* The name of the configuration object.
* @param \Drupal\Core\Config\Config $new_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 importUpdate($name, Config $new_config, Config $old_config);
/**
* Delete entities upon synchronizing configuration changes.
*
* @param string $name
* The name of the configuration object.
* @param \Drupal\Core\Config\Config $new_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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment