comparison core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\Core\ParamConverter; 3 namespace Drupal\Core\ParamConverter;
4 4
5 use Drupal\Core\Config\ConfigFactoryInterface;
5 use Drupal\Core\Config\Entity\ConfigEntityInterface; 6 use Drupal\Core\Config\Entity\ConfigEntityInterface;
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
6 use Drupal\Core\Routing\AdminContext; 8 use Drupal\Core\Routing\AdminContext;
7 use Symfony\Component\Routing\Route; 9 use Symfony\Component\Routing\Route;
8 use Drupal\Core\Config\ConfigFactoryInterface;
9 use Drupal\Core\Entity\EntityManagerInterface;
10 10
11 /** 11 /**
12 * Makes sure the unmodified ConfigEntity is loaded on admin pages. 12 * Makes sure the unmodified ConfigEntity is loaded on admin pages.
13 * 13 *
14 * Converts entity route arguments to unmodified entities as opposed to 14 * Converts entity route arguments to unmodified entities as opposed to
40 protected $adminContext; 40 protected $adminContext;
41 41
42 /** 42 /**
43 * Constructs a new EntityConverter. 43 * Constructs a new EntityConverter.
44 * 44 *
45 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager 45 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
46 * The entity manager. 46 * The entity type manager.
47 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory 47 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
48 * The config factory. 48 * The config factory.
49 * @param \Drupal\Core\Routing\AdminContext $admin_context 49 * @param \Drupal\Core\Routing\AdminContext $admin_context
50 * The route admin context service. 50 * The route admin context service.
51 * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
52 * The entity repository.
51 */ 53 */
52 public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, AdminContext $admin_context) { 54 public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, AdminContext $admin_context, $entity_repository = NULL) {
53 parent::__construct($entity_manager); 55 parent::__construct($entity_type_manager, $entity_repository);
54 56
55 $this->configFactory = $config_factory; 57 $this->configFactory = $config_factory;
56 $this->adminContext = $admin_context; 58 $this->adminContext = $admin_context;
57 } 59 }
58 60
63 $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); 65 $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults);
64 66
65 // If the entity type is dynamic, confirm it to be a config entity. Static 67 // If the entity type is dynamic, confirm it to be a config entity. Static
66 // entity types will have performed this check in self::applies(). 68 // entity types will have performed this check in self::applies().
67 if (strpos($definition['type'], 'entity:{') === 0) { 69 if (strpos($definition['type'], 'entity:{') === 0) {
68 $entity_type = $this->entityManager->getDefinition($entity_type_id); 70 $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
69 if (!$entity_type->entityClassImplements(ConfigEntityInterface::class)) { 71 if (!$entity_type->entityClassImplements(ConfigEntityInterface::class)) {
70 return parent::convert($value, $definition, $name, $defaults); 72 return parent::convert($value, $definition, $name, $defaults);
71 } 73 }
72 } 74 }
73 75
74 if ($storage = $this->entityManager->getStorage($entity_type_id)) { 76 if ($storage = $this->entityTypeManager->getStorage($entity_type_id)) {
75 // Make sure no overrides are loaded. 77 // Make sure no overrides are loaded.
76 return $storage->loadOverrideFree($value); 78 return $storage->loadOverrideFree($value);
77 } 79 }
78 } 80 }
79 81
91 if (strpos($entity_type_id, '{') === 0) { 93 if (strpos($entity_type_id, '{') === 0) {
92 return TRUE; 94 return TRUE;
93 } 95 }
94 // As we only want to override EntityConverter for ConfigEntities, find 96 // As we only want to override EntityConverter for ConfigEntities, find
95 // out whether the current entity is a ConfigEntity. 97 // out whether the current entity is a ConfigEntity.
96 $entity_type = $this->entityManager->getDefinition($entity_type_id); 98 $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
97 if ($entity_type->entityClassImplements(ConfigEntityInterface::class)) { 99 if ($entity_type->entityClassImplements(ConfigEntityInterface::class)) {
98 return $this->adminContext->isAdminRoute($route); 100 return $this->adminContext->isAdminRoute($route);
99 } 101 }
100 } 102 }
101 return FALSE; 103 return FALSE;