function Workspace::postDelete
Same name and namespace in other branches
- 11.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()
- 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()
Overrides EntityBase::postDelete
File
-
core/
modules/ workspaces/ src/ Entity/ Workspace.php, line 194
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');
/** @var \Drupal\workspaces\WorkspaceTrackerInterface $workspace_tracker */
$workspace_tracker = \Drupal::service('workspaces.tracker');
// Gather the list of deleted workspace IDs, since the passed-in array is
// not required to be keyed by them.
$workspaces_ids = array_map(fn($entity) => $entity->id(), $entities);
// Disable the currently active workspace if it has been deleted.
if ($workspace_manager->hasActiveWorkspace() && in_array($workspace_manager->getActiveWorkspace()
->id(), $workspaces_ids, TRUE)) {
$workspace_manager->switchToLive();
}
// Non-empty workspaces will have to go through the revision purging process
// from \Drupal\workspaces\Hook\WorkspacesHooks::cron().
$workspace_ids_to_purge = [];
foreach ($workspaces_ids as $workspace_id) {
if ($workspace_tracker->getTrackedEntities($workspace_id)) {
$workspace_ids_to_purge[$workspace_id] = $workspace_id;
}
}
if ($workspace_ids_to_purge) {
$state = \Drupal::state();
$deleted_workspace_ids = $state->get('workspace.deleted', []);
$state->set('workspace.deleted', $deleted_workspace_ids + $workspace_ids_to_purge);
// Trigger a batch purge to allow workspaces with few revisions to be
// deleted immediately.
// @todo This is temporary until batch purging is converted to use queues.
// @see https://www.drupal.org/i/3553654
\Drupal::service(WorkspacesHooks::class)->cron();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.