comparison core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.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
1 <?php 1 <?php
2 2
3 namespace Drupal\Core\Entity; 3 namespace Drupal\Core\Entity;
4 4
5 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
5 use Drupal\Core\Entity\Schema\DynamicallyFieldableEntityStorageSchemaInterface; 6 use Drupal\Core\Entity\Schema\DynamicallyFieldableEntityStorageSchemaInterface;
6 use Drupal\Core\Entity\Schema\EntityStorageSchemaInterface; 7 use Drupal\Core\Entity\Schema\EntityStorageSchemaInterface;
7 use Drupal\Core\Field\BaseFieldDefinition; 8 use Drupal\Core\Field\BaseFieldDefinition;
8 use Drupal\Core\Field\FieldStorageDefinitionInterface; 9 use Drupal\Core\Field\FieldStorageDefinitionInterface;
10 use Drupal\Core\Field\FieldStorageDefinitionListenerInterface;
9 use Drupal\Core\StringTranslation\StringTranslationTrait; 11 use Drupal\Core\StringTranslation\StringTranslationTrait;
10 12
11 /** 13 /**
12 * Manages entity definition updates. 14 * Manages entity definition updates.
13 */ 15 */
14 class EntityDefinitionUpdateManager implements EntityDefinitionUpdateManagerInterface { 16 class EntityDefinitionUpdateManager implements EntityDefinitionUpdateManagerInterface {
15 use StringTranslationTrait; 17 use StringTranslationTrait;
16 18 use DeprecatedServicePropertyTrait;
17 /** 19
18 * The entity manager service. 20 /**
19 * 21 * {@inheritdoc}
20 * @var \Drupal\Core\Entity\EntityManagerInterface 22 */
21 */ 23 protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
22 protected $entityManager; 24
25 /**
26 * The entity field manager service.
27 *
28 * @var \Drupal\Core\Entity\EntityFieldManagerInterface
29 */
30 protected $entityFieldManager;
31
32 /**
33 * The entity type listener service.
34 *
35 * @var \Drupal\Core\Entity\EntityTypeListenerInterface
36 */
37 protected $entityTypeListener;
38
39 /**
40 * The entity type manager service.
41 *
42 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
43 */
44 protected $entityTypeManager;
45
46 /**
47 * The field storage definition listener service.
48 *
49 * @var \Drupal\Core\Field\FieldStorageDefinitionListenerInterface
50 */
51 protected $fieldStorageDefinitionListener;
23 52
24 /** 53 /**
25 * The last installed schema repository. 54 * The last installed schema repository.
26 * 55 *
27 * @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface 56 * @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
29 protected $entityLastInstalledSchemaRepository; 58 protected $entityLastInstalledSchemaRepository;
30 59
31 /** 60 /**
32 * Constructs a new EntityDefinitionUpdateManager. 61 * Constructs a new EntityDefinitionUpdateManager.
33 * 62 *
34 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager 63 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
35 * The entity manager. 64 * The entity type manager service.
36 * @param \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository 65 * @param \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository
37 * The last installed schema repository service. 66 * The last installed schema repository service.
38 */ 67 * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
39 public function __construct(EntityManagerInterface $entity_manager, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository = NULL) { 68 * The entity field manager service.
40 $this->entityManager = $entity_manager; 69 * @param \Drupal\Core\Entity\EntityTypeListenerInterface $entity_type_listener
41 70 * The entity type listener interface.
42 if (!isset($entity_last_installed_schema_repository)) { 71 * @param \Drupal\Core\Field\FieldStorageDefinitionListenerInterface $field_storage_definition_listener
43 @trigger_error('The $entity_last_installed_schema_repository parameter was added in Drupal 8.6.x and will be required in 9.0.0. See https://www.drupal.org/node/2973262.', E_USER_DEPRECATED); 72 * The field storage definition listener service.
44 $entity_last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository'); 73 */
45 } 74 public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository = NULL, EntityFieldManagerInterface $entity_field_manager = NULL, EntityTypeListenerInterface $entity_type_listener = NULL, FieldStorageDefinitionListenerInterface $field_storage_definition_listener = NULL) {
46 $this->entityLastInstalledSchemaRepository = $entity_last_installed_schema_repository; 75 if ($entity_type_manager instanceof EntityManagerInterface) {
76 @trigger_error('Passing the entity.manager service to EntityDefinitionUpdateManager::__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);
77 $this->entityTypeManager = \Drupal::entityTypeManager();
78 }
79 else {
80 $this->entityTypeManager = $entity_type_manager;
81 }
82
83 if ($entity_last_installed_schema_repository) {
84 $this->entityLastInstalledSchemaRepository = $entity_last_installed_schema_repository;
85 }
86 else {
87 @trigger_error('The entity.last_installed_schema.repository service must be passed to EntityDefinitionUpdateManager::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
88 $this->entityLastInstalledSchemaRepository = \Drupal::service('entity.last_installed_schema.repository');
89 }
90
91 if ($entity_field_manager) {
92 $this->entityFieldManager = $entity_field_manager;
93 }
94 else {
95 @trigger_error('The entity_field.manager service must be passed to EntityDefinitionUpdateManager::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
96 $this->entityFieldManager = \Drupal::service('entity_field.manager');
97 }
98
99 if ($entity_type_listener) {
100 $this->entityTypeListener = $entity_type_listener;
101 }
102 else {
103 @trigger_error('The entity_type.listener service must be passed to EntityDefinitionUpdateManager::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
104 $this->entityTypeListener = \Drupal::service('entity_type.listener');
105 }
106
107 if ($field_storage_definition_listener) {
108 $this->fieldStorageDefinitionListener = $field_storage_definition_listener;
109 }
110 else {
111 @trigger_error('The field_storage_definition.listener service must be passed to EntityDefinitionUpdateManager::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
112 $this->fieldStorageDefinitionListener = \Drupal::service('field_storage_definition.listener');
113 }
47 } 114 }
48 115
49 /** 116 /**
50 * {@inheritdoc} 117 * {@inheritdoc}
51 */ 118 */
60 $summary = []; 127 $summary = [];
61 128
62 foreach ($this->getChangeList() as $entity_type_id => $change_list) { 129 foreach ($this->getChangeList() as $entity_type_id => $change_list) {
63 // Process entity type definition changes. 130 // Process entity type definition changes.
64 if (!empty($change_list['entity_type'])) { 131 if (!empty($change_list['entity_type'])) {
65 $entity_type = $this->entityManager->getDefinition($entity_type_id); 132 $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
66 133
67 switch ($change_list['entity_type']) { 134 switch ($change_list['entity_type']) {
68 case static::DEFINITION_CREATED: 135 case static::DEFINITION_CREATED:
69 $summary[$entity_type_id][] = $this->t('The %entity_type entity type needs to be installed.', ['%entity_type' => $entity_type->getLabel()]); 136 $summary[$entity_type_id][] = $this->t('The %entity_type entity type needs to be installed.', ['%entity_type' => $entity_type->getLabel()]);
70 break; 137 break;
75 } 142 }
76 } 143 }
77 144
78 // Process field storage definition changes. 145 // Process field storage definition changes.
79 if (!empty($change_list['field_storage_definitions'])) { 146 if (!empty($change_list['field_storage_definitions'])) {
80 $storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id); 147 $storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id);
81 $original_storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type_id); 148 $original_storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type_id);
82 149
83 foreach ($change_list['field_storage_definitions'] as $field_name => $change) { 150 foreach ($change_list['field_storage_definitions'] as $field_name => $change) {
84 switch ($change) { 151 switch ($change) {
85 case static::DEFINITION_CREATED: 152 case static::DEFINITION_CREATED:
103 170
104 /** 171 /**
105 * {@inheritdoc} 172 * {@inheritdoc}
106 */ 173 */
107 public function applyUpdates() { 174 public function applyUpdates() {
108 $complete_change_list = $this->getChangeList(); 175 trigger_error('EntityDefinitionUpdateManagerInterface::applyUpdates() is deprecated in 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::getChangeList() and execute each entity type and field storage update manually instead. See https://www.drupal.org/node/3034742.', E_USER_DEPRECATED);
109 if ($complete_change_list) {
110 // self::getChangeList() only disables the cache and does not invalidate.
111 // In case there are changes, explicitly invalidate caches.
112 $this->entityManager->clearCachedDefinitions();
113 }
114 foreach ($complete_change_list as $entity_type_id => $change_list) {
115 // Process entity type definition changes before storage definitions ones
116 // this is necessary when you change an entity type from non-revisionable
117 // to revisionable and at the same time add revisionable fields to the
118 // entity type.
119 if (!empty($change_list['entity_type'])) {
120 $this->doEntityUpdate($change_list['entity_type'], $entity_type_id);
121 }
122
123 // Process field storage definition changes.
124 if (!empty($change_list['field_storage_definitions'])) {
125 $storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id);
126 $original_storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type_id);
127
128 foreach ($change_list['field_storage_definitions'] as $field_name => $change) {
129 $storage_definition = isset($storage_definitions[$field_name]) ? $storage_definitions[$field_name] : NULL;
130 $original_storage_definition = isset($original_storage_definitions[$field_name]) ? $original_storage_definitions[$field_name] : NULL;
131 $this->doFieldUpdate($change, $storage_definition, $original_storage_definition);
132 }
133 }
134 }
135 } 176 }
136 177
137 /** 178 /**
138 * {@inheritdoc} 179 * {@inheritdoc}
139 */ 180 */
151 192
152 /** 193 /**
153 * {@inheritdoc} 194 * {@inheritdoc}
154 */ 195 */
155 public function installEntityType(EntityTypeInterface $entity_type) { 196 public function installEntityType(EntityTypeInterface $entity_type) {
156 $this->entityManager->clearCachedDefinitions(); 197 $this->clearCachedDefinitions();
157 $this->entityManager->onEntityTypeCreate($entity_type); 198 $this->entityTypeListener->onEntityTypeCreate($entity_type);
158 } 199 }
159 200
160 /** 201 /**
161 * {@inheritdoc} 202 * {@inheritdoc}
162 */ 203 */
163 public function updateEntityType(EntityTypeInterface $entity_type) { 204 public function updateEntityType(EntityTypeInterface $entity_type) {
164 $original = $this->getEntityType($entity_type->id()); 205 $original = $this->getEntityType($entity_type->id());
165 $this->entityManager->clearCachedDefinitions(); 206 $this->clearCachedDefinitions();
166 $this->entityManager->onEntityTypeUpdate($entity_type, $original); 207 $this->entityTypeListener->onEntityTypeUpdate($entity_type, $original);
167 } 208 }
168 209
169 /** 210 /**
170 * {@inheritdoc} 211 * {@inheritdoc}
171 */ 212 */
172 public function uninstallEntityType(EntityTypeInterface $entity_type) { 213 public function uninstallEntityType(EntityTypeInterface $entity_type) {
173 $this->entityManager->clearCachedDefinitions(); 214 $this->clearCachedDefinitions();
174 $this->entityManager->onEntityTypeDelete($entity_type); 215 $this->entityTypeListener->onEntityTypeDelete($entity_type);
216 }
217
218 /**
219 * {@inheritdoc}
220 */
221 public function updateFieldableEntityType(EntityTypeInterface $entity_type, array $field_storage_definitions, array &$sandbox = NULL) {
222 $original = $this->getEntityType($entity_type->id());
223
224 if ($this->requiresEntityDataMigration($entity_type, $original) && $sandbox === NULL) {
225 throw new \InvalidArgumentException('The entity schema update for the ' . $entity_type->id() . ' entity type requires a data migration.');
226 }
227
228 $original_field_storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type->id());
229 $this->entityTypeListener->onFieldableEntityTypeUpdate($entity_type, $original, $field_storage_definitions, $original_field_storage_definitions, $sandbox);
230 $this->clearCachedDefinitions();
175 } 231 }
176 232
177 /** 233 /**
178 * {@inheritdoc} 234 * {@inheritdoc}
179 */ 235 */
185 ->setName($name) 241 ->setName($name)
186 ->setTargetEntityTypeId($entity_type_id) 242 ->setTargetEntityTypeId($entity_type_id)
187 ->setProvider($provider) 243 ->setProvider($provider)
188 ->setTargetBundle(NULL); 244 ->setTargetBundle(NULL);
189 } 245 }
190 $this->entityManager->clearCachedDefinitions(); 246 $this->clearCachedDefinitions();
191 $this->entityManager->onFieldStorageDefinitionCreate($storage_definition); 247 $this->fieldStorageDefinitionListener->onFieldStorageDefinitionCreate($storage_definition);
192 } 248 }
193 249
194 /** 250 /**
195 * {@inheritdoc} 251 * {@inheritdoc}
196 */ 252 */
202 /** 258 /**
203 * {@inheritdoc} 259 * {@inheritdoc}
204 */ 260 */
205 public function updateFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition) { 261 public function updateFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition) {
206 $original = $this->getFieldStorageDefinition($storage_definition->getName(), $storage_definition->getTargetEntityTypeId()); 262 $original = $this->getFieldStorageDefinition($storage_definition->getName(), $storage_definition->getTargetEntityTypeId());
207 $this->entityManager->clearCachedDefinitions(); 263 $this->clearCachedDefinitions();
208 $this->entityManager->onFieldStorageDefinitionUpdate($storage_definition, $original); 264 $this->fieldStorageDefinitionListener->onFieldStorageDefinitionUpdate($storage_definition, $original);
209 } 265 }
210 266
211 /** 267 /**
212 * {@inheritdoc} 268 * {@inheritdoc}
213 */ 269 */
214 public function uninstallFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition) { 270 public function uninstallFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition) {
215 $this->entityManager->clearCachedDefinitions(); 271 $this->clearCachedDefinitions();
216 $this->entityManager->onFieldStorageDefinitionDelete($storage_definition); 272 $this->fieldStorageDefinitionListener->onFieldStorageDefinitionDelete($storage_definition);
217 } 273 }
218 274
219 /** 275 /**
220 * Performs an entity type definition update. 276 * {@inheritdoc}
221 * 277 */
222 * @param string $op 278 public function getChangeList() {
223 * The operation to perform, either static::DEFINITION_CREATED or 279 $this->entityTypeManager->useCaches(FALSE);
224 * static::DEFINITION_UPDATED. 280 $this->entityFieldManager->useCaches(FALSE);
225 * @param string $entity_type_id
226 * The entity type ID.
227 */
228 protected function doEntityUpdate($op, $entity_type_id) {
229 $entity_type = $this->entityManager->getDefinition($entity_type_id);
230 switch ($op) {
231 case static::DEFINITION_CREATED:
232 $this->entityManager->onEntityTypeCreate($entity_type);
233 break;
234
235 case static::DEFINITION_UPDATED:
236 $original = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id);
237 $this->entityManager->onEntityTypeUpdate($entity_type, $original);
238 break;
239 }
240 }
241
242 /**
243 * Performs a field storage definition update.
244 *
245 * @param string $op
246 * The operation to perform, possible values are static::DEFINITION_CREATED,
247 * static::DEFINITION_UPDATED or static::DEFINITION_DELETED.
248 * @param array|null $storage_definition
249 * The new field storage definition.
250 * @param array|null $original_storage_definition
251 * The original field storage definition.
252 */
253 protected function doFieldUpdate($op, $storage_definition = NULL, $original_storage_definition = NULL) {
254 switch ($op) {
255 case static::DEFINITION_CREATED:
256 $this->entityManager->onFieldStorageDefinitionCreate($storage_definition);
257 break;
258
259 case static::DEFINITION_UPDATED:
260 $this->entityManager->onFieldStorageDefinitionUpdate($storage_definition, $original_storage_definition);
261 break;
262
263 case static::DEFINITION_DELETED:
264 $this->entityManager->onFieldStorageDefinitionDelete($original_storage_definition);
265 break;
266 }
267 }
268
269 /**
270 * Gets a list of changes to entity type and field storage definitions.
271 *
272 * @return array
273 * An associative array keyed by entity type id of change descriptors. Every
274 * entry is an associative array with the following optional keys:
275 * - entity_type: a scalar having only the DEFINITION_UPDATED value.
276 * - field_storage_definitions: an associative array keyed by field name of
277 * scalars having one value among:
278 * - DEFINITION_CREATED
279 * - DEFINITION_UPDATED
280 * - DEFINITION_DELETED
281 */
282 protected function getChangeList() {
283 $this->entityManager->useCaches(FALSE);
284 $change_list = []; 281 $change_list = [];
285 282
286 foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { 283 foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
287 $original = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id); 284 $original = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id);
288 285
289 // @todo Support non-storage-schema-changing definition updates too: 286 // @todo Support non-storage-schema-changing definition updates too:
290 // https://www.drupal.org/node/2336895. 287 // https://www.drupal.org/node/2336895.
291 if (!$original) { 288 if (!$original) {
294 else { 291 else {
295 if ($this->requiresEntityStorageSchemaChanges($entity_type, $original)) { 292 if ($this->requiresEntityStorageSchemaChanges($entity_type, $original)) {
296 $change_list[$entity_type_id]['entity_type'] = static::DEFINITION_UPDATED; 293 $change_list[$entity_type_id]['entity_type'] = static::DEFINITION_UPDATED;
297 } 294 }
298 295
299 if ($this->entityManager->getStorage($entity_type_id) instanceof DynamicallyFieldableEntityStorageInterface) { 296 if ($this->entityTypeManager->getStorage($entity_type_id) instanceof DynamicallyFieldableEntityStorageInterface) {
300 $field_changes = []; 297 $field_changes = [];
301 $storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id); 298 $storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id);
302 $original_storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type_id); 299 $original_storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type_id);
303 300
304 // Detect created field storage definitions. 301 // Detect created field storage definitions.
305 foreach (array_diff_key($storage_definitions, $original_storage_definitions) as $field_name => $storage_definition) { 302 foreach (array_diff_key($storage_definitions, $original_storage_definitions) as $field_name => $storage_definition) {
306 $field_changes[$field_name] = static::DEFINITION_CREATED; 303 $field_changes[$field_name] = static::DEFINITION_CREATED;
334 331
335 // @todo Support deleting entity definitions when we support base field 332 // @todo Support deleting entity definitions when we support base field
336 // purging. 333 // purging.
337 // @see https://www.drupal.org/node/2907779 334 // @see https://www.drupal.org/node/2907779
338 335
339 $this->entityManager->useCaches(TRUE); 336 $this->entityTypeManager->useCaches(TRUE);
337 $this->entityFieldManager->useCaches(TRUE);
340 338
341 return array_filter($change_list); 339 return array_filter($change_list);
342 } 340 }
343 341
344 /** 342 /**
351 * 349 *
352 * @return bool 350 * @return bool
353 * TRUE if storage schema changes are required, FALSE otherwise. 351 * TRUE if storage schema changes are required, FALSE otherwise.
354 */ 352 */
355 protected function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) { 353 protected function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
356 $storage = $this->entityManager->getStorage($entity_type->id()); 354 $storage = $this->entityTypeManager->getStorage($entity_type->id());
357 return ($storage instanceof EntityStorageSchemaInterface) && $storage->requiresEntityStorageSchemaChanges($entity_type, $original); 355 return ($storage instanceof EntityStorageSchemaInterface) && $storage->requiresEntityStorageSchemaChanges($entity_type, $original);
358 } 356 }
359 357
360 /** 358 /**
361 * Checks if the changes to the storage definition requires schema changes. 359 * Checks if the changes to the storage definition requires schema changes.
367 * 365 *
368 * @return bool 366 * @return bool
369 * TRUE if storage schema changes are required, FALSE otherwise. 367 * TRUE if storage schema changes are required, FALSE otherwise.
370 */ 368 */
371 protected function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { 369 protected function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
372 $storage = $this->entityManager->getStorage($storage_definition->getTargetEntityTypeId()); 370 $storage = $this->entityTypeManager->getStorage($storage_definition->getTargetEntityTypeId());
373 return ($storage instanceof DynamicallyFieldableEntityStorageSchemaInterface) && $storage->requiresFieldStorageSchemaChanges($storage_definition, $original); 371 return ($storage instanceof DynamicallyFieldableEntityStorageSchemaInterface) && $storage->requiresFieldStorageSchemaChanges($storage_definition, $original);
374 } 372 }
375 373
374 /**
375 * Checks if existing data would be lost if the schema changes were applied.
376 *
377 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
378 * The updated entity type definition.
379 * @param \Drupal\Core\Entity\EntityTypeInterface $original
380 * The original entity type definition.
381 *
382 * @return bool
383 * TRUE if data migration is required, FALSE otherwise.
384 */
385 protected function requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
386 $storage = $this->entityTypeManager->getStorage($entity_type->id());
387 return ($storage instanceof EntityStorageSchemaInterface) && $storage->requiresEntityDataMigration($entity_type, $original);
388 }
389
390 /**
391 * Clears necessary caches to apply entity/field definition updates.
392 */
393 protected function clearCachedDefinitions() {
394 $this->entityTypeManager->clearCachedDefinitions();
395 $this->entityFieldManager->clearCachedFieldDefinitions();
396 }
397
376 } 398 }