Issue #3366257 by amateescu: The active workspace is not deactivated when it's deleted
parent
917678cf43
commit
96939a6ba0
|
@ -174,16 +174,27 @@ class Workspace extends ContentEntityBase implements WorkspaceInterface {
|
||||||
public static function postDelete(EntityStorageInterface $storage, array $entities) {
|
public static function postDelete(EntityStorageInterface $storage, array $entities) {
|
||||||
parent::postDelete($storage, $entities);
|
parent::postDelete($storage, $entities);
|
||||||
|
|
||||||
// Add the IDs of the deleted workspaces to the list of workspaces that will
|
/** @var \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager */
|
||||||
// be purged on cron.
|
$workspace_manager = \Drupal::service('workspaces.manager');
|
||||||
$state = \Drupal::state();
|
// Disable the currently active workspace if it has been deleted.
|
||||||
$deleted_workspace_ids = $state->get('workspace.deleted', []);
|
if ($workspace_manager->hasActiveWorkspace()
|
||||||
$deleted_workspace_ids += array_combine(array_keys($entities), array_keys($entities));
|
&& in_array($workspace_manager->getActiveWorkspace()->id(), array_keys($entities), TRUE)) {
|
||||||
$state->set('workspace.deleted', $deleted_workspace_ids);
|
$workspace_manager->switchToLive();
|
||||||
|
}
|
||||||
|
|
||||||
// Trigger a batch purge to allow empty workspaces to be deleted
|
// Ensure that workspace batch purging does not happen inside a workspace.
|
||||||
// immediately.
|
$workspace_manager->executeOutsideWorkspace(function () use ($workspace_manager, $entities) {
|
||||||
\Drupal::service('workspaces.manager')->purgeDeletedWorkspacesBatch();
|
// 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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,6 +201,9 @@ class WorkspaceCRUDTest extends KernelTestBase {
|
||||||
|
|
||||||
$workspace_deleted = \Drupal::state()->get('workspace.deleted');
|
$workspace_deleted = \Drupal::state()->get('workspace.deleted');
|
||||||
$this->assertCount(0, $workspace_deleted);
|
$this->assertCount(0, $workspace_deleted);
|
||||||
|
|
||||||
|
// Check that the deleted workspace is no longer active.
|
||||||
|
$this->assertFalse($this->workspaceManager->hasActiveWorkspace());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue