function Workspace::preDelete
Same name in other branches
- 9 core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::preDelete()
- 8.9.x core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::preDelete()
- 10 core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::preDelete()
Overrides EntityBase::preDelete
File
-
core/
modules/ workspaces/ src/ Entity/ Workspace.php, line 168
Class
- Workspace
- The workspace entity class.
Namespace
Drupal\workspaces\EntityCode
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.