Problem/Motivation
A theme can replace the component of a module or base theme with replaces, and core picks the replacement from the active theme. The builder page runs on the admin theme, and so do its htmx requests, which send the page theme. The Library and the component form then use the original definition: its label, props, slots and default values. The Canvas and the Preview run on the default theme and render the replacement. When the two differ, the form misses what the Canvas renders.
Steps to reproduce
- Use an admin theme other than the default theme.
- In the default theme, add a component with
replaces: my_module:cardand an extra slot. - Open a display in the builder and add the card from the Library.
- The Library and the form show the module card, without the extra slot. The Canvas renders the theme card.
Proposed resolution
Negotiate components for the default theme, the one the Canvas renders in. Switch the active theme around the Library definitions and the component form build, then restore it, as BuilderDataConverter::convertPage() already does. Core caches the negotiation per active theme, so the switch reads fresh results.
Remaining tasks
- Kernel test: the child test theme of #3631053: Styles, design tokens and components follow the default theme replaces a component of its base theme, with another theme active.
- Fix.
- Review.
User interface changes
The Library and the component form show the label, props and slots of the replacing component.
API changes
None.
Data model changes
None: sources keep the original component ID, as core expects.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 3631267 fix.png | 209.12 KB | csakiistvan |
Issue fork display_builder-3631267
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
Comment #2
mogtofu33 commentedComment #3
pdureau commentedComment #4
pdureau commentedFor information,
replacescan only be added to SDC defined in a theme, not in the ones defined in a module. This distinction may help.As said in the ticket description, we load SDCs both from:
ComponentLibraryDefinitions,ContextualFormPanelandApiController(for HTMX events)And
ScaffoldPanel?TreePanel? It will not resolve it while printing the component name. Were they skipped in purpose?In Core?
We can propose a fix in Core, like an optional theme argument:
But the responsibility of resolving the theme will stay on our side (more specifically, on UI Patterns side), and it will never land on time for our upcoming RC.
In Display Builder?
Is it something we can fix in a simple way (no additional service, no crazy thing)?
Let's be careful about switching to front theme in
ContextualFormPanel, we may lose the admin theme's processing (Claro alterscontainer,text_format,vertical_tabs… I don't know about the new Default Admin Theme) or, worse, render the form with the front theme.Comment #6
pdureau commentedHere is a MR with a proposal: https://git.drupalcode.org/project/display_builder/-/merge_requests/507
It breaks my heart we need to add another loosely defined service like that (
Drupal\display_builder\DefaultThemeComponentNegotiator), but I didn't find a betters way, even with the help of a LLM.How to test:
display_builder_theme_test:test_simpleLet's also address Scaffold and Tree panels.
Comment #7
pdureau commentedOK for me.
Comment #8
csakiistvanComment #9
csakiistvan❌ Does not fix the issue — after applying MR !507 and rebuilding caches, the Library shows the replacing component's label and the added card gets its heading default, but its extra slot is still missing from the builder. The slots of the replacing component are not covered yet.
Code review
33076e0c, pipeline green.BuilderPanel.php(line 95),TreePanel.php(line 72) andScaffoldPanel.php(line 65) still call$source->getSlotDefinitions()outsideforDefaultTheme(), so they read the original component's slots.Comment #10
pdureau commentedThanks you, this "replaced" topic is a rabbit hole, there are impacts everywhere.
Because there a slots, but also props and library previews:
labelprop (shared with parent)subtitleprop (specific to child)I will work on it.
Comment #11
pdureau commentedNew commit added to MR: https://git.drupalcode.org/project/display_builder/-/merge_requests/507
A lot of lines have changed because we got 6 calls to
DefaultThemeComponentNegotiatorand there was an opportunity to factorize. That's why the MR is smaller 27 PHP LOC smaller now.Tests (still with "Display Builder test child theme" as default theme):
labelprop (shared with parent)subtitleprop (specific to child)Comment #12
csakiistvanComment #13
csakiistvan✅ Tested and works — re-tested only the point from my previous review: applied MR !507 (latest commit), rebuilt caches, added "Card (theme)" from the Library to a new page layout on /admin/structure/page-layout/{id}/builder, and the Builder now shows the replacing component's "Footer (theme only)" slot next to "Body", with its "Theme heading" default. The missing-slot problem from the last round is fixed.
Comment #14
pdureau commentedComment #16
mogtofu33 commentedThanks for the work, pushed a small follow-up before merge.
The replacing component's label now comes from
ComponentSource::getChoiceLabel()soViewPanelBaseno longer needs the negotiator.DefaultThemeComponentNegotiatoralso caches the default theme, which cuts each lookup from 0.17 ms to 0.01 ms.No behavior change, the kernel tests cover both, so I'm merging on the existing RTBC.
Comment #18
pdureau commentedShipped in beta10 release.