Mercurial > hg > isophonics-drupal-site
diff core/modules/field/src/Entity/FieldConfig.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 |
line wrap: on
line diff
--- a/core/modules/field/src/Entity/FieldConfig.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/modules/field/src/Entity/FieldConfig.php Mon Apr 23 09:46:53 2018 +0100 @@ -189,27 +189,26 @@ * {@inheritdoc} */ public static function preDelete(EntityStorageInterface $storage, array $fields) { - $state = \Drupal::state(); + /** @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository */ + $deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository'); $entity_type_manager = \Drupal::entityTypeManager(); parent::preDelete($storage, $fields); - // Keep the field definitions in the state storage so we can use them - // later during field_purge_batch(). - $deleted_fields = $state->get('field.field.deleted') ?: []; + // Keep the field definitions in the deleted fields repository so we can use + // them later during field_purge_batch(). /** @var \Drupal\field\FieldConfigInterface $field */ foreach ($fields as $field) { // Only mark a field for purging if there is data. Otherwise, just remove // it. $target_entity_storage = $entity_type_manager->getStorage($field->getTargetEntityTypeId()); if (!$field->deleted && $target_entity_storage instanceof FieldableEntityStorageInterface && $target_entity_storage->countFieldData($field->getFieldStorageDefinition(), TRUE)) { - $config = $field->toArray(); - $config['deleted'] = TRUE; - $config['field_storage_uuid'] = $field->getFieldStorageDefinition()->uuid(); - $deleted_fields[$field->uuid()] = $config; + $field = clone $field; + $field->deleted = TRUE; + $field->fieldStorage = NULL; + $deleted_fields_repository->addFieldDefinition($field); } } - $state->set('field.field.deleted', $deleted_fields); } /** @@ -288,14 +287,30 @@ */ public function getFieldStorageDefinition() { if (!$this->fieldStorage) { - $fields = $this->entityManager()->getFieldStorageDefinitions($this->entity_type); - if (!isset($fields[$this->field_name])) { + $field_storage_definition = NULL; + + $field_storage_definitions = $this->entityManager()->getFieldStorageDefinitions($this->entity_type); + if (isset($field_storage_definitions[$this->field_name])) { + $field_storage_definition = $field_storage_definitions[$this->field_name]; + } + // If this field has been deleted, try to find its field storage + // definition in the deleted fields repository. + elseif ($this->deleted) { + $deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')->getFieldStorageDefinitions(); + foreach ($deleted_storage_definitions as $deleted_storage_definition) { + if ($deleted_storage_definition->getName() === $this->field_name) { + $field_storage_definition = $deleted_storage_definition; + } + } + } + + if (!$field_storage_definition) { throw new FieldException("Attempt to create a field {$this->field_name} that does not exist on entity type {$this->entity_type}."); } - if (!$fields[$this->field_name] instanceof FieldStorageConfigInterface) { + if (!$field_storage_definition instanceof FieldStorageConfigInterface) { throw new FieldException("Attempt to create a configurable field of non-configurable field storage {$this->field_name}."); } - $this->fieldStorage = $fields[$this->field_name]; + $this->fieldStorage = $field_storage_definition; } return $this->fieldStorage; @@ -331,6 +346,13 @@ } /** + * {@inheritdoc} + */ + public function getUniqueIdentifier() { + return $this->uuid(); + } + + /** * Loads a field config entity based on the entity type and field name. * * @param string $entity_type_id