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
Issue fork display_builder-3608901
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 commented2 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:
But it is called only from
::buildSingleBlock(), so not for components.Comment #7
andres alvarez commentedConfirmed 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 viahasMultipleRoot(), 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.
Comment #8
andres alvarez commentedComment #9
mogtofu33 commentedComment #10
andres alvarez commentedRemoved
DebugComponentTestfrom the MR, it was leftover diagnostic code and asserted nothing. The multi-root case stays covered byBuilderPanelTest::testBuildSingleComponentMultiRootWrap, which fails without thehasMultipleRoot()condition and passes with it. Rebased cleanly on 1.0.x locally,BuilderPanelTestgreen.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 nonode_idand the builder shows "An error occurred". With the change both roots sit inside one wrapper node, the request carries itsnode_idand the move succeeds.Comment #11
andres alvarez commentedComment #12
mogtofu33 commentedComment #13
pdureau commentedIt seems the proposal (which is only one line of code) is addressing exactly what was described in:
Comment #15
mogtofu33 commented