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

  1. Call $instance->attachToSlot($component_node_id, 'not_a_slot', 0, 'textfield', ['value' => 'x']).
  2. 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

  1. Kernel test: unknown slot on a component, slot on a source without slots.
  2. Fix, and the @throws on both methods.
  3. Section in the rc1 change record.
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

Status: Active » Needs review
csakiistvan’s picture

Assigned: Unassigned » csakiistvan
csakiistvan’s picture

Assigned: csakiistvan » Unassigned
Status: Needs review » Reviewed & tested by the community

✅ Tested and works — on 1.0.x, attachToSlot() and moveToSlot() into an undeclared not_a_slot on 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 throw InvalidNodeException, while declared component slots, layout_twocol_section regions and page layout theme regions still accept nodes. Unknown slots can no longer be written to the tree.

  • mogtofu33 committed 70fdd559 on 1.0.x
    fix: #3639102 Attaching or moving a node to an unknown slot saves a node...
mogtofu33’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the review.

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.