Problem/Motivation
With #3514072: SDC slots can set expectations and cardinality , Core will introduce 3 new optional keywords in each SDC slot definition:
expectedwith a list of values: SDC plugin IDs (if they have a colon inside) or tags/groups (if no colon inside)minItemsandmaxItemswith 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
ComponentSlotFormwhen 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
Issue fork ui_patterns-3551587
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
pdureau commentedComment #3
pdureau commentedComment #4
pdureau commentedImportant to deal with that ASAP
Comment #5
just_like_good_vibesi take that
Comment #6
pdureau commentedComment #8
just_like_good_vibesComment #9
pdureau commentedComment #10
pdureau commentedThat's great,
Comment #11
pdureau commentedThe MR is implementing
expectedandmaxItemslogic inComponentSlotForm.For information, we have also already done
maxItemsin Dsipaly Builder: #3544026: Cardinality constraints for slots And we plan to doexpectedafter 1.0.0: #3617065: Expected components constraints for slotsWe 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:
ComponentSlotFormfor UI PatternsViewPanelBasefor Dispaly BuilderBut let's make sure they are fitting well. Maybe the y case use the same methods from the same Interface.
Comment #12
pdureau commentedWorks well :)
Comment #14
just_like_good_vibes