diff --git a/core/core.services.yml b/core/core.services.yml index e9cb98770ab04ddc1cf3af0c6e5a14847daa0d08..b1fbd4f0ec668a311e5ba0925d402657060692c4 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.manager: + class: Drupal\Core\Config\ConfigManager + arguments: ['@entity.manager', '@config.factory', '@config.typed', '@string_translation'] 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.manager', '@event_dispatcher'] config.storage.staging: class: Drupal\Core\Config\FileStorage factory_class: Drupal\Core\Config\FileStorageFactory @@ -540,7 +543,7 @@ services: class: Drupal\Core\EventSubscriber\ConfigSnapshotSubscriber tags: - { name: event_subscriber } - arguments: ['@config.storage', '@config.storage.snapshot'] + arguments: ['@config.manager', '@config.storage', '@config.storage.snapshot'] exception_controller: class: Drupal\Core\Controller\ExceptionController arguments: ['@content_negotiation', '@string_translation', '@title_resolver', '@html_page_renderer', '@html_fragment_renderer'] diff --git a/core/includes/config.inc b/core/includes/config.inc index 8c3ded308fbe485b55be8d9438ab170ff4f24dec..9604ee5085514333cda626026ac5efb8f2f7b397 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -1,50 +1,18 @@ <?php -use Drupal\Component\Utility\Unicode; -use Drupal\Core\Config\Config; -use Drupal\Core\Config\ConfigException; -use Drupal\Core\Language\Language; -use Drupal\Core\Config\ExtensionInstallStorage; -use Drupal\Core\Config\FileStorage; -use Drupal\Core\Config\StorageInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Symfony\Component\Yaml\Dumper; -use Symfony\Component\EventDispatcher\EventDispatcher; - /** * @file * This is the API for configuration storage. */ -/** - * Uninstalls the default configuration of a given extension. - * - * @param string $type - * The extension type; e.g., 'module' or 'theme'. - * @param string $name - * The name of the module or theme to install default configuration for. - */ -function config_uninstall_default_config($type, $name) { - $storage = \Drupal::service('config.storage'); - $config_names = $storage->listAll($name . '.'); - foreach ($config_names as $config_name) { - \Drupal::config($config_name)->delete(); - } - $schema_dir = drupal_get_path($type, $name) . '/config/schema'; - if (is_dir($schema_dir)) { - // Refresh the schema cache if uninstalling an extension that provides - // configuration schema. - \Drupal::service('config.typed')->clearCachedDefinitions(); - } -} - /** * Gets configuration object names starting with a given prefix. * - * @see \Drupal\Core\Config\StorageInterface::listAll() + * @deprecated Deprecated since Drupal 8.x-dev, to be removed in Drupal 8.0. + * Use \Drupal::configFactory()->listAll() instead. */ function config_get_storage_names_with_prefix($prefix = '') { - return \Drupal::service('config.storage')->listAll($prefix); + return \Drupal::configFactory()->listAll($prefix); } /** @@ -54,7 +22,8 @@ function config_get_storage_names_with_prefix($prefix = '') { * @code \Drupal::config('book.admin') @endcode will return a configuration * object in which the book module can store its administrative settings. * - * @deprecated as of Drupal 8.0. Use \Drupal::config() instead. + * @deprecated Deprecated since Drupal 8.x-dev, to be removed in Drupal 8.0. + * Use \Drupal::config() instead. * * @param string $name * The name of the configuration object to retrieve. The name corresponds to @@ -69,27 +38,14 @@ function config($name) { return \Drupal::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_type) use ($name) { - return ($config_prefix = $entity_type->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. * + * @deprecated Deprecated since Drupal 8.x-dev, to be removed in Drupal 8.0. + * Use \Drupal::service('config.typed') instead. + * * @see \Drupal\Core\TypedData\TypedDataManager::create() * * @return \Drupal\Core\Config\TypedConfigManager @@ -98,57 +54,3 @@ function config_typed() { return \Drupal::service('config.typed'); } -/** - * Creates a configuration snapshot following a successful import. - * - * @param \Drupal\Core\Config\StorageInterface $source_storage - * The storage to synchronize configuration from. - * @param \Drupal\Core\Config\StorageInterface $snapshot_storage - * The storage to synchronize configuration to. - */ -function config_import_create_snapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage) { - $snapshot_storage->deleteAll(); - foreach ($source_storage->listAll() as $name) { - $snapshot_storage->write($name, $source_storage->read($name)); - } -} - -/** - * Return a formatted diff of a named config between two storages. - * - * @param \Drupal\Core\Config\StorageInterface $source_storage - * The storage to diff configuration from. - * @param \Drupal\Core\Config\StorageInterface $target_storage - * The storage to diff configuration to. - * @param string $name - * The name of the configuration object to diff. - * - * @return core/lib/Drupal/Component/Diff - * A formatted string showing the difference between the two storages. - * - * @todo Make renderer injectable - */ -function config_diff(StorageInterface $source_storage, StorageInterface $target_storage, $name) { - require_once DRUPAL_ROOT . '/core/lib/Drupal/Component/Diff/DiffEngine.php'; - - // The output should show configuration object differences formatted as YAML. - // But the configuration is not necessarily stored in files. Therefore, they - // need to be read and parsed, and lastly, dumped into YAML strings. - $dumper = new Dumper(); - $dumper->setIndentation(2); - - $source_data = explode("\n", $dumper->dump($source_storage->read($name), PHP_INT_MAX)); - $target_data = explode("\n", $dumper->dump($target_storage->read($name), PHP_INT_MAX)); - - // Check for new or removed files. - if ($source_data === array('false')) { - // Added file. - $source_data = array(t('File added')); - } - if ($target_data === array('false')) { - // Deleted file. - $target_data = array(t('File removed')); - } - - return new Diff($source_data, $target_data); -} diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 0b25e590a1e198abde87110680d0966a2ad96fa0..80e586c73768932f830b83efe34db1c1055a716e 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -2191,7 +2191,7 @@ function install_finished(&$install_state) { // Save a snapshot of the initially installed configuration. $active = \Drupal::service('config.storage'); $snapshot = \Drupal::service('config.storage.snapshot'); - config_import_create_snapshot($active, $snapshot); + \Drupal::service('config.manager')->createSnapshot($active, $snapshot); return $output; } diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index 7029d11f4d6560cf928fc034c48d5c17749bd1f2..8b74a70e9d68ce8cd198d8313771f1ba2eb88a76 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -345,6 +345,13 @@ public function getLanguageConfigName($langcode, $name) { return static::LANGUAGE_CONFIG_PREFIX . '.' . $langcode . '.' . $name; } + /** + * {@inheritdoc} + */ + public function listAll($prefix = '') { + return $this->storage->listAll($prefix); + } + /** * Determines if a particular configuration object can be overridden. * diff --git a/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php b/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php index c01d472cbb284bdc8f10cafba4d3f4cfbae568f3..663404776eb19a2acb68f2fc7816a29163d36037 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php +++ b/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php @@ -182,4 +182,18 @@ public function getLanguageConfigNames(array $names); */ public function getLanguageConfigName($langcode, $name); + /** + * Gets configuration object names starting with a given prefix. + * + * @see \Drupal\Core\Config\StorageInterface::listAll() + * + * @param string $prefix + * (optional) The prefix to search for. If omitted, all configuration object + * names that exist are returned. + * + * @return array + * An array containing matching configuration object names. + */ + public function listAll($prefix = ''); + } diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index e2354f473a276940c8997bbc99f547ec3ae9c210..92476b5f15f36dce436b3f32047ef21f25e98df1 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -7,10 +7,7 @@ namespace Drupal\Core\Config; -use Drupal\Core\Config\TypedConfigManager; -use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Lock\LockBackendInterface; -use Drupal\Component\Uuid\UuidInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -54,25 +51,25 @@ class ConfigImporter { protected $eventDispatcher; /** - * The configuration factory. + * The configuration manager. * - * @var \Drupal\Core\Config\ConfigFactory + * @var \Drupal\Core\Config\ConfigManagerInterface */ - protected $configFactory; + protected $configManager; /** - * 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(). @@ -88,20 +85,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. * @@ -110,24 +93,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\ConfigManagerInterface $config_manager + * The configuration manager. * @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, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManager $typed_config) { $this->storageComparer = $storage_comparer; $this->eventDispatcher = $event_dispatcher; - $this->configFactory = $config_factory; - $this->entityManager = $entity_manager; + $this->configManager = $config_manager; $this->lock = $lock; - $this->uuidService = $uuid_service; $this->typedConfigManager = $typed_config; $this->processed = $this->storageComparer->getEmptyChangelist(); } @@ -294,7 +271,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->configManager->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 +284,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->configManager->getEntityManager()->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 0be3354705b482fdade7e5dbfde20ba38614493f..39f8d8ab3843daeaf0b0993cfd7cd88fe6e3df6c 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Config; use Drupal\Component\Utility\Unicode; -use Drupal\Core\Entity\EntityManagerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; class ConfigInstaller implements ConfigInstallerInterface { @@ -35,11 +34,11 @@ class ConfigInstaller implements ConfigInstallerInterface { protected $typedConfig; /** - * The entity manager. + * The configuration manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Config\ConfigManagerInterface */ - protected $entityManager; + protected $configManager; /** * The event dispatcher. @@ -57,16 +56,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\ConfigManagerInterface $config_manager + * The configuration 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, ConfigManagerInterface $config_manager, EventDispatcherInterface $event_dispatcher) { $this->configFactory = $config_factory; $this->activeStorage = $active_storage; $this->typedConfig = $typed_config; - $this->entityManager = $entity_manager; + $this->configManager = $config_manager; $this->eventDispatcher = $event_dispatcher; } @@ -119,8 +118,9 @@ 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->configManager->getEntityTypeIdByName($name)) { + $this->configManager + ->getEntityManager() ->getStorageController($entity_type) ->create($new_config->get()) ->save(); diff --git a/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php new file mode 100644 index 0000000000000000000000000000000000000000..65a78461862ab598885b30b2975e7491adf81150 --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigManager.php @@ -0,0 +1,138 @@ +<?php + +/** + * @file + * Contains \Drupal\Core\Config\ConfigManager. + */ + +namespace Drupal\Core\Config; + +use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\StringTranslation\TranslationManager; +use Symfony\Component\Yaml\Dumper; + +/** + * The ConfigManager provides helper functions for the configuration system. + */ +class ConfigManager implements ConfigManagerInterface { + + /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + + /** + * The configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $configFactory; + + /** + * The typed config manager. + * + * @var \Drupal\Core\Config\TypedConfigManager + */ + protected $typedConfigManager; + + /** + * The string translation service. + * + * @var \Drupal\Core\StringTranslation\TranslationManager + */ + protected $stringTranslation; + + /** + * Creates ConfigManager objects. + * + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The entity manager. + */ + public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, TypedConfigManager $typed_config_manager, TranslationManager $string_translation) { + $this->entityManager = $entity_manager; + $this->configFactory = $config_factory; + $this->typedConfigManager = $typed_config_manager; + $this->stringTranslation = $string_translation; + } + + /** + * {@inheritdoc} + */ + public function getEntityTypeIdByName($name) { + $entities = array_filter($this->entityManager->getDefinitions(), function (EntityTypeInterface $entity_type) use ($name) { + return ($config_prefix = $entity_type->getConfigPrefix()) && strpos($name, $config_prefix . '.') === 0; + }); + return key($entities); + } + + /** + * {@inheritdoc} + */ + public function getEntityManager() { + return $this->entityManager; + } + + /** + * {@inheritdoc} + */ + public function diff(StorageInterface $source_storage, StorageInterface $target_storage, $name) { + // @todo Replace with code that can be autoloaded. + // https://drupal.org/node/2188595 + require_once DRUPAL_ROOT . '/core/lib/Drupal/Component/Diff/DiffEngine.php'; + + // The output should show configuration object differences formatted as YAML. + // But the configuration is not necessarily stored in files. Therefore, they + // need to be read and parsed, and lastly, dumped into YAML strings. + $dumper = new Dumper(); + $dumper->setIndentation(2); + + $source_data = explode("\n", $dumper->dump($source_storage->read($name), PHP_INT_MAX)); + $target_data = explode("\n", $dumper->dump($target_storage->read($name), PHP_INT_MAX)); + + // Check for new or removed files. + if ($source_data === array('false')) { + // Added file. + $source_data = array($this->stringTranslation->translate('File added')); + } + if ($target_data === array('false')) { + // Deleted file. + $target_data = array($this->stringTranslation->translate('File removed')); + } + + return new \Diff($source_data, $target_data); + } + + /** + * {@inheritdoc} + */ + function createSnapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage) { + $snapshot_storage->deleteAll(); + foreach ($source_storage->listAll() as $name) { + $snapshot_storage->write($name, $source_storage->read($name)); + } + } + + /** + * Uninstalls the default configuration of a given extension. + * + * @param string $type + * The extension type; e.g., 'module' or 'theme'. + * @param string $name + * The name of the module or theme to install default configuration for. + */ + function uninstall($type, $name) { + $config_names = $this->configFactory->listAll($name . '.'); + foreach ($config_names as $config_name) { + $this->configFactory->get($config_name)->delete(); + } + $schema_dir = drupal_get_path($type, $name) . '/config/schema'; + if (is_dir($schema_dir)) { + // Refresh the schema cache if uninstalling an extension that provides + // configuration schema. + $this->typedConfigManager->clearCachedDefinitions(); + } + } +} diff --git a/core/lib/Drupal/Core/Config/ConfigManagerInterface.php b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..e63108d9b5dafa75fa1d9691b70d60b61ac1619f --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php @@ -0,0 +1,71 @@ +<?php + +/** + * @file + * Contains \Drupal\Core\Config\ConfigManagerInterface. + */ + +namespace Drupal\Core\Config; + +/** + * Provides an interface for configuration manager. + */ +interface ConfigManagerInterface { + + /** + * 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); + + /** + * Gets the entity manager. + * + * @return \Drupal\Core\Entity\EntityManagerInterface + * The entity manager. + */ + public function getEntityManager(); + + /** + * Return a formatted diff of a named config between two storages. + * + * @param \Drupal\Core\Config\StorageInterface $source_storage + * The storage to diff configuration from. + * @param \Drupal\Core\Config\StorageInterface $target_storage + * The storage to diff configuration to. + * @param string $name + * The name of the configuration object to diff. + * + * @return core/lib/Drupal/Component/Diff + * A formatted string showing the difference between the two storages. + * + * @todo Make renderer injectable + */ + public function diff(StorageInterface $source_storage, StorageInterface $target_storage, $name); + + /** + * Creates a configuration snapshot following a successful import. + * + * @param \Drupal\Core\Config\StorageInterface $source_storage + * The storage to synchronize configuration from. + * @param \Drupal\Core\Config\StorageInterface $snapshot_storage + * The storage to synchronize configuration to. + */ + public function createSnapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage); + + /** + * Uninstalls the configuration of a given extension. + * + * @param string $type + * The extension type; e.g., 'module' or 'theme'. + * @param string $name + * The name of the module or theme to install configuration for. + */ + public function uninstall($type, $name); + +} diff --git a/core/lib/Drupal/Core/EventSubscriber/ConfigSnapshotSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ConfigSnapshotSubscriber.php index 54c60dc1ba49215061d65911b644b42a3c0edc10..656eb2d0591c6fa293b434c8351e8d1d239da4d3 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ConfigSnapshotSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ConfigSnapshotSubscriber.php @@ -8,6 +8,7 @@ namespace Drupal\Core\EventSubscriber; use Drupal\Core\Config\Config; +use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\ConfigImporterEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -17,6 +18,13 @@ */ class ConfigSnapshotSubscriber implements EventSubscriberInterface { + /** + * The configuration manager. + * + * @var \Drupal\Core\Config\ConfigManagerInterface + */ + protected $configManager; + /** * The source storage used to discover configuration changes. * @@ -39,7 +47,8 @@ class ConfigSnapshotSubscriber implements EventSubscriberInterface { * @param StorageInterface $snapshot_storage * The snapshot storage used to write configuration changes. */ - public function __construct(StorageInterface $source_storage, StorageInterface $snapshot_storage) { + public function __construct(ConfigManagerInterface $config_manager, StorageInterface $source_storage, StorageInterface $snapshot_storage) { + $this->configManager = $config_manager; $this->sourceStorage = $source_storage; $this->snapshotStorage = $snapshot_storage; } @@ -51,7 +60,7 @@ public function __construct(StorageInterface $source_storage, StorageInterface $ * The Event to process. */ public function onConfigImporterImport(ConfigImporterEvent $event) { - config_import_create_snapshot($this->sourceStorage, $this->snapshotStorage); + $this->configManager->createSnapshot($this->sourceStorage, $this->snapshotStorage); } /** diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index ef7b5e74fce58819dac4ac21f5dc9ea4d07a6422..001e27813a8d65377519f5aff18abe6004e2b5ba 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -730,7 +730,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { $module_config->clear("enabled.$module")->save(); // Remove all configuration belonging to the module. - config_uninstall_default_config('module', $module); + \Drupal::service('config.manager')->uninstall('module', $module); // Update the module handler to remove the module. // The current ModuleHandler instance is obsolete with the kernel rebuild diff --git a/core/modules/config/lib/Drupal/config/Controller/ConfigController.php b/core/modules/config/lib/Drupal/config/Controller/ConfigController.php index a1e8510d730482120065611cf001ebd94f5b0f9c..ee5cd4aad69645c804d413a1f52c89e35976ea77 100644 --- a/core/modules/config/lib/Drupal/config/Controller/ConfigController.php +++ b/core/modules/config/lib/Drupal/config/Controller/ConfigController.php @@ -8,6 +8,7 @@ namespace Drupal\config\Controller; use Drupal\Component\Archiver\ArchiveTar; +use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\system\FileDownloadController; @@ -33,6 +34,13 @@ class ConfigController implements ContainerInjectionInterface { */ protected $sourceStorage; + /** + * The configuration manager. + * + * @var \Drupal\Core\Config\ConfigManagerInterface + */ + protected $configManager; + /** * The file download controller. * @@ -47,6 +55,7 @@ public static function create(ContainerInterface $container) { return new static( $container->get('config.storage'), $container->get('config.storage.staging'), + $container->get('config.manager'), new FileDownloadController() ); } @@ -61,9 +70,10 @@ public static function create(ContainerInterface $container) { * @param \Drupal\system\FileDownloadController $file_download_controller * The file download controller. */ - public function __construct(StorageInterface $target_storage, StorageInterface $source_storage, FileDownloadController $file_download_controller) { + public function __construct(StorageInterface $target_storage, StorageInterface $source_storage, ConfigManagerInterface $config_manager, FileDownloadController $file_download_controller) { $this->targetStorage = $target_storage; $this->sourceStorage = $source_storage; + $this->configManager = $config_manager; $this->fileDownloadController = $file_download_controller; } @@ -94,7 +104,7 @@ public function downloadExport() { */ public function diff($config_file) { - $diff = config_diff($this->targetStorage, $this->sourceStorage, $config_file); + $diff = $this->configManager->diff($this->targetStorage, $this->sourceStorage, $config_file); $formatter = new \DrupalDiffFormatter(); $formatter->show_header = FALSE; diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSync.php b/core/modules/config/lib/Drupal/config/Form/ConfigSync.php index 8e95d7e069721d11a7b9f5403f7c10dcc0b02a0a..e13eb3f5e5d17e126ca9454713731fee5ad356d1 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSync.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSync.php @@ -7,15 +7,13 @@ namespace Drupal\config\Form; -use Drupal\Component\Uuid\UuidInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Config\StorageComparer; use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\ConfigException; -use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\TypedConfigManager; use Drupal\Core\Routing\UrlGeneratorInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -55,9 +53,11 @@ class ConfigSync extends FormBase { protected $eventDispatcher; /** - * @var \Drupal\Core\Entity\EntityManagerInterface; + * The configuration manager. + * + * @var \Drupal\Core\Config\ConfigManagerInterface; */ - protected $entity_manager; + protected $configManager; /** * URL generator service. @@ -66,13 +66,6 @@ class ConfigSync extends FormBase { */ protected $urlGenerator; - /** - * The UUID service. - * - * @var \Drupal\Component\Uuid\UuidInterface - */ - protected $uuidService; - /** * The typed config manager. * @@ -91,26 +84,20 @@ class ConfigSync extends FormBase { * The lock object. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * Event dispatcher. - * @param \Drupal\Core\Config\ConfigFactory $config_factory - * The config factory. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * Entity manager. + * @param \Drupal\Core\Config\ConfigManager + * Configuration manager. * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * The url generator service. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_service - * The UUID Service. * @param \Drupal\Core\Config\TypedConfigManager $typed_config * The typed configuration manager. */ - public function __construct(StorageInterface $sourceStorage, StorageInterface $targetStorage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigFactory $config_factory, EntityManagerInterface $entity_manager, UrlGeneratorInterface $url_generator, UuidInterface $uuid_service, TypedConfigManager $typed_config) { + public function __construct(StorageInterface $sourceStorage, StorageInterface $targetStorage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, UrlGeneratorInterface $url_generator, TypedConfigManager $typed_config) { $this->sourceStorage = $sourceStorage; $this->targetStorage = $targetStorage; $this->lock = $lock; $this->eventDispatcher = $event_dispatcher; - $this->configFactory = $config_factory; - $this->entity_manager = $entity_manager; + $this->configManager = $config_manager; $this->urlGenerator = $url_generator; - $this->uuidService = $uuid_service; $this->typedConfigManager = $typed_config; } @@ -123,10 +110,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.manager'), $container->get('url_generator'), - $container->get('uuid'), $container->get('config.typed') ); } @@ -236,10 +221,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->configManager, $this->lock, - $this->uuidService, $this->typedConfigManager ); if ($config_importer->alreadyImporting()) { diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigDiffTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigDiffTest.php index 5ffe66222e07f8cae1aff13522d06931ef40d4ed..57e05532afba1734ca4c2b8092cc260ec76dd7cf 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigDiffTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigDiffTest.php @@ -56,7 +56,7 @@ function testDiff() { $staging->write($config_name, $staging_data); // Verify that the diff reflects a change. - $diff = config_diff($active, $staging, $config_name); + $diff = \Drupal::service('config.manager')->diff($active, $staging, $config_name); $this->assertEqual($diff->edits[0]->type, 'change', 'The first item in the diff is a change.'); $this->assertEqual($diff->edits[0]->orig[0], $change_key . ': ' . $original_data[$change_key], format_string("The active value for key '%change_key' is '%original_data'.", array('%change_key' => $change_key, '%original_data' => $original_data[$change_key]))); $this->assertEqual($diff->edits[0]->closing[0], $change_key . ': ' . $change_data, format_string("The staging value for key '%change_key' is '%change_data'.", array('%change_key' => $change_key, '%change_data' => $change_data))); @@ -67,7 +67,7 @@ function testDiff() { $staging->write($config_name, $staging_data); // Verify that the diff reflects a removed key. - $diff = config_diff($active, $staging, $config_name); + $diff = \Drupal::service('config.manager')->diff($active, $staging, $config_name); $this->assertEqual($diff->edits[0]->type, 'copy', 'The first item in the diff is a copy.'); $this->assertEqual($diff->edits[1]->type, 'delete', 'The second item in the diff is a delete.'); $this->assertEqual($diff->edits[1]->orig[0], $remove_key . ': ' . $original_data[$remove_key], format_string("The active value for key '%remove_key' is '%original_data'.", array('%remove_key' => $remove_key, '%original_data' => $original_data[$remove_key]))); @@ -79,7 +79,7 @@ function testDiff() { $staging->write($config_name, $staging_data); // Verify that the diff reflects an added key. - $diff = config_diff($active, $staging, $config_name); + $diff = \Drupal::service('config.manager')->diff($active, $staging, $config_name); $this->assertEqual($diff->edits[0]->type, 'copy', 'The first item in the diff is a copy.'); $this->assertEqual($diff->edits[1]->type, 'add', 'The second item in the diff is an add.'); $this->assertFalse($diff->edits[1]->orig, format_string("The key '%add_key' does not exist in active.", array('%add_key' => $add_key))); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php index ec445c584a6ca7a306c11f2134d706c25419cf68..f23cdcb182e29dc3c263718b4d895f4c7049a99d 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.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/config/lib/Drupal/config/Tests/ConfigInstallTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php index bd2eab5eab30fe5263a97e8fa5ed7051dec6302c..7188744fbec7d9dd701c8011e065d9743a117097 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php @@ -76,7 +76,7 @@ function testModuleInstallation() { // Test that uninstalling configuration removes configuration schema. \Drupal::config('system.module')->set('enabled', array())->save(); - config_uninstall_default_config('module', 'config_test'); + \Drupal::service('config.manager')->uninstall('module', 'config_test'); $this->assertFalse(\Drupal::service('config.typed')->hasConfigSchema('config_test.schema_in_install'), 'Configuration schema for config_test.schema_in_install does not exist.'); } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php index c277ac69bacde6fc56302ce2bbaa1130bd7f6518..d8e7187de92770b130e0a9523a8ff1d55f170ea1 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php @@ -35,7 +35,7 @@ public function setUp() { $this->installSchema('system', 'config_snapshot'); // Update the config snapshot. This allows the parent::setUp() to write // configuration files. - config_import_create_snapshot(\Drupal::service('config.storage'), \Drupal::service('config.storage.snapshot')); + \Drupal::service('config.manager')->createSnapshot(\Drupal::service('config.storage'), \Drupal::service('config.storage.snapshot')); } /** @@ -62,7 +62,7 @@ function testSnapshot() { $this->assertTrue($active_snapshot_comparer->reset()->hasChanges()); // Update the config snapshot. - config_import_create_snapshot($active, $snapshot); + \Drupal::service('config.manager')->createSnapshot($active, $snapshot); // The snapshot and active config should now contain the same config // objects. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index b6df34700810310e73e26c74c1d2c94ba90283c1..61e04d23fb4ecd5d8a640d2e4b3e55d8e5f687d0 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.manager'), $this->container->get('lock'), - $this->container->get('uuid'), $this->container->get('config.typed') ); }