function EntityOperations::entityPredelete

Same name in other branches
  1. 8.9.x core/modules/workspaces/src/EntityOperations.php \Drupal\workspaces\EntityOperations::entityPredelete()
  2. 10 core/modules/workspaces/src/EntityOperations.php \Drupal\workspaces\EntityOperations::entityPredelete()
  3. 11.x core/modules/workspaces/src/EntityOperations.php \Drupal\workspaces\EntityOperations::entityPredelete()

Acts on an entity before it is deleted.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity being deleted.

See also

hook_entity_predelete()

File

core/modules/workspaces/src/EntityOperations.php, line 224

Class

EntityOperations
Defines a class for reacting to entity events.

Namespace

Drupal\workspaces

Code

public function entityPredelete(EntityInterface $entity) {
    $entity_type = $entity->getEntityType();
    // Only run if we are not dealing with an entity type provided by the
    // Workspaces module, an internal entity type or if we are in a non-default
    // workspace.
    if ($this->shouldSkipPreOperations($entity_type)) {
        return;
    }
    // Disallow any change to an unsupported entity when we are not in the
    // default workspace.
    if (!$this->workspaceManager
        ->isEntityTypeSupported($entity_type)) {
        throw new \RuntimeException('This entity can only be deleted in the default workspace.');
    }
}

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