Loading core/modules/workspaces/src/Entity/Workspace.php +21 −10 Original line number Diff line number Diff line Loading @@ -174,6 +174,16 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie 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(); Loading @@ -183,7 +193,8 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti // Trigger a batch purge to allow empty workspaces to be deleted // immediately. \Drupal::service('workspaces.manager')->purgeDeletedWorkspacesBatch(); $workspace_manager->purgeDeletedWorkspacesBatch(); }); } } core/modules/workspaces/tests/src/Kernel/WorkspaceCRUDTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -201,6 +201,9 @@ public function testDeletingWorkspaces() { $workspace_deleted = \Drupal::state()->get('workspace.deleted'); $this->assertCount(0, $workspace_deleted); // Check that the deleted workspace is no longer active. $this->assertFalse($this->workspaceManager->hasActiveWorkspace()); } /** Loading Loading
core/modules/workspaces/src/Entity/Workspace.php +21 −10 Original line number Diff line number Diff line Loading @@ -174,6 +174,16 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie 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(); Loading @@ -183,7 +193,8 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti // Trigger a batch purge to allow empty workspaces to be deleted // immediately. \Drupal::service('workspaces.manager')->purgeDeletedWorkspacesBatch(); $workspace_manager->purgeDeletedWorkspacesBatch(); }); } }
core/modules/workspaces/tests/src/Kernel/WorkspaceCRUDTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -201,6 +201,9 @@ public function testDeletingWorkspaces() { $workspace_deleted = \Drupal::state()->get('workspace.deleted'); $this->assertCount(0, $workspace_deleted); // Check that the deleted workspace is no longer active. $this->assertFalse($this->workspaceManager->hasActiveWorkspace()); } /** Loading