You are here

public function SqlContentEntityStorage::onFieldStorageDefinitionDelete in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::onFieldStorageDefinitionDelete()

Reacts to the deletion of a field storage definition.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition: The field being deleted.

Overrides ContentEntityStorageBase::onFieldStorageDefinitionDelete

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php, line 1414
Contains \Drupal\Core\Entity\Sql\SqlContentEntityStorage.

Class

SqlContentEntityStorage
A content entity database storage implementation.

Namespace

Drupal\Core\Entity\Sql

Code

public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) {
  $table_mapping = $this
    ->getTableMapping($this->entityManager
    ->getLastInstalledFieldStorageDefinitions($this->entityType
    ->id()));

  // @todo Remove the FieldStorageConfigInterface check when non-configurable
  //   fields support purging: https://www.drupal.org/node/2282119.
  if ($storage_definition instanceof FieldStorageConfigInterface && $table_mapping
    ->requiresDedicatedTableStorage($storage_definition)) {

    // Mark all data associated with the field for deletion.
    $table = $table_mapping
      ->getDedicatedDataTableName($storage_definition);
    $revision_table = $table_mapping
      ->getDedicatedRevisionTableName($storage_definition);
    $this->database
      ->update($table)
      ->fields(array(
      'deleted' => 1,
    ))
      ->execute();
    if ($this->entityType
      ->isRevisionable()) {
      $this->database
        ->update($revision_table)
        ->fields(array(
        'deleted' => 1,
      ))
        ->execute();
    }
  }

  // Update the field schema.
  $this
    ->wrapSchemaException(function () use ($storage_definition) {
    $this
      ->getStorageSchema()
      ->onFieldStorageDefinitionDelete($storage_definition);
  });
}