comparison core/modules/field/src/FieldStorageConfigStorage.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
5 use Drupal\Component\Uuid\UuidInterface; 5 use Drupal\Component\Uuid\UuidInterface;
6 use Drupal\Core\Config\Entity\ConfigEntityStorage; 6 use Drupal\Core\Config\Entity\ConfigEntityStorage;
7 use Drupal\Core\Entity\EntityInterface; 7 use Drupal\Core\Entity\EntityInterface;
8 use Drupal\Core\Entity\EntityManagerInterface; 8 use Drupal\Core\Entity\EntityManagerInterface;
9 use Drupal\Core\Entity\EntityTypeInterface; 9 use Drupal\Core\Entity\EntityTypeInterface;
10 use Drupal\Core\Field\DeletedFieldsRepositoryInterface;
10 use Drupal\Core\Field\FieldTypePluginManagerInterface; 11 use Drupal\Core\Field\FieldTypePluginManagerInterface;
11 use Drupal\Core\Language\LanguageManagerInterface; 12 use Drupal\Core\Language\LanguageManagerInterface;
12 use Symfony\Component\DependencyInjection\ContainerInterface; 13 use Symfony\Component\DependencyInjection\ContainerInterface;
13 use Drupal\Core\Config\ConfigFactoryInterface; 14 use Drupal\Core\Config\ConfigFactoryInterface;
14 use Drupal\Core\Extension\ModuleHandlerInterface; 15 use Drupal\Core\Extension\ModuleHandlerInterface;
15 use Drupal\Core\State\StateInterface;
16 16
17 /** 17 /**
18 * Controller class for "field storage" configuration entities. 18 * Storage handler for "field storage" configuration entities.
19 */ 19 */
20 class FieldStorageConfigStorage extends ConfigEntityStorage { 20 class FieldStorageConfigStorage extends ConfigEntityStorage {
21 21
22 /** 22 /**
23 * The module handler. 23 * The module handler.
32 * @var \Drupal\Core\Entity\EntityManagerInterface 32 * @var \Drupal\Core\Entity\EntityManagerInterface
33 */ 33 */
34 protected $entityManager; 34 protected $entityManager;
35 35
36 /** 36 /**
37 * The state keyvalue collection.
38 *
39 * @var \Drupal\Core\State\StateInterface
40 */
41 protected $state;
42
43 /**
44 * The field type plugin manager. 37 * The field type plugin manager.
45 * 38 *
46 * @var \Drupal\Core\Field\FieldTypePluginManagerInterface 39 * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
47 */ 40 */
48 protected $fieldTypeManager; 41 protected $fieldTypeManager;
42
43 /**
44 * The deleted fields repository.
45 *
46 * @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface
47 */
48 protected $deletedFieldsRepository;
49 49
50 /** 50 /**
51 * Constructs a FieldStorageConfigStorage object. 51 * Constructs a FieldStorageConfigStorage object.
52 * 52 *
53 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type 53 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
60 * The language manager. 60 * The language manager.
61 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager 61 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
62 * The entity manager. 62 * The entity manager.
63 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler 63 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
64 * The module handler. 64 * The module handler.
65 * @param \Drupal\Core\State\StateInterface $state 65 * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
66 * The state key value store.
67 * @param \Drupal\Component\Plugin\PluginManagerInterface\FieldTypePluginManagerInterface $field_type_manager
68 * The field type plugin manager. 66 * The field type plugin manager.
67 * @param \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository
68 * The deleted fields repository.
69 */ 69 */
70 public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, StateInterface $state, FieldTypePluginManagerInterface $field_type_manager) { 70 public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository) {
71 parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); 71 parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager);
72 $this->entityManager = $entity_manager; 72 $this->entityManager = $entity_manager;
73 $this->moduleHandler = $module_handler; 73 $this->moduleHandler = $module_handler;
74 $this->state = $state;
75 $this->fieldTypeManager = $field_type_manager; 74 $this->fieldTypeManager = $field_type_manager;
75 $this->deletedFieldsRepository = $deleted_fields_repository;
76 } 76 }
77 77
78 /** 78 /**
79 * {@inheritdoc} 79 * {@inheritdoc}
80 */ 80 */
84 $container->get('config.factory'), 84 $container->get('config.factory'),
85 $container->get('uuid'), 85 $container->get('uuid'),
86 $container->get('language_manager'), 86 $container->get('language_manager'),
87 $container->get('entity.manager'), 87 $container->get('entity.manager'),
88 $container->get('module_handler'), 88 $container->get('module_handler'),
89 $container->get('state'), 89 $container->get('plugin.manager.field.field_type'),
90 $container->get('plugin.manager.field.field_type') 90 $container->get('entity_field.deleted_fields_repository')
91 ); 91 );
92 } 92 }
93 93
94 /** 94 /**
95 * {@inheritdoc} 95 * {@inheritdoc}
102 /** @var \Drupal\field\FieldStorageConfigInterface[] $storages */ 102 /** @var \Drupal\field\FieldStorageConfigInterface[] $storages */
103 $storages = []; 103 $storages = [];
104 104
105 // Get field storages living in configuration. If we are explicitly looking 105 // Get field storages living in configuration. If we are explicitly looking
106 // for deleted storages only, this can be skipped, because they will be 106 // for deleted storages 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['field_name'])) { 109 if (isset($conditions['entity_type']) && 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['field_name']; 111 $id = $conditions['entity_type'] . $conditions['field_name'];
112 $storages = $this->loadMultiple([$id]); 112 $storages = $this->loadMultiple([$id]);
115 // No specific ID, we need to examine all existing storages. 115 // No specific ID, we need to examine all existing storages.
116 $storages = $this->loadMultiple(); 116 $storages = $this->loadMultiple();
117 } 117 }
118 } 118 }
119 119
120 // Merge deleted field storages (living in state) if needed. 120 // Merge deleted field storage definitions from the deleted fields
121 // repository if needed.
121 if ($include_deleted || !empty($conditions['deleted'])) { 122 if ($include_deleted || !empty($conditions['deleted'])) {
122 $deleted_storages = $this->state->get('field.storage.deleted') ?: []; 123 $deleted_storage_definitions = $this->deletedFieldsRepository->getFieldStorageDefinitions();
123 foreach ($deleted_storages as $id => $config) { 124 foreach ($deleted_storage_definitions as $id => $field_storage_definition) {
124 $storages[$id] = $this->create($config); 125 if ($field_storage_definition instanceof FieldStorageConfigInterface) {
126 $storages[$id] = $field_storage_definition;
127 }
125 } 128 }
126 } 129 }
127 130
128 // Collect matching fields. 131 // Collect matching fields.
129 $matches = []; 132 $matches = [];