You are here

public static function FieldConfig::preDelete in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Entity/FieldConfig.php \Drupal\field\Entity\FieldConfig::preDelete()

Acts on entities before they are deleted and before hooks are invoked.

Used before the entities are deleted and before invoking the delete hook.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.

Overrides ConfigEntityBase::preDelete

File

core/modules/field/src/Entity/FieldConfig.php, line 195
Contains \Drupal\field\Entity\FieldConfig.

Class

FieldConfig
Defines the Field entity.

Namespace

Drupal\field\Entity

Code

public static function preDelete(EntityStorageInterface $storage, array $fields) {
  $state = \Drupal::state();
  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') ?: array();
  foreach ($fields as $field) {
    if (!$field->deleted) {
      $config = $field
        ->toArray();
      $config['deleted'] = TRUE;
      $config['field_storage_uuid'] = $field
        ->getFieldStorageDefinition()
        ->uuid();
      $deleted_fields[$field
        ->uuid()] = $config;
    }
  }
  $state
    ->set('field.field.deleted', $deleted_fields);
}