diff --git a/core/core.services.yml b/core/core.services.yml index d10db5b..193c03b 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -70,6 +70,9 @@ services: class: Drupal\Core\Config\FileStorage factory_class: Drupal\Core\Config\FileStorageFactory factory_method: getActive + config.entity_manager: + class: Drupal\Core\Config\Entity\ConfigEntityManager + arguments: ['@entity.manager'] config.storage: class: Drupal\Core\Config\CachedStorage arguments: ['@config.cachedstorage.storage', '@cache.config'] @@ -83,7 +86,7 @@ services: arguments: ['@config.storage', '@event_dispatcher', '@config.typed'] config.installer: class: Drupal\Core\Config\ConfigInstaller - arguments: ['@config.factory', '@config.storage', '@config.typed', '@entity.manager', '@event_dispatcher'] + arguments: ['@config.factory', '@config.storage', '@config.typed', '@config.entity_manager', '@event_dispatcher'] config.storage.staging: class: Drupal\Core\Config\FileStorage factory_class: Drupal\Core\Config\FileStorageFactory diff --git a/core/includes/config.inc b/core/includes/config.inc index 954c470..52a082f 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -70,22 +70,6 @@ function config($name) { } /** - * Returns the entity type of a configuration object. - * - * @param string $name - * The configuration object name. - * - * @return string|null - * Either the entity type name, or NULL if none match. - */ -function config_get_entity_type_by_name($name) { - $entities = array_filter(\Drupal::entityManager()->getDefinitions(), function (EntityTypeInterface $entity_info) use ($name) { - return ($config_prefix = $entity_info->getConfigPrefix()) && strpos($name, $config_prefix . '.') === 0; - }); - return key($entities); -} - -/** * Returns the typed config manager service. * * Use the typed data manager service for creating typed configuration objects. diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index e2354f4..0e2a953 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -7,10 +7,8 @@ namespace Drupal\Core\Config; -use Drupal\Core\Config\TypedConfigManager; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Config\Entity\ConfigEntityManagerInterface; use Drupal\Core\Lock\LockBackendInterface; -use Drupal\Component\Uuid\UuidInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -54,25 +52,25 @@ class ConfigImporter { protected $eventDispatcher; /** - * The configuration factory. + * The config entity manager. * - * @var \Drupal\Core\Config\ConfigFactory + * @var \Drupal\Core\Config\Entity\ConfigEntityManagerInterface */ - protected $configFactory; + protected $configEntityManager; /** - * The plugin manager for entities. + * The used lock backend instance. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Lock\LockBackendInterface */ - protected $entityManager; + protected $lock; /** - * The used lock backend instance. + * The typed config manager. * - * @var \Drupal\Core\Lock\LockBackendInterface + * @var \Drupal\Core\Config\TypedConfigManager */ - protected $lock; + protected $typedConfigManager; /** * List of changes processed by the import(). @@ -89,20 +87,6 @@ class ConfigImporter { protected $validated; /** - * The UUID service. - * - * @var \Drupal\Component\Uuid\UuidInterface - */ - protected $uuidService; - - /** - * The typed config manager. - * - * @var \Drupal\Core\Config\TypedConfigManager - */ - protected $typedConfigManager; - - /** * Constructs a configuration import object. * * @param \Drupal\Core\Config\StorageComparerInterface $storage_comparer @@ -110,24 +94,18 @@ class ConfigImporter { * access the source and target storage objects. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * The event dispatcher used to notify subscribers of config import events. - * @param \Drupal\Core\Config\ConfigFactory $config_factory - * The config factory that statically caches config objects. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager used to import config entities. + * @param \Drupal\Core\Config\Entity\ConfigEntityManagerInterface $config_entity_manager + * The config entity manager used to import config entities. * @param \Drupal\Core\Lock\LockBackendInterface * The lock backend to ensure multiple imports do not occur at the same time. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_service - * The UUID service. * @param \Drupal\Core\Config\TypedConfigManager $typed_config * The typed configuration manager. */ - public function __construct(StorageComparerInterface $storage_comparer, EventDispatcherInterface $event_dispatcher, ConfigFactory $config_factory, EntityManagerInterface $entity_manager, LockBackendInterface $lock, UuidInterface $uuid_service, TypedConfigManager $typed_config) { + public function __construct(StorageComparerInterface $storage_comparer, EventDispatcherInterface $event_dispatcher, ConfigEntityManagerInterface $config_entity_manager, LockBackendInterface $lock, TypedConfigManager $typed_config) { $this->storageComparer = $storage_comparer; $this->eventDispatcher = $event_dispatcher; - $this->configFactory = $config_factory; - $this->entityManager = $entity_manager; + $this->configEntityManager = $config_entity_manager; $this->lock = $lock; - $this->uuidService = $uuid_service; $this->typedConfigManager = $typed_config; $this->processed = $this->storageComparer->getEmptyChangelist(); } @@ -294,7 +272,7 @@ protected function importInvokeOwner() { $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)) { + if ($entity_type = $this->configEntityManager->getEntityTypeIdByName($name)) { $old_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); if ($old_data = $this->storageComparer->getTargetStorage()->read($name)) { $old_config->initWithData($old_data); @@ -307,7 +285,7 @@ protected function importInvokeOwner() { } $method = 'import' . ucfirst($op); - $handled_by_module = $this->entityManager->getStorageController($entity_type)->$method($name, $new_config, $old_config); + $handled_by_module = $this->configEntityManager->getStorageController($entity_type)->$method($name, $new_config, $old_config); } if (!empty($handled_by_module)) { $this->setProcessed($op, $name); diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index 0be3354..d5f32e5 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Config; use Drupal\Component\Utility\Unicode; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Config\Entity\ConfigEntityManagerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; class ConfigInstaller implements ConfigInstallerInterface { @@ -35,11 +35,11 @@ class ConfigInstaller implements ConfigInstallerInterface { protected $typedConfig; /** - * The entity manager. + * The config entity manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Config\Entity\ConfigEntityManagerInterface */ - protected $entityManager; + protected $configEntityManager; /** * The event dispatcher. @@ -57,16 +57,16 @@ class ConfigInstaller implements ConfigInstallerInterface { * The active configuration storage. * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config * The typed configuration manager. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. + * @param \Drupal\Core\Config\Entity\ConfigEntityManagerInterface $config_entity_manager + * The config entity manager. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * The event dispatcher. */ - public function __construct(ConfigFactory $config_factory, StorageInterface $active_storage, TypedConfigManagerInterface $typed_config, EntityManagerInterface $entity_manager, EventDispatcherInterface $event_dispatcher) { + public function __construct(ConfigFactory $config_factory, StorageInterface $active_storage, TypedConfigManagerInterface $typed_config, ConfigEntityManagerInterface $config_entity_manager, EventDispatcherInterface $event_dispatcher) { $this->configFactory = $config_factory; $this->activeStorage = $active_storage; $this->typedConfig = $typed_config; - $this->entityManager = $entity_manager; + $this->configEntityManager = $config_entity_manager; $this->eventDispatcher = $event_dispatcher; } @@ -119,8 +119,8 @@ public function installDefaultConfig($type, $name) { if ($data !== FALSE) { $new_config->setData($data); } - if ($entity_type = config_get_entity_type_by_name($name)) { - $this->entityManager + if ($entity_type = $this->configEntityManager->getEntityTypeIdByName($name)) { + $this->configEntityManager ->getStorageController($entity_type) ->create($new_config->get()) ->save(); diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityManager.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManager.php new file mode 100644 index 0000000..0e97114 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManager.php @@ -0,0 +1,55 @@ +entityManager = $entity_manager; + } + + /** + * Returns the entity type of a configuration object. + * + * @param string $name + * The configuration object name. + * + * @return string|null + * Either the entity type name, or NULL if none match. + */ + function getEntityTypeIdByName($name) { + $entities = array_filter($this->entityManager->getDefinitions(), function (EntityTypeInterface $entity_info) use ($name) { + return ($config_prefix = $entity_info->getConfigPrefix()) && strpos($name, $config_prefix . '.') === 0; + }); + return key($entities); + } + + /** + * {@inheritdoc} + */ + public function getStorageController($entity_type) { + return $this->entityManager->getStorageController($entity_type); + } + +} diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityManagerInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManagerInterface.php new file mode 100644 index 0000000..59799f6 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManagerInterface.php @@ -0,0 +1,37 @@ +sourceStorage = $sourceStorage; $this->targetStorage = $targetStorage; $this->lock = $lock; $this->eventDispatcher = $event_dispatcher; - $this->configFactory = $config_factory; - $this->entity_manager = $entity_manager; + $this->configEntityManager = $config_entity_manager; $this->urlGenerator = $url_generator; - $this->uuidService = $uuid_service; $this->typedConfigManager = $typed_config; } @@ -123,10 +108,8 @@ public static function create(ContainerInterface $container) { $container->get('config.storage'), $container->get('lock'), $container->get('event_dispatcher'), - $container->get('config.factory'), - $container->get('entity.manager'), + $container->get('config.entity_manager'), $container->get('url_generator'), - $container->get('uuid'), $container->get('config.typed') ); } @@ -236,10 +219,8 @@ public function submitForm(array &$form, array &$form_state) { $config_importer = new ConfigImporter( $form_state['storage_comparer'], $this->eventDispatcher, - $this->configFactory, - $this->entity_manager, + $this->configEntityManager, $this->lock, - $this->uuidService, $this->typedConfigManager ); if ($config_importer->alreadyImporting()) { diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php index ec445c5..d5b5aa9 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php @@ -58,12 +58,9 @@ function setUp() { $this->configImporter = new ConfigImporter( $storage_comparer->createChangelist(), $this->container->get('event_dispatcher'), - $this->container->get('config.factory'), - $this->container->get('entity.manager'), + $this->container->get('config.entity_manager'), $this->container->get('lock'), - $this->container->get('uuid'), - $this->container->get('config.typed'), - $this->container->get('module_handler') + $this->container->get('config.typed') ); $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.staging')); } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index b6df347..05136ed 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -1473,10 +1473,8 @@ public function configImporter() { $this->configImporter = new ConfigImporter( $storage_comparer, $this->container->get('event_dispatcher'), - $this->container->get('config.factory'), - $this->container->get('entity.manager'), + $this->container->get('config.entity_manager'), $this->container->get('lock'), - $this->container->get('uuid'), $this->container->get('config.typed') ); }