Problem/Motivation

I am well aware that it is not possible to add a new language while you are switched to for example the stage workspace - i just had to look up and test something. but the problem is if you are trying to add for example a content type or save any configuration form, they fail gracefully, while when i am trying to add a new language i am running into the following runtime exception:

The website encountered an unexpected error. Try again later.

RuntimeException: This entity can only be saved in the default workspace. in Drupal\workspaces\EntityOperations->entityPresave() (line 132 of core/modules/workspaces/src/EntityOperations.php).
workspaces_entity_presave()
call_user_func_array() (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 325)
Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook() (Line: 529)
Drupal\Core\Entity\EntityStorageBase->doPreSave() (Line: 483)
Drupal\Core\Entity\EntityStorageBase->save() (Line: 239)
Drupal\Core\Config\Entity\ConfigEntityStorage->save() (Line: 354)
Drupal\Core\Entity\EntityBase->save() (Line: 617)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 293)
Drupal\Core\Entity\EntityForm->save() (Line: 88)
Drupal\language\Form\LanguageAddForm->save()
call_user_func_array() (Line: 105)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 43)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 589)
Drupal\Core\Form\FormBuilder->processForm() (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult() (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult() (Line: 80)
Drupal\workspaces\Controller\WorkspacesHtmlEntityFormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 593)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19) 

Steps to reproduce

  • switch to the stage workspace
  • go to admin/config/regional/language/add and add another language

Proposed resolution

Avoid the runtime exception and return an error message that this form can only be submitted in the default workspace

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3471675

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:

Comments

rkoller created an issue. See original summary.

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

amateescu’s picture

Status: Active » Needs review

Looked into this today and it turns out that the language add/edit forms are using #limit_validation_errors and the workspace validation didn't account for that.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Thanks for always including test coverage from the jump!

1) Drupal\Tests\workspaces\Functional\WorkspaceFormValidationTest::testValidateLimitErrors
Behat\Mink\Exception\ResponseTextException: The text "This form can only be submitted in the default workspace." was not found anywhere in the text of the current page.
/builds/issue/drupal-3471675/vendor/behat/mink/src/WebAssert.php:907
/builds/issue/drupal-3471675/vendor/behat/mink/src/WebAssert.php:293
/builds/issue/drupal-3471675/core/tests/Drupal/Tests/WebAssert.php:979
/builds/issue/drupal-3471675/core/modules/workspaces/tests/src/Functional/WorkspaceFormValidationTest.php:56
FAILURES!

Test coverage appears to be there and following the test.

Following the steps provided I don't get an exception.

LGTM

penyaskito’s picture

Status: Reviewed & tested by the community » Needs work

There are merge conflicts on the phpstan baseline.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

Fixed.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

There are quite a few Functional test failures here in the Workspaces module.

amateescu changed the visibility of the branch 3471675-improve-form-validation to hidden.

amateescu changed the visibility of the branch 3471675-improve-form-validation to active.

amateescu’s picture

Status: Needs work » Needs review

Found the cause of those test failures, and implemented a quick workaround until #3485896: Hook ordering across OOP, procedural and with extra types i.e replace hook_module_implements_alter is done.

smustgrave’s picture

Won't this mean that entityFormAlter() won't be called?

amateescu’s picture

Re #12: Nope, it's now called "manually" from core/modules/workspaces/src/Hook/FormOperations::formAlter(). It's easier to see if you look at the commit directly: https://git.drupalcode.org/project/drupal/-/merge_requests/10447/diffs?c...

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, that was my only finding during the review.

catch’s picture

Status: Reviewed & tested by the community » Needs work

I don't think we should leave the hook method on the hooks class but without the attribute, it was confusing when reviewing, and could be confusing for anyone finding it later. Also hook ordering has landed, so we could probably use that directly in this issue now.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

Yay, hook ordering actually works now :) Reverted that change and made EntityOperations::entityFormAlter() run first. Back to RTBC because there's no functional change to the MR and the current code has already been reviewed before.

penyaskito’s picture

Issue tags: +11.2.0 release target

The test failure was random. Workspaces isn't enabled by default in Drupal CMS, but there is work going on for the next months where this might be a blocker, so if we can fit it in 11.2.0 it would be great.

catch’s picture

Status: Reviewed & tested by the community » Needs work

This has merge conflicts.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

Merged latest 11.x.

  • catch committed 6d0a54f6 on 11.x
    Issue #3471675 by amateescu, smustgrave, rkoller: RuntimeException when...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

Status: Fixed » Closed (fixed)

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