RuntimeException when trying to add a new language

Created on 2 September 2024, 6 months ago

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

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
WorkspacesΒ  β†’

Last updated 3 days ago

No maintainer
Created by

πŸ‡©πŸ‡ͺGermany rkoller NΓΌrnberg, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @rkoller
  • First commit to issue fork.
  • Merge request !10447Improve workspace-unsafe form validation. β†’ (Open) created by amateescu
  • Pipeline finished with Failed
    3 months ago
    Total: 141s
    #358199
  • πŸ‡·πŸ‡΄Romania amateescu

    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.

  • Pipeline finished with Success
    3 months ago
    Total: 1077s
    #358214
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    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

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    There are merge conflicts on the phpstan baseline.

  • πŸ‡·πŸ‡΄Romania amateescu

    Fixed.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 760s
    #380766
  • Pipeline finished with Failed
    about 2 months ago
    Total: 567s
    #389528
  • πŸ‡³πŸ‡ΏNew Zealand quietone

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

  • πŸ‡·πŸ‡΄Romania amateescu

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

  • πŸ‡·πŸ‡΄Romania amateescu

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

  • Pipeline finished with Failed
    about 1 month ago
    Total: 1522s
    #402524
  • Pipeline finished with Success
    18 days ago
    Total: 346s
    #414782
  • Status changed to Needs review 18 days ago
  • πŸ‡·πŸ‡΄Romania amateescu

    Found the cause of those test failures, and implemented a quick workaround until πŸ“Œ Hook ordering across OOP, procedural and with extra types Active is done.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

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

Production build 0.71.5 2024