Problem/Motivation

Trying to delete a workspace that has associated content results in the following error:

The website encountered an unexpected error. Please try again later.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "0" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 150 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).
Drupal\Core\Entity\EntityTypeManager->getHandler(0, 'storage') (Line: 208)
Drupal\Core\Entity\EntityTypeManager->getStorage(0) (Line: 161)
Drupal\workspaces\WorkspaceAssociation->getAssociatedRevisions('workspace_id', 0, 'node') (Line: 96)
Drupal\workspaces\Form\WorkspaceDeleteForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 532)
Drupal\Core\Form\FormBuilder->retrieveForm('workspace_delete_form', Object) (Line: 278)
...

Steps to reproduce

  1. Create a workspace and activate it
  2. Create content in the workspace
  3. Switch to the Default workspace
  4. Click the Delete link in the dropbutton for the workspace created in 1, e.g. /admin/config/workflow/workspaces/manage/[your_workspace_id]/delete

Proposed resolution

Remove incorrect array_keys() call (see patch)

Remaining tasks

  • Verify patch/tests

Issue fork drupal-3181508

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tedfordgif created an issue. See original summary.

tedfordgif’s picture

tedfordgif’s picture

Issue summary: View changes
tedfordgif’s picture

And now with a test that works. Probably should do this with a unit test...

tedfordgif’s picture

Status: Active » Needs review
tedfordgif’s picture

larowlan’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative
+++ b/core/modules/workspaces/tests/src/Functional/WorkspaceDeleteFromUiTest.php
@@ -0,0 +1,53 @@
+ * Tests access bypass permission controls on workspaces.
...
+   * Verifies that a user can edit anything in a workspace they own.

these comments look to be copy/paste

Other than that, this looks good to me

tedfordgif’s picture

tedfordgif’s picture

Status: Needs work » Needs review

Bumping status

Status: Needs review » Needs work

The last submitted patch, 8: 3181508-workspace-delete-bug-8.test-only.patch, failed testing. View results

tedfordgif’s picture

Status: Needs work » Needs review

Patches were tested in wrong order, my bad. The patch with the fix passes.

amateescu’s picture

Status: Needs review » Needs work

Nice find! I looked around and we only test deleting workspaces in a kernel test, that's why we missed this in #3062434: Track the workspace of a revision in a base field and convert the workspace_association entity type to a custom index.

  1. +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceDeleteFromUiTest.php
    @@ -0,0 +1,53 @@
    +   * Verifies that uid 1 can delete workspaces from the UI.
    

    It's not really relevant which user deletes the workspace, so we could change this to "Verifies that a workspace with existing content can be deleted."

  2. +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceDeleteFromUiTest.php
    @@ -0,0 +1,53 @@
    +  public function testDeleteWorkspaceFromUi() {
    

    Let's move this test method to the existing functional test for workspace's UI: \Drupal\Tests\workspaces\Functional\WorkspaceTest

    and rename it to testDeleteWorkspaceWithExistingContent

  3. +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceDeleteFromUiTest.php
    @@ -0,0 +1,53 @@
    +    $page = $this->getSession()->getPage();
    +    $page->findLink('Switch to May 4')->click();
    +    $page = $this->getSession()->getPage();
    +    $page->findButton('Confirm')->click();
    

    Let's use switchToWorkspace() instead.

  4. +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceDeleteFromUiTest.php
    @@ -0,0 +1,53 @@
    +    $page->hasContent("The workspace May 4 has been deleted.");
    

    We can use single quotes here :)

tedfordgif’s picture

Feedback from #12 addressed. I also added an assertion to give a more informative error message if the workspace switcher block isn't enabled (meaning the test was written incorrectly).

It felt a bit arbitrary to expand the WorkspaceTest class, given that all the required modules aren't used in each test, but that is small beans.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, looks great now!

The last submitted patch, 15: 3181508-workspace-delete-bug-15.test-only.patch, failed testing. View results

Rajeshreeputra made their first commit to this issue’s fork.

amateescu’s picture

Please ignore #17, the patch from #15 is the one that is RTBC.

  • catch committed aa39bb3 on 9.2.x
    Issue #3181508 by tedfordgif, amateescu, larowlan: Can not delete...

  • catch committed c67bf77 on 9.1.x
    Issue #3181508 by tedfordgif, amateescu, larowlan: Can not delete...
catch’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.