Problem/Motivation

If a component is a pattern (ie: include multiple components, like a header or a footer), it needs to be wrapped in a dom element or some sub components will be "draggable" in the Display Builder "builder" Island and will raise an error when moved as they do not exist in the config.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

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

Title: API errors on builder » Component patterns must be wrap to work in the builder
Issue summary: View changes
pdureau’s picture

pdureau’s picture

2 infos which may be useful.

A pattern source tree has always a single root, which is the selected source from which the pattern entity has been created.
https://git.drupalcode.org/project/display_builder/-/blob/1.0.x/src/Enti...

BuilderPanel::hasMultipleRoot() is already checking if a renderable has multiple HTMl elements at the root:
https://git.drupalcode.org/project/display_builder/-/blob/1.0.x/src/Plug...

And wrapping it if necessary:

   elseif (!$this->useAttributesVariable($build) || $this->hasMultipleRoot($build)) {
      $build = [
        '#type' => 'html_tag',
        '#tag' => 'div',
        '#attributes' => ['class' => $classes],
        'content' => $build,
      ];
    }

But it is called only from ::buildSingleBlock(), so not for components.

andres alvarez made their first commit to this issue’s fork.

andres alvarez’s picture

Confirmed the root cause. Component patterns with multiple root HTML elements require wrapping in a single container for the Display Builder's drag-and-drop logic to work correctly. Without wrapping, each root element becomes individually draggable.

The fix extends the wrapping condition in buildComponentRealRender() to check for multiple roots via hasMultipleRoot(), in addition to the existing attributes variable check. Test coverage added for the multi-root pattern scenario.

Validation: kernel test passes; confirmed via stash/pop that test fails without the fix. MR to follow.

andres alvarez’s picture

Status: Active » Needs review
mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Needs review » Needs work
andres alvarez’s picture

Removed DebugComponentTest from the MR, it was leftover diagnostic code and asserted nothing. The multi-root case stays covered by BuilderPanelTest::testBuildSingleComponentMultiRootWrap, which fails without the hasMultipleRoot() condition and passes with it. Rebased cleanly on 1.0.x locally, BuilderPanelTest green.

Also reproduced it in a real builder (Article display, component with a <header> and a <footer> root). Without the change, dragging the second root sends a move request with no node_id and the builder shows "An error occurred". With the change both roots sit inside one wrapper node, the request carries its node_id and the move succeeds.

andres alvarez’s picture

Status: Needs work » Needs review
mogtofu33’s picture

Assigned: Unassigned » pdureau
pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs review » Reviewed & tested by the community

It seems the proposal (which is only one line of code) is addressing exactly what was described in:

BuilderPanel::hasMultipleRoot() is already checking if a renderable has multiple HTMl elements at the root:
https://git.drupalcode.org/project/display_builder/-/blob/1.0.x/src/Plug... but it is called only from ::buildSingleBlock(), so not for components.

mogtofu33’s picture

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

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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.