RuntimeException when trying to add a new language

Created on 2 September 2024, 8 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 about 2 hours 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
    5 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
    5 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
    4 months ago
    Total: 760s
    #380766
  • Pipeline finished with Failed
    4 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
    4 months ago
    Total: 1522s
    #402524
  • Pipeline finished with Success
    3 months ago
    Total: 346s
    #414782
  • Status changed to Needs review 3 months 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?

  • πŸ‡·πŸ‡΄Romania amateescu

    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...

  • Status changed to RTBC 30 days ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks, that was my only finding during the review.

  • πŸ‡¬πŸ‡§United Kingdom catch

    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.

  • πŸ‡·πŸ‡΄Romania amateescu

    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.

  • Pipeline finished with Failed
    about 18 hours ago
    Total: 478s
    #492439
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    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.

  • πŸ‡¬πŸ‡§United Kingdom catch

    This has merge conflicts.

  • πŸ‡·πŸ‡΄Romania amateescu

    Merged latest 11.x.

Production build 0.71.5 2024