You are here

public function SqlContentEntityStorage::onFieldDefinitionDelete in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::onFieldDefinitionDelete()
  2. 10 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::onFieldDefinitionDelete()

Reacts to the deletion of a field.

Stored values should not be wiped at once, but marked as 'deleted' so that they can go through a proper purge process later on.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition being deleted.

Overrides ContentEntityStorageBase::onFieldDefinitionDelete

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php, line 1594

Class

SqlContentEntityStorage
A content entity database storage implementation.

Namespace

Drupal\Core\Entity\Sql

Code

public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definition) {
  $table_mapping = $this
    ->getTableMapping();
  $storage_definition = $field_definition
    ->getFieldStorageDefinition();

  // Mark field data as deleted.
  if ($table_mapping
    ->requiresDedicatedTableStorage($storage_definition)) {
    $table_name = $table_mapping
      ->getDedicatedDataTableName($storage_definition);
    $revision_name = $table_mapping
      ->getDedicatedRevisionTableName($storage_definition);
    $this->database
      ->update($table_name)
      ->fields([
      'deleted' => 1,
    ])
      ->condition('bundle', $field_definition
      ->getTargetBundle())
      ->execute();
    if ($this->entityType
      ->isRevisionable()) {
      $this->database
        ->update($revision_name)
        ->fields([
        'deleted' => 1,
      ])
        ->condition('bundle', $field_definition
        ->getTargetBundle())
        ->execute();
    }
  }
}