Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/hal/src/LinkManager/RelationLinkManager.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
3 namespace Drupal\hal\LinkManager; | 3 namespace Drupal\hal\LinkManager; |
4 | 4 |
5 use Drupal\Core\Cache\Cache; | 5 use Drupal\Core\Cache\Cache; |
6 use Drupal\Core\Cache\CacheBackendInterface; | 6 use Drupal\Core\Cache\CacheBackendInterface; |
7 use Drupal\Core\Config\ConfigFactoryInterface; | 7 use Drupal\Core\Config\ConfigFactoryInterface; |
8 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; | |
8 use Drupal\Core\Entity\ContentEntityTypeInterface; | 9 use Drupal\Core\Entity\ContentEntityTypeInterface; |
9 use Drupal\Core\Entity\EntityManagerInterface; | 10 use Drupal\Core\Entity\EntityFieldManagerInterface; |
11 use Drupal\Core\Entity\EntityTypeBundleInfoInterface; | |
12 use Drupal\Core\Entity\EntityTypeManagerInterface; | |
10 use Drupal\Core\Extension\ModuleHandlerInterface; | 13 use Drupal\Core\Extension\ModuleHandlerInterface; |
11 use Symfony\Component\HttpFoundation\RequestStack; | 14 use Symfony\Component\HttpFoundation\RequestStack; |
12 | 15 |
13 class RelationLinkManager extends LinkManagerBase implements RelationLinkManagerInterface { | 16 class RelationLinkManager extends LinkManagerBase implements RelationLinkManagerInterface { |
17 use DeprecatedServicePropertyTrait; | |
18 | |
19 /** | |
20 * {@inheritdoc} | |
21 */ | |
22 protected $deprecatedProperties = ['entityManager' => 'entity.manager']; | |
14 | 23 |
15 /** | 24 /** |
16 * @var \Drupal\Core\Cache\CacheBackendInterface | 25 * @var \Drupal\Core\Cache\CacheBackendInterface |
17 */ | 26 */ |
18 protected $cache; | 27 protected $cache; |
19 | 28 |
20 /** | 29 /** |
21 * Entity manager. | 30 * The entity field manager. |
22 * | 31 * |
23 * @var \Drupal\Core\Entity\EntityManagerInterface | 32 * @var \Drupal\Core\Entity\EntityFieldManagerInterface |
24 */ | 33 */ |
25 protected $entityManager; | 34 protected $entityFieldManager; |
35 | |
36 /** | |
37 * The entity bundle info. | |
38 * | |
39 * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface | |
40 */ | |
41 protected $entityTypeBundleInfo; | |
42 | |
43 /** | |
44 * The entity type manager. | |
45 * | |
46 * @var \Drupal\Core\Entity\EntityTypeManagerInterface | |
47 */ | |
48 protected $entityTypeManager; | |
26 | 49 |
27 /** | 50 /** |
28 * Module handler service. | 51 * Module handler service. |
29 * | 52 * |
30 * @var \Drupal\Core\Extension\ModuleHandlerInterface | 53 * @var \Drupal\Core\Extension\ModuleHandlerInterface |
34 /** | 57 /** |
35 * Constructor. | 58 * Constructor. |
36 * | 59 * |
37 * @param \Drupal\Core\Cache\CacheBackendInterface $cache | 60 * @param \Drupal\Core\Cache\CacheBackendInterface $cache |
38 * The cache of relation URIs and their associated Typed Data IDs. | 61 * The cache of relation URIs and their associated Typed Data IDs. |
39 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager | 62 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
40 * The entity manager. | 63 * The entity type manager. |
41 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler | 64 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler |
42 * The module handler service. | 65 * The module handler service. |
43 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory | 66 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory |
44 * The config factory service. | 67 * The config factory service. |
45 * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack | 68 * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack |
46 * The request stack. | 69 * The request stack. |
47 */ | 70 * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info |
48 public function __construct(CacheBackendInterface $cache, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, RequestStack $request_stack) { | 71 * The entity type bundle info. |
72 * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager | |
73 * The entity field manager. | |
74 */ | |
75 public function __construct(CacheBackendInterface $cache, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, RequestStack $request_stack, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, EntityFieldManagerInterface $entity_field_manager = NULL) { | |
49 $this->cache = $cache; | 76 $this->cache = $cache; |
50 $this->entityManager = $entity_manager; | 77 $this->entityTypeManager = $entity_type_manager; |
78 if (!$entity_type_bundle_info) { | |
79 @trigger_error('The entity_type.bundle.info service must be passed to RelationLinkManager::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED); | |
80 $entity_type_bundle_info = \Drupal::service('entity_type.bundle.info'); | |
81 } | |
82 $this->entityTypeBundleInfo = $entity_type_bundle_info; | |
83 if (!$entity_field_manager) { | |
84 @trigger_error('The entity_field.manager service must be passed to RelationLinkManager::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED); | |
85 $entity_field_manager = \Drupal::service('entity_field.manager'); | |
86 } | |
87 $this->entityFieldManager = $entity_field_manager; | |
51 $this->configFactory = $config_factory; | 88 $this->configFactory = $config_factory; |
52 $this->moduleHandler = $module_handler; | 89 $this->moduleHandler = $module_handler; |
53 $this->requestStack = $request_stack; | 90 $this->requestStack = $request_stack; |
54 } | 91 } |
55 | 92 |
121 $data = $cache->data; | 158 $data = $cache->data; |
122 } | 159 } |
123 | 160 |
124 // @todo https://www.drupal.org/node/2716163 Remove this in Drupal 9.0. | 161 // @todo https://www.drupal.org/node/2716163 Remove this in Drupal 9.0. |
125 foreach ($data as $relation_uri => $ids) { | 162 foreach ($data as $relation_uri => $ids) { |
126 $data[$relation_uri]['entity_type'] = $this->entityManager->getDefinition($ids['entity_type_id']); | 163 $data[$relation_uri]['entity_type'] = $this->entityTypeManager->getDefinition($ids['entity_type_id']); |
127 } | 164 } |
128 return $data; | 165 return $data; |
129 } | 166 } |
130 | 167 |
131 /** | 168 /** |
143 * The values for 'entity_type_id', 'bundle' and 'field_name' are strings. | 180 * The values for 'entity_type_id', 'bundle' and 'field_name' are strings. |
144 */ | 181 */ |
145 protected function writeCache($context = []) { | 182 protected function writeCache($context = []) { |
146 $data = []; | 183 $data = []; |
147 | 184 |
148 foreach ($this->entityManager->getDefinitions() as $entity_type) { | 185 foreach ($this->entityTypeManager->getDefinitions() as $entity_type) { |
149 if ($entity_type instanceof ContentEntityTypeInterface) { | 186 if ($entity_type instanceof ContentEntityTypeInterface) { |
150 foreach ($this->entityManager->getBundleInfo($entity_type->id()) as $bundle => $bundle_info) { | 187 foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()) as $bundle => $bundle_info) { |
151 foreach ($this->entityManager->getFieldDefinitions($entity_type->id(), $bundle) as $field_definition) { | 188 foreach ($this->entityFieldManager->getFieldDefinitions($entity_type->id(), $bundle) as $field_definition) { |
152 $relation_uri = $this->getRelationUri($entity_type->id(), $bundle, $field_definition->getName(), $context); | 189 $relation_uri = $this->getRelationUri($entity_type->id(), $bundle, $field_definition->getName(), $context); |
153 $data[$relation_uri] = [ | 190 $data[$relation_uri] = [ |
154 'entity_type_id' => $entity_type->id(), | 191 'entity_type_id' => $entity_type->id(), |
155 'bundle' => $bundle, | 192 'bundle' => $bundle, |
156 'field_name' => $field_definition->getName(), | 193 'field_name' => $field_definition->getName(), |