Generated with the help of an LLM.
Problem/Motivation
attachToSlot() and moveToSlot() accept any slot ID on an existing parent.
An undeclared component slot is saved and never rendered, since UI Patterns builds declared slots only.
A slot on a source without slots is dropped at the next load.
getSlotCardinality() calls an unknown slot unlimited, so the full slot guard never stops it.
display_builder_ai passes slot IDs chosen by the model, so this is reachable today.
Steps to reproduce
- Call
$instance->attachToSlot($component_node_id, 'not_a_slot', 0, 'textfield', ['value' => 'x']). - It returns a node ID, and the node never renders in the Builder.
Proposed resolution
Throw InvalidNodeException when the parent source does not declare the slot, checked against getSlotDefinitions().
getSlotNodeIds() keeps its documented answer for an unknown slot, an empty array: a read needs no exception.
Remaining tasks
- Kernel test: unknown slot on a component, slot on a source without slots.
- Fix, and the
@throwson both methods. - Section in the rc1 change record.
Issue fork display_builder-3639102
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 #3
mogtofu33 commentedComment #4
csakiistvanComment #5
csakiistvan✅ Tested and works — on 1.0.x,
attachToSlot()andmoveToSlot()into an undeclarednot_a_sloton a card component saved both nodes, which did not render on the node page, and a child attached to a textfield was gone after reload; with MR !568 applied and caches rebuilt, all three calls throwInvalidNodeException, while declared component slots,layout_twocol_sectionregions and page layout theme regions still accept nodes. Unknown slots can no longer be written to the tree.Comment #7
mogtofu33 commentedThanks for the review.