function Workspace::postDelete
Same name in other branches
- 9 core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::postDelete()
- 8.9.x core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::postDelete()
- 10 core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::postDelete()
Overrides EntityBase::postDelete
File
-
core/
modules/ workspaces/ src/ Entity/ Workspace.php, line 184
Class
- Workspace
- The workspace entity class.
Namespace
Drupal\workspaces\EntityCode
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
/** @var \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager */
$workspace_manager = \Drupal::service('workspaces.manager');
// Disable the currently active workspace if it has been deleted.
if ($workspace_manager->hasActiveWorkspace() && in_array($workspace_manager->getActiveWorkspace()
->id(), array_keys($entities), TRUE)) {
$workspace_manager->switchToLive();
}
// Ensure that workspace batch purging does not happen inside a workspace.
$workspace_manager->executeOutsideWorkspace(function () use ($workspace_manager, $entities) {
// Add the IDs of the deleted workspaces to the list of workspaces that will
// be purged on cron.
$state = \Drupal::state();
$deleted_workspace_ids = $state->get('workspace.deleted', []);
$deleted_workspace_ids += array_combine(array_keys($entities), array_keys($entities));
$state->set('workspace.deleted', $deleted_workspace_ids);
// Trigger a batch purge to allow empty workspaces to be deleted
// immediately.
$workspace_manager->purgeDeletedWorkspacesBatch();
});
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.