comparison core/modules/field/src/FieldConfigStorage.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
3 namespace Drupal\field; 3 namespace Drupal\field;
4 4
5 use Drupal\Core\Config\Config; 5 use Drupal\Core\Config\Config;
6 use Drupal\Core\Entity\EntityManagerInterface; 6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\Entity\EntityTypeInterface; 7 use Drupal\Core\Entity\EntityTypeInterface;
8 use Drupal\Core\Field\DeletedFieldsRepositoryInterface;
8 use Drupal\Core\Field\FieldConfigStorageBase; 9 use Drupal\Core\Field\FieldConfigStorageBase;
9 use Drupal\Core\Field\FieldTypePluginManagerInterface; 10 use Drupal\Core\Field\FieldTypePluginManagerInterface;
10 use Drupal\Core\Language\LanguageManagerInterface; 11 use Drupal\Core\Language\LanguageManagerInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface; 12 use Symfony\Component\DependencyInjection\ContainerInterface;
12 use Drupal\Core\Config\ConfigFactoryInterface; 13 use Drupal\Core\Config\ConfigFactoryInterface;
13 use Drupal\Component\Uuid\UuidInterface; 14 use Drupal\Component\Uuid\UuidInterface;
14 use Drupal\Core\State\StateInterface;
15 15
16 /** 16 /**
17 * Controller class for fields. 17 * Storage handler for field config.
18 */ 18 */
19 class FieldConfigStorage extends FieldConfigStorageBase { 19 class FieldConfigStorage extends FieldConfigStorageBase {
20 20
21 /** 21 /**
22 * The entity manager. 22 * The entity manager.
24 * @var \Drupal\Core\Entity\EntityManagerInterface 24 * @var \Drupal\Core\Entity\EntityManagerInterface
25 */ 25 */
26 protected $entityManager; 26 protected $entityManager;
27 27
28 /** 28 /**
29 * The state keyvalue collection.
30 *
31 * @var \Drupal\Core\State\StateInterface
32 */
33 protected $state;
34
35 /**
36 * The field type plugin manager. 29 * The field type plugin manager.
37 * 30 *
38 * @var \Drupal\Core\Field\FieldTypePluginManagerInterface 31 * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
39 */ 32 */
40 protected $fieldTypeManager; 33 protected $fieldTypeManager;
34
35 /**
36 * The deleted fields repository.
37 *
38 * @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface
39 */
40 protected $deletedFieldsRepository;
41 41
42 /** 42 /**
43 * Constructs a FieldConfigStorage object. 43 * Constructs a FieldConfigStorage object.
44 * 44 *
45 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type 45 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
50 * The UUID service. 50 * The UUID service.
51 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager 51 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
52 * The language manager. 52 * The language manager.
53 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager 53 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
54 * The entity manager. 54 * The entity manager.
55 * @param \Drupal\Core\State\StateInterface $state
56 * The state key value store.
57 * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager 55 * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
58 * The field type plugin manager. 56 * The field type plugin manager.
57 * @param \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository
58 * The deleted fields repository.
59 */ 59 */
60 public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, StateInterface $state, FieldTypePluginManagerInterface $field_type_manager) { 60 public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository) {
61 parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); 61 parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager);
62 $this->entityManager = $entity_manager; 62 $this->entityManager = $entity_manager;
63 $this->state = $state;
64 $this->fieldTypeManager = $field_type_manager; 63 $this->fieldTypeManager = $field_type_manager;
64 $this->deletedFieldsRepository = $deleted_fields_repository;
65 } 65 }
66 66
67 /** 67 /**
68 * {@inheritdoc} 68 * {@inheritdoc}
69 */ 69 */
72 $entity_type, 72 $entity_type,
73 $container->get('config.factory'), 73 $container->get('config.factory'),
74 $container->get('uuid'), 74 $container->get('uuid'),
75 $container->get('language_manager'), 75 $container->get('language_manager'),
76 $container->get('entity.manager'), 76 $container->get('entity.manager'),
77 $container->get('state'), 77 $container->get('plugin.manager.field.field_type'),
78 $container->get('plugin.manager.field.field_type') 78 $container->get('entity_field.deleted_fields_repository')
79 ); 79 );
80 } 80 }
81 81
82 /** 82 /**
83 * {@inheritdoc} 83 * {@inheritdoc}
102 102
103 $fields = []; 103 $fields = [];
104 104
105 // Get fields stored in configuration. If we are explicitly looking for 105 // Get fields stored in configuration. If we are explicitly looking for
106 // deleted fields only, this can be skipped, because they will be 106 // deleted fields only, this can be skipped, because they will be
107 // retrieved from state below. 107 // retrieved from the deleted fields repository below.
108 if (empty($conditions['deleted'])) { 108 if (empty($conditions['deleted'])) {
109 if (isset($conditions['entity_type']) && isset($conditions['bundle']) && isset($conditions['field_name'])) { 109 if (isset($conditions['entity_type']) && isset($conditions['bundle']) && isset($conditions['field_name'])) {
110 // Optimize for the most frequent case where we do have a specific ID. 110 // Optimize for the most frequent case where we do have a specific ID.
111 $id = $conditions['entity_type'] . '.' . $conditions['bundle'] . '.' . $conditions['field_name']; 111 $id = $conditions['entity_type'] . '.' . $conditions['bundle'] . '.' . $conditions['field_name'];
112 $fields = $this->loadMultiple([$id]); 112 $fields = $this->loadMultiple([$id]);
115 // No specific ID, we need to examine all existing fields. 115 // No specific ID, we need to examine all existing fields.
116 $fields = $this->loadMultiple(); 116 $fields = $this->loadMultiple();
117 } 117 }
118 } 118 }
119 119
120 // Merge deleted fields (stored in state) if needed. 120 // Merge deleted fields from the deleted fields repository if needed.
121 if ($include_deleted || !empty($conditions['deleted'])) { 121 if ($include_deleted || !empty($conditions['deleted'])) {
122 $deleted_fields = $this->state->get('field.field.deleted') ?: []; 122 $deleted_field_definitions = $this->deletedFieldsRepository->getFieldDefinitions();
123 $deleted_storages = $this->state->get('field.storage.deleted') ?: []; 123 foreach ($deleted_field_definitions as $id => $field_definition) {
124 foreach ($deleted_fields as $id => $config) { 124 if ($field_definition instanceof FieldConfigInterface) {
125 // If the field storage itself is deleted, inject it directly in the field. 125 $fields[$id] = $field_definition;
126 if (isset($deleted_storages[$config['field_storage_uuid']])) {
127 $config['field_storage'] = $this->entityManager->getStorage('field_storage_config')->create($deleted_storages[$config['field_storage_uuid']]);
128 } 126 }
129 $fields[$id] = $this->create($config);
130 } 127 }
131 } 128 }
132 129
133 // Collect matching fields. 130 // Collect matching fields.
134 $matching_fields = []; 131 $matching_fields = [];