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.
ContextualForm is out of scope
For Display Builder, it will be about builder & layers panels only. Everything happening in the ContextualForm panel, even involving slots, will be manged by UI Patterns 2. An issue will be created there.
The content overrides case
For content overrides, we need to also support the maxItems mechanism. Because the cardinality of the UI Patterns Soure field (" Allowed number of values " from the Field API) is acting like the maxItems keyword proposed in the Core issue, on the root dropzone (which is a slot of a "virtual" component).
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.
General:
- Let's ignore
minItemsfor now. - SDC and the Render API will only suggest, not enforce. So, it would be great to have a config in the Profile, or in the island(s), so we can apply strict behaviour to only some user roles
- If a logic would be better in UI Patterns level, go for it, to avoid duplicating logic later when UIP2 will need the same mechanism
- The challenge will be the UI. What do we do? Disactivate dropzones according to the component
Specific to maxItems:
- For builder & layers panels
- Content override: Limit the number of sources we can put in the root dropzone by checking the cardinality of the content field
- 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
expected will have its own ticket: #3617065: Expected components constraints for slots
Other follow-ups
- #3551232: Add a lock system
- the root dropzone cardinality logic will be needed if we add an UI to edit patterns sources
Issue fork display_builder-3544026
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 commentedComment #5
pdureau commentedMikael is taking the related UIP2 issue #3551587: Slots restrictions according to suggestions and cardinality so it is the best candidate for this task
Comment #6
pdureau commentedCareful, there are some changes at Druapl Core level: #3514072: SDC slots can set expectations and cardinality
Please follow closely what is happening there.
Comment #7
svendecabooterComment #8
svendecabooterComment #9
pdureau commentedThis change is also needed for #3551232: Add a lock system
Comment #10
mogtofu33 commentedComment #11
pdureau commentedComment #12
pdureau commented#3514072: SDC slots can set expectations and cardinality has been merged to Core main branch tooday
Comment #13
pdureau commentedI will give a try
Comment #15
pdureau commentedThis is a feature request
Comment #16
pdureau commentedIt has started by the way ;)
Comment #17
pdureau commentedSome parts of the scope has been moved to #3617065: Expected components constraints for slots
So, let's focus on
maxItems:>
playwright testsplaywright testsAlso:
We now have at least 4 other tickets waiting for this feature:
isDropzoneLocked()JavaScript logicSourceWithSlotsInterfaceComment #18
pdureau commentedComment #19
pdureau commentedComment #20
pdureau commentedComment #21
pdureau commentedCurrent status:
playwright testsplaywright testsHow do this work?
ViewPanelBaseis addingdata-max-itemsattribute to dropzoneDisplayBuildableInterface::getRootCardinality()dropzone.jsis preventing the drop.ApiContoller::attachToRoot()is listeningOutOfRangeExceptionInstance::attachToRoot()andInstance::moveToRoot()DisplayBuildableInterface::getRootCardinality()RealRenderTraitis addingdata-max-itemsattribute to dropzoneSourceWithSlotsInterface::getSlotCardinality()dropzone.jsis preventing the dropApiContoller::attachToSlot()is listeningOutOfRangeExceptionInstance::attachToSlot()andInstance::moveToslot()SourceWithSlotsInterface::getSlotCardinality()Topics to discuss during review:
For information, the other tickets waiting for this mechanism:
isDropzoneLocked()JavaScript logicSourceWithSlotsInterfaceComment #22
mogtofu33 commentedPushed 4 fixes in individuals commit for review, so they can be discussed/reverted if problem.
Comment #23
pdureau commentedThanks for the quick review and the 4 welcomed changes 👍
I will try this a bit.
OK
Thanks a lot. I will assign the ticket to you once ready.
OK, so I will just add a few information, and we will do the whole pass later.
Comment #24
pdureau commentedDone.
Comment #25
pdureau commentedDocumentation changed, not much because of the expected whole pass, but at least cardinality is mentioned:
docs/entity-displays-overrides.mddocs/sdc.mdI have also added mentions of:
docs/internals.mddocs/islands.mdComment #26
mogtofu33 commented