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
Comments
Comment #4
amateescu commentedLooked into this today and it turns out that the language add/edit forms are using
#limit_validation_errorsand the workspace validation didn't account for that.Comment #5
smustgrave commentedThanks for always including test coverage from the jump!
Test coverage appears to be there and following the test.
Following the steps provided I don't get an exception.
LGTM
Comment #6
penyaskitoThere are merge conflicts on the phpstan baseline.
Comment #7
amateescu commentedFixed.
Comment #8
quietone commentedThere are quite a few Functional test failures here in the Workspaces module.
Comment #11
amateescu commentedFound 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.
Comment #12
smustgrave commentedWon't this mean that entityFormAlter() won't be called?
Comment #13
amateescu commentedRe #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...Comment #14
smustgrave commentedThanks, that was my only finding during the review.
Comment #15
catchI 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.
Comment #16
amateescu commentedYay, 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.Comment #17
penyaskitoThe 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.
Comment #18
catchThis has merge conflicts.
Comment #19
amateescu commentedMerged latest 11.x.
Comment #21
catchCommitted/pushed to 11.x, thanks!