Needs work
Project:
Drupal core
Version:
main
Component:
layout_builder.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
26 Sep 2019 at 01:21 UTC
Updated:
28 Sep 2026 at 05:36 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
weynhamzComment #3
weynhamzDrupal core assumes only `full` is the view mode used for the canonical route, so it does not pick up the override we made per node for the custom view mode. Is this canonical mode check really necessary? Attached patch currently disables the canonical mode check to temporarily resolve this issue.
The related broader issue is to make the layout builder override work for all custom view mode, that should address and resolve this specific use case.
Comment #4
weynhamzSilly mistake.
Comment #6
tim.plunkettNW for tests
Comment #8
avpadernoComment #11
danflanagan8Fixed typo in title.
Comment #15
mitchel432 commentedRefactored patch for Drupal 9.5
Comment #16
mitchel432 commentedFixed EOL and Encoding on my patch file.
Comment #17
_utsavsharma commentedComment #18
smustgrave commentedWas previously tagged for tests in #6 which still needs to happen.
Comment #20
twodLeftover debug override?
Comment #21
bbu23hook_entity_view_mode_alter in combination with Layout Builder + a formatter set in the "new view mode" that contains an ajax form crashes. I've seen multiple issues related to layout builder and other view modes besides full. I've tried a combination of patches, including the one from here (with the observation from previous comment manually modified), but that does not fix my issue.
A workaround for me is manually building the form prior to layout builder
Details:
1. I have a field formatter that displays an ajax form that whenever is submitted it reveals the processed value(s) of that field. But it requires this user interaction through ajax.
2. I have multiple "full" view modes that depend on specific entity values. So the "full" view mode is altered.
3. The ajax form does not work on the altered view modes, only on "full". It gives the "javascript is disabled" error which is described anyways in the ajax url documentation that it can happen.
Workaround:
1. If the form is loaded earlier forcefully, without storing it or anything, just form builder load with any potential params, then the ajax form works.
I feel like the solution for this lies in multiple issues combined. I doubt that anyone or maybe just a few people have this setup, but I wanted to share.
Comment #22
nightlife2008 commentedI discovered a side effect of the patch in #16, namely that my theme is prematurely initialized, and the default theme is used instead of the admin theme, because the route match hasn't been determined yet at that point, since it's currently determining it :D
Steps in code when this happens:
1. Find route match for path
/layout_builder/add/block/overrides/node.391/0/<region>/<pluginId>2. Routing parses the route params
3. Causes section storage's method
deriveContextsFromRouteto be triggered4. Rendering the entity causes the Theme negotiators to run on a
NullRoute, which at that point always returns the default theme.5. The page is rendered in the default theme instead of using the admin_theme as it should according to the
_admin_route: TRUEflag.Comment #23
tim@lammar.be commentedRework of #16 with removal of first (I think debug?) change.
Tested on local D10.2.4.
Comment #24
tim@lammar.be commentedComment #25
waropd commentedUpdated patch for D11.3
Comment #26
avpadernoComment #29
volegerAdded test case of hook implementation with display mode set.
Comment #30
smustgrave commentedleft comments on the MR.
Thanks.
Comment #31
volegerComment #32
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #33
danielvezaGiven the changes a quick sweep, I'm not too sure about the property_exists call, it feels a bit brittle.
Comment #35
volegerSo we need to choose either to introduce an API change or to use a brittle solution based on the
property_existscheck.Are there any other options to resolve the issue?
Comment #36
keshavv commentedRe-rolled #25 to fix the fatal it introduces, and to answer the question left open in #33/#35.
Why #25 and MR !14183 don't work as-is
LayoutEntityHelperTrait neither declares $entityTypeManager nor requires its users to provide one. In 11.3.x, LayoutOverrideFieldHelper uses the trait and injects only two services:
public function __construct(
protected SectionStorageManagerInterface $sectionStorageManager,
protected LayoutTempstoreRepositoryInterface $layoutTempstoreRepository,
) {}
So $this->entityTypeManager in #25 is an undefined property there, and the path is reachable from an ordinary entity save:
LayoutBuilderHooks::entityUpdate() #[Hook('entity_update')]
→ LayoutOverrideFieldHelper::updateTempstoreEntityContext()
→ LayoutEntityHelperTrait::getOverridesSectionStorageForEntity() (line 167)
→ LayoutEntityHelperTrait::getSectionStorageContextsForEntity() (line 181)
→ Error: Undefined property
With #25 applied, saving any entity that has the layout override field fatals. Contrib hits the same thing — page_manager's LayoutBuilderDisplayVariant and layout_builder_st's ComponentPluginTranslate also use the trait with no entity type manager.
MR !14183 avoids the fatal with property_exists($this, 'entityTypeManager'), but that skips the new code entirely for exactly those classes, LayoutOverrideFieldHelper included — so the reported bug stays unfixed on the path that actually reaches it. That is the brittleness #33 is pointing at.
Proposed approach — neither an API change nor property_exists
The trait already solves this for its other dependency, two methods up at line 155:
private function sectionStorageManager() {
return $this->sectionStorageManager ?? \Drupal::service('plugin.manager.layout_builder.section_storage');
}
The attached patch uses the same null-coalescing container fallback:
$entity_type_manager = $this->entityTypeManager ?? \Drupal::entityTypeManager();
?? uses isset() semantics, so it is safe both when the property is absent and when it is declared but uninitialised.
I deliberately did not add an entityTypeManager() accessor mirroring sectionStorageManager(). LayoutBuilderEntityViewDisplay also uses this trait and inherits EntityBase::entityTypeManager(); a trait method of that name would take precedence over the inherited one, and reducing it to private would be a fatal visibility error.
Also changed != to !== — both operands are strings.