function Workspace::preDelete

Same name and namespace in other branches
  1. 8.9.x core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::preDelete()
  2. 10 core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::preDelete()
  3. 11.x core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::preDelete()

Overrides EntityBase::preDelete

File

core/modules/workspaces/src/Entity/Workspace.php, line 157

Class

Workspace
The workspace entity class.

Namespace

Drupal\workspaces\Entity

Code

public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage, $entities);
    $workspace_tree = \Drupal::service('workspaces.repository')->loadTree();
    // Ensure that workspaces that have descendants can not be deleted.
    foreach ($entities as $entity) {
        if (!empty($workspace_tree[$entity->id()]['descendants'])) {
            throw new \InvalidArgumentException("The {$entity->label()} workspace can not be deleted because it has child workspaces.");
        }
    }
}

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