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

  1. Use an admin theme other than the default theme.
  2. In the default theme, add a component with replaces: my_module:card and an extra slot.
  3. Open a display in the builder and add the card from the Library.
  4. 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

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.

CommentFileSizeAuthor
#13 3631267 fix.png209.12 KBcsakiistvan
Command icon 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

mogtofu33 created an issue. See original summary.

mogtofu33’s picture

Issue tags: +RC blocker
pdureau’s picture

pdureau’s picture

For information, replaces can 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:

  • Front theme, resolving the replacement: BuilderPanel, Preview
  • Admin theme, not resolving the replacement: ComponentLibraryDefinitions, ContextualFormPanel and ApiController (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:

$sdcManager->find('my_module:card', theme: 'olivero');
$negotiator->negotiate($id, $definitions, theme: 'olivero');

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)?

Switch the active theme around the Library definitions and the component form build, then restore it.

Let's be careful about switching to front theme in ContextualFormPanel, we may lose the admin theme's processing (Claro alters container, text_format, vertical_tabs… I don't know about the new Default Admin Theme) or, worse, render the form with the front theme.

pdureau’s picture

Assigned: Unassigned » pdureau
Status: Active » Needs work

Here 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:

  1. Activate "Display Builder test child theme" as default theme. It has a Test simple child component, replacing display_builder_theme_test:test_simple
  2. Build a Display.
Step Expectation 1.0.x MR
Open Component library "Test simple" is missing. "Test simple child" is present. ❌ it is the opposite ✅
Drop "Test simple child" in the Builder panel The child is rendered (red background on slot) ❌ "Test simple" is rendered (green background on slot) ✅
Check Scaffold and Tree panels The component is called "Test simple child" ❌ "Test simple" ⚠️ Still "Test simple", but it was not part of the scope.
Stay on the contextual form The form is rendered with admin theme ✅ ✅
Submit a change The component prop is correctly updated ✅ ✅

Let's also address Scaffold and Tree panels.

pdureau’s picture

Assigned: pdureau » Unassigned
Status: Needs work » Needs review

OK for me.

Step Expectation 1.0.x MR
Open Component library "Test simple" is missing. "Test simple child" is present. ❌ it is the opposite ✅
Drop "Test simple child" in the Builder panel The child is rendered (red background on slot) ❌ "Test simple" is rendered (green background on slot) ✅
Check Scaffold and Tree panels The component is called "Test simple child" ❌ "Test simple" ✅
Stay on the contextual form The form is rendered with admin theme ✅ ✅
Submit a change The component prop is correctly updated ✅ ✅
csakiistvan’s picture

Assigned: Unassigned » csakiistvan
csakiistvan’s picture

Assigned: csakiistvan » Unassigned
Status: Needs review » Needs work

❌ 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
  • MR !507 at 33076e0c, pipeline green.
  • Blocking: BuilderPanel.php (line 95), TreePanel.php (line 72) and ScaffoldPanel.php (line 65) still call $source->getSlotDefinitions() outside forDefaultTheme(), so they read the original component's slots.
pdureau’s picture

Assigned: Unassigned » pdureau

Thanks you, this "replaced" topic is a rabbit hole, there are impacts everywhere.

Because there a slots, but also props and library previews:

Step Expectation 1.0.x MR
Open Component library "Test simple" is missing. "Test simple child" is present. ❌ ✅
Hover on "Test simple child" The child is rendered (red background on slot) ❌ ❌
Drop "Test simple child" in the Builder panel The child is rendered (red background on slot) ❌ ✅
Drop another component in slot 2 slot 2 is available and usable ❌ ❌
Check Scaffold and Tree panels The component is called "Test simple child" ❌ ✅
Stay on the contextual form The form is rendered with admin theme ✅ ✅
Submit a change in label prop (shared with parent) The component prop is correctly updated ✅ ✅
Submit in the subtitle prop (specific to child) The component prop is correctly updated ❌ ❌

I will work on it.

pdureau’s picture

Assigned: pdureau » Unassigned
Status: Needs work » Needs review

New 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 DefaultThemeComponentNegotiator and 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):

Step Expectation 1.0.x initial MR updated MR
Open Component library "Test simple" is missing. "Test simple child" is present. ❌ ✅ ✅
Hover on "Test simple child" The child is rendered (red background on slot) ❌ ❌ ✅
Drop "Test simple child" in the Builder panel The child is rendered (red background on slot) ❌ ✅ ✅
Drop another component in slot 2 slot 2 is available and usable ❌ ❌ ✅
Check Scaffold and Tree panels The component is called "Test simple child" ❌ ✅ ✅
Stay on the contextual form The form is rendered with admin theme ✅ ✅ ✅
Submit a change in label prop (shared with parent) The component prop is correctly updated ✅ ✅ ✅
Submit in the subtitle prop (specific to child) The component prop is correctly updated ❌ ❌ ✅
csakiistvan’s picture

Assigned: Unassigned » csakiistvan
csakiistvan’s picture

Assigned: csakiistvan » Unassigned
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new209.12 KB

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

pdureau’s picture

Assigned: Unassigned » mogtofu33

  • mogtofu33 committed 2e05f84c on 1.0.x authored by pdureau
    fix: #3631267 The Library and the component form ignore components...
mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Reviewed & tested by the community » Fixed

Thanks for the work, pushed a small follow-up before merge.
The replacing component's label now comes from ComponentSource::getChoiceLabel() so ViewPanelBase no longer needs the negotiator.
DefaultThemeComponentNegotiator also 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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

pdureau’s picture

Status: Fixed » Closed (fixed)

Shipped in beta10 release.