Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/Config/ConfigManager.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 7a779792577d |
children |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Config/ConfigManager.php Thu Feb 28 13:21:36 2019 +0000 +++ b/core/lib/Drupal/Core/Config/ConfigManager.php Thu May 09 15:33:08 2019 +0100 @@ -6,8 +6,11 @@ use Drupal\Core\Config\Entity\ConfigDependencyManager; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Serialization\Yaml; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; @@ -18,13 +21,27 @@ */ class ConfigManager implements ConfigManagerInterface { use StringTranslationTrait; + use DeprecatedServicePropertyTrait; + use StorageCopyTrait; /** - * The entity manager. + * {@inheritdoc} + */ + protected $deprecatedProperties = ['entityManager' => 'entity.manager']; + + /** + * The entity type manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; + + /** + * The entity repository. + * + * @var \Drupal\Core\Entity\EntityRepositoryInterface + */ + protected $entityRepository; /** * The configuration factory. @@ -71,8 +88,8 @@ /** * Creates ConfigManager objects. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The configuration factory. * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager @@ -83,21 +100,36 @@ * The active configuration storage. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * The event dispatcher. + * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository + * The entity repository. */ - public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config_manager, TranslationInterface $string_translation, StorageInterface $active_storage, EventDispatcherInterface $event_dispatcher) { - $this->entityManager = $entity_manager; + public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config_manager, TranslationInterface $string_translation, StorageInterface $active_storage, EventDispatcherInterface $event_dispatcher, EntityRepositoryInterface $entity_repository = NULL) { + if ($entity_type_manager instanceof EntityManagerInterface) { + @trigger_error('Passing the entity.manager service to ConfigManager::__construct() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Pass the new dependencies instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED); + $this->entityTypeManager = \Drupal::entityTypeManager(); + } + else { + $this->entityTypeManager = $entity_type_manager; + } $this->configFactory = $config_factory; $this->typedConfigManager = $typed_config_manager; $this->stringTranslation = $string_translation; $this->activeStorage = $active_storage; $this->eventDispatcher = $event_dispatcher; + if ($entity_repository) { + $this->entityRepository = $entity_repository; + } + else { + @trigger_error('The entity.repository service must be passed to ConfigManager::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED); + $this->entityRepository = \Drupal::service('entity.repository'); + } } /** * {@inheritdoc} */ public function getEntityTypeIdByName($name) { - $entities = array_filter($this->entityManager->getDefinitions(), function (EntityTypeInterface $entity_type) use ($name) { + $entities = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $entity_type) use ($name) { return ($entity_type instanceof ConfigEntityTypeInterface && $config_prefix = $entity_type->getConfigPrefix()) && strpos($name, $config_prefix . '.') === 0; }); return key($entities); @@ -109,9 +141,9 @@ public function loadConfigEntityByName($name) { $entity_type_id = $this->getEntityTypeIdByName($name); if ($entity_type_id) { - $entity_type = $this->entityManager->getDefinition($entity_type_id); + $entity_type = $this->entityTypeManager->getDefinition($entity_type_id); $id = substr($name, strlen($entity_type->getConfigPrefix()) + 1); - return $this->entityManager->getStorage($entity_type_id)->load($id); + return $this->entityTypeManager->getStorage($entity_type_id)->load($id); } return NULL; } @@ -120,7 +152,15 @@ * {@inheritdoc} */ public function getEntityManager() { - return $this->entityManager; + @trigger_error('ConfigManagerInterface::getEntityManager() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use ::getEntityTypeManager() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED); + return \Drupal::service('entity.manager'); + } + + /** + * {@inheritdoc} + */ + public function getEntityTypeManager() { + return $this->entityTypeManager; } /** @@ -168,23 +208,7 @@ * {@inheritdoc} */ public function createSnapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage) { - // Empty the snapshot of all configuration. - $snapshot_storage->deleteAll(); - foreach ($snapshot_storage->getAllCollectionNames() as $collection) { - $snapshot_collection = $snapshot_storage->createCollection($collection); - $snapshot_collection->deleteAll(); - } - foreach ($source_storage->listAll() as $name) { - $snapshot_storage->write($name, $source_storage->read($name)); - } - // Copy collections as well. - foreach ($source_storage->getAllCollectionNames() as $collection) { - $source_collection = $source_storage->createCollection($collection); - $snapshot_collection = $snapshot_storage->createCollection($collection); - foreach ($source_collection->listAll() as $name) { - $snapshot_collection->write($name, $source_collection->read($name)); - } - } + self::replaceStorageContents($source_storage, $snapshot_storage); } /** @@ -264,7 +288,7 @@ public function findConfigEntityDependentsAsEntities($type, array $names, ConfigDependencyManager $dependency_manager = NULL) { $dependencies = $this->findConfigEntityDependents($type, $names, $dependency_manager); $entities = []; - $definitions = $this->entityManager->getDefinitions(); + $definitions = $this->entityTypeManager->getDefinitions(); foreach ($dependencies as $config_name => $dependency) { // Group by entity type to efficient load entities using // \Drupal\Core\Entity\EntityStorageInterface::loadMultiple(). @@ -280,7 +304,7 @@ } $entities_to_return = []; foreach ($entities as $entity_type_id => $entities_to_load) { - $storage = $this->entityManager->getStorage($entity_type_id); + $storage = $this->entityTypeManager->getStorage($entity_type_id); // Remove the keys since there are potential ID clashes from different // configuration entity types. $entities_to_return = array_merge($entities_to_return, array_values($storage->loadMultiple($entities_to_load))); @@ -440,7 +464,7 @@ else { // Ignore the bundle. list($entity_type_id,, $uuid) = explode(':', $name); - return $this->entityManager->loadEntityByConfigTarget($entity_type_id, $uuid); + return $this->entityRepository->loadEntityByConfigTarget($entity_type_id, $uuid); } }, $affected_dependencies[$type]); } @@ -487,7 +511,7 @@ foreach (array_unique($content_dependencies) as $content_dependency) { // Format of the dependency is entity_type:bundle:uuid. list($entity_type, $bundle, $uuid) = explode(':', $content_dependency, 3); - if (!$this->entityManager->loadEntityByUuid($entity_type, $uuid)) { + if (!$this->entityRepository->loadEntityByUuid($entity_type, $uuid)) { $missing_dependencies[$uuid] = [ 'entity_type' => $entity_type, 'bundle' => $bundle,