Mercurial > hg > cmmr2012-drupal-site
comparison core/lib/Drupal/Core/Entity/EntityFieldManager.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 |
---|---|
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\Cache\UseCacheBackendTrait; | 7 use Drupal\Core\Cache\UseCacheBackendTrait; |
8 use Drupal\Core\Extension\ModuleHandlerInterface; | 8 use Drupal\Core\Extension\ModuleHandlerInterface; |
9 use Drupal\Core\Field\BaseFieldDefinition; | 9 use Drupal\Core\Field\BaseFieldDefinition; |
10 use Drupal\Core\Field\FieldDefinition; | |
10 use Drupal\Core\KeyValueStore\KeyValueFactoryInterface; | 11 use Drupal\Core\KeyValueStore\KeyValueFactoryInterface; |
11 use Drupal\Core\Language\LanguageManagerInterface; | 12 use Drupal\Core\Language\LanguageManagerInterface; |
12 use Drupal\Core\StringTranslation\StringTranslationTrait; | 13 use Drupal\Core\StringTranslation\StringTranslationTrait; |
13 use Drupal\Core\TypedData\TypedDataManagerInterface; | 14 use Drupal\Core\TypedData\TypedDataManagerInterface; |
14 | 15 |
51 * - $entity_type_id: \Drupal\Core\Field\BaseFieldDefinition[] | 52 * - $entity_type_id: \Drupal\Core\Field\BaseFieldDefinition[] |
52 * | 53 * |
53 * @var array | 54 * @var array |
54 */ | 55 */ |
55 protected $fieldStorageDefinitions; | 56 protected $fieldStorageDefinitions; |
57 | |
58 /** | |
59 * Static cache of active field storage definitions per entity type. | |
60 * | |
61 * @var array | |
62 */ | |
63 protected $activeFieldStorageDefinitions; | |
56 | 64 |
57 /** | 65 /** |
58 * An array keyed by entity type. Each value is an array whose keys are | 66 * An array keyed by entity type. Each value is an array whose keys are |
59 * field names and whose value is an array with two entries: | 67 * field names and whose value is an array with two entries: |
60 * - type: The field type. | 68 * - type: The field type. |
403 // for non-configurable fields. | 411 // for non-configurable fields. |
404 foreach ($bundle_field_definitions as $field_name => $field_definition) { | 412 foreach ($bundle_field_definitions as $field_name => $field_definition) { |
405 if ($field_definition instanceof BaseFieldDefinition) { | 413 if ($field_definition instanceof BaseFieldDefinition) { |
406 $field_definition->setName($field_name); | 414 $field_definition->setName($field_name); |
407 $field_definition->setTargetEntityTypeId($entity_type_id); | 415 $field_definition->setTargetEntityTypeId($entity_type_id); |
416 } | |
417 if ($field_definition instanceof BaseFieldDefinition || $field_definition instanceof FieldDefinition) { | |
408 $field_definition->setTargetBundle($bundle); | 418 $field_definition->setTargetBundle($bundle); |
409 } | 419 } |
410 } | 420 } |
411 | 421 |
412 // Invoke 'per bundle' alter hook. | 422 // Invoke 'per bundle' alter hook. |
438 $this->cacheSet($cid, $field_storage_definitions, Cache::PERMANENT, ['entity_types', 'entity_field_info']); | 448 $this->cacheSet($cid, $field_storage_definitions, Cache::PERMANENT, ['entity_types', 'entity_field_info']); |
439 } | 449 } |
440 $this->fieldStorageDefinitions[$entity_type_id] += $field_storage_definitions; | 450 $this->fieldStorageDefinitions[$entity_type_id] += $field_storage_definitions; |
441 } | 451 } |
442 return $this->fieldStorageDefinitions[$entity_type_id]; | 452 return $this->fieldStorageDefinitions[$entity_type_id]; |
453 } | |
454 | |
455 /** | |
456 * Gets the active field storage definitions for a content entity type. | |
457 * | |
458 * @param string $entity_type_id | |
459 * The entity type ID. Only content entities are supported. | |
460 * | |
461 * @return \Drupal\Core\Field\FieldStorageDefinitionInterface[] | |
462 * An array of field storage definitions that are active in the current | |
463 * request, keyed by field name. | |
464 * | |
465 * @internal | |
466 */ | |
467 public function getActiveFieldStorageDefinitions($entity_type_id) { | |
468 if (!isset($this->activeFieldStorageDefinitions[$entity_type_id])) { | |
469 $this->activeFieldStorageDefinitions[$entity_type_id] = $this->keyValueFactory->get('entity.definitions.installed')->get($entity_type_id . '.field_storage_definitions', []); | |
470 } | |
471 return $this->activeFieldStorageDefinitions[$entity_type_id] ?: $this->getFieldStorageDefinitions($entity_type_id); | |
443 } | 472 } |
444 | 473 |
445 /** | 474 /** |
446 * {@inheritdoc} | 475 * {@inheritdoc} |
447 */ | 476 */ |
564 */ | 593 */ |
565 public function clearCachedFieldDefinitions() { | 594 public function clearCachedFieldDefinitions() { |
566 $this->baseFieldDefinitions = []; | 595 $this->baseFieldDefinitions = []; |
567 $this->fieldDefinitions = []; | 596 $this->fieldDefinitions = []; |
568 $this->fieldStorageDefinitions = []; | 597 $this->fieldStorageDefinitions = []; |
598 $this->activeFieldStorageDefinitions = []; | |
569 $this->fieldMap = []; | 599 $this->fieldMap = []; |
570 $this->fieldMapByFieldType = []; | 600 $this->fieldMapByFieldType = []; |
571 $this->entityDisplayRepository->clearDisplayModeInfo(); | 601 $this->entityDisplayRepository->clearDisplayModeInfo(); |
572 $this->extraFields = []; | 602 $this->extraFields = []; |
573 Cache::invalidateTags(['entity_field_info']); | 603 Cache::invalidateTags(['entity_field_info']); |
583 $this->useCaches = $use_caches; | 613 $this->useCaches = $use_caches; |
584 if (!$use_caches) { | 614 if (!$use_caches) { |
585 $this->fieldDefinitions = []; | 615 $this->fieldDefinitions = []; |
586 $this->baseFieldDefinitions = []; | 616 $this->baseFieldDefinitions = []; |
587 $this->fieldStorageDefinitions = []; | 617 $this->fieldStorageDefinitions = []; |
618 $this->activeFieldStorageDefinitions = []; | |
588 } | 619 } |
589 } | 620 } |
590 | 621 |
591 /** | 622 /** |
592 * {@inheritdoc} | 623 * {@inheritdoc} |