function EntityOperations::entityPredelete

Same name in other branches
  1. 9 core/modules/workspaces/src/EntityOperations.php \Drupal\workspaces\EntityOperations::entityPredelete()
  2. 8.9.x core/modules/workspaces/src/EntityOperations.php \Drupal\workspaces\EntityOperations::entityPredelete()
  3. 10 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 271

Class

EntityOperations
Defines a class for reacting to entity events.

Namespace

Drupal\workspaces

Code

public function entityPredelete(EntityInterface $entity) {
    if ($this->shouldSkipOperations($entity)) {
        return;
    }
    // Prevent the entity from being deleted if the entity type does not have
    // support for workspaces, or if the entity has a published default
    // revision.
    $active_workspace = $this->workspaceManager
        ->getActiveWorkspace();
    if (!$this->workspaceInfo
        ->isEntitySupported($entity) || !$this->workspaceInfo
        ->isEntityDeletable($entity, $active_workspace)) {
        throw new \RuntimeException("This {$entity->getEntityType()->getSingularLabel()} can only be deleted in the Live workspace.");
    }
}

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