function FieldStorageConfig::preDelete

Same name in other branches
  1. 9 core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::preDelete()
  2. 10 core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::preDelete()
  3. 11.x core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::preDelete()

Overrides ConfigEntityBase::preDelete

File

core/modules/field/src/Entity/FieldStorageConfig.php, line 405

Class

FieldStorageConfig
Defines the Field storage configuration entity.

Namespace

Drupal\field\Entity

Code

public static function preDelete(EntityStorageInterface $storage, array $field_storages) {
    
    /** @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository */
    $deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository');
    // Set the static flag so that we don't delete field storages whilst
    // deleting fields.
    static::$inDeletion = TRUE;
    // Delete or fix any configuration that is dependent, for example, fields.
    parent::preDelete($storage, $field_storages);
    // Keep the field storage definitions in the deleted fields repository so we
    // can use them later during field_purge_batch().
    
    /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
    foreach ($field_storages as $field_storage) {
        // Only mark a field for purging if there is data. Otherwise, just remove
        // it.
        $target_entity_storage = \Drupal::entityTypeManager()->getStorage($field_storage->getTargetEntityTypeId());
        if (!$field_storage->deleted && $target_entity_storage instanceof FieldableEntityStorageInterface && $target_entity_storage->countFieldData($field_storage, TRUE)) {
            $storage_definition = clone $field_storage;
            $storage_definition->deleted = TRUE;
            $deleted_fields_repository->addFieldStorageDefinition($storage_definition);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.