Problem/Motivation

With #3514072: SDC slots can set expectations and cardinality , Core will introduce 3 new optional keywords in each SDC slot definition:

  • expected with a list of values: SDC plugin IDs (if they have a colon inside) or tags/groups (if no colon inside)
  • minItems and maxItems with a strictly positive integer value: Enforce a lower/maximum limit on the number of children

SDC and the Render API will only suggest, not enforce. So, both UI Patterns 2 (in the slot part of the component form) and Display Builder will need to find a way to leverage those properties.

Display Builder already have a dedicated issue #3544026: Cardinality constraints for slots

Proposal

We don't need to wait the Core issue to be merged to start. The consensus has been reached and Core will not do much anyway.

Let's ignore minItems for now.

Specific to maxItems:

  • Disable the "Select a source to add" select in ComponentSlotForm when the limit is reached
  • The restriction works for all sources, because if a source can have many renderables but many sources can't generate a single renderable
  • because if a source can have many renderables, we may overpass the limit without knowing it but it is OK, this is the sitaution we can accept

Specific to expected:

  • Filter out components from ComponentSource source plugin select list.
  • This restrictions works only on components, other sources are still free to be put anywhere
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

pdureau created an issue. See original summary.

pdureau’s picture

Title: Slots restrictions accordign to suggestions and cardinality » Slots restrictions according to suggestions and cardinality
pdureau’s picture

pdureau’s picture

Important to deal with that ASAP

just_like_good_vibes’s picture

Assigned: Unassigned » just_like_good_vibes
Status: Active » Needs work

i take that

pdureau’s picture

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » pdureau
Status: Needs work » Needs review
pdureau’s picture

Issue summary: View changes
pdureau’s picture

Assigned: pdureau » just_like_good_vibes
Issue summary: View changes

That's great,

pdureau’s picture

The MR is implementing expected and maxItems logic in ComponentSlotForm.

For information, we have also already done maxItems in Dsipaly Builder: #3544026: Cardinality constraints for slots And we plan to do expected after 1.0.0: #3617065: Expected components constraints for slots

We did it by leveraging https://git.drupalcode.org/project/display_builder/-/blob/1.0.x/src/Sour... whiwh we plan to move to UI Patterns soon: #3571009: Add SourceWithSlotsInterface and LayoutSource & #3572186: Use SourceWithSlotsInterface from UI Patterns.

The 2 works are different, because the act on distinct UI:

  • ComponentSlotForm for UI Patterns
  • ViewPanelBase for Dispaly Builder

But let's make sure they are fitting well. Maybe the y case use the same methods from the same Interface.

pdureau’s picture

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

Works well :)

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » 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.