Closed (fixed)
Project:
Drupal core
Version:
11.3.x-dev
Component:
other
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
25 Apr 2025 at 07:54 UTC
Updated:
2 Dec 2025 at 11:04 UTC
Jump to comment: Most recent
Comments
Comment #3
bbralaWow, am i dreaming. This little trick might make it possible to support those symfony constraints without weirdness.
Everything is green... It cant be that easy right?
Comment #4
smustgrave commentedLeft some small comments and a question
If you are another contributor eager to jump in, please allow the previous poster(s) at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!
Comment #5
bbralaFixed issues, but kinda need someone into validation to review this since it feels weird this works at face value. It might overlook issues.
Comment #6
bbralaRemoving tag since committer who will review this seems to be the subsystem maintainer.
Comment #7
bbralaComment #8
smustgrave commentedGoing to mark because I believe all feedback has been addressed on this one, thank you for adding the CR.
Comment #9
quietone commentedI did not do a code review but I left a question about the name of the constraint and then made some minor suggestions.
This should have another opinion about the name, not just mine.
Comment #10
bbralaThanks quietone for the review. Since it was all style/wording ill set it back to RTBC
Comment #11
borisson_While this is great, we don't usually add new features if they don't have an immediate usecase in core. Do you know where we could be using this? Or is this just about exposing all the symfony constraints?
Comment #12
bbralaValid point. As per parent Wim said he had a quite a few places where this was usefull, but he didnt say where. When i look at core i see a few places where this might be quite usefull. Few examples:
Here it could first say "Should not be blank", then if that is true "Invalid extension name", when "Extension does not exist".
This is way better than doing them all.
Same here:
or
I think a lot of the places where more than one constraint is defined we should use this. Should we pick one or perhaps just do follow ups? What do you think.
Comment #13
wim leers#12++
Comment #14
borisson_I think doing followups makes most sense here.
Comment #15
bbralaI've made #3544203: [META] Update schema's with multiple contraints to SequentiallyConstraint to start working on those after this issue.
Comment #17
dcam commentedI'm checking all RTBC issues to ensure their new tests use attributes. Because these changes are minor and the tests are passing I'm going to leave the issue at RTBC.
Comment #18
dcam commentedThe MR for this issue was identified as having a new Kernel/Functional test class that did not have the
#[RunTestsInSeparateProcesses]attribute. A deprecation warning is now issued in the case of these omissions. I've rebased the MR added the attribute to prevent this from being committed as-is and accidentally breaking tests on HEAD. Because this is a minor change to test metadata and the tests are passing I am leaving the issue's status as RTBC.Comment #19
alexpottNeed this to fix a PHP 8.5 issue! Will merge once we're out of the commit freeze.
Comment #20
alexpottI think we should convert the block region constraint here because it is where the PHP 8.5 deprecation is AND it shows we've got an implementation problem somewhere because the test is unable to get the correct violation property path...
Comment #21
alexpottComment #22
bbralahttps://drupal.slack.com/archives/C079NQPQUEN/p1763045170414389?thread_t...
Comment #23
alexpottComment #24
bbralaOk, with the help of @alexpott the issue has been fixed and we can easily support all the Composite constratiants now.
I've fixed the tests, which also seem to proove sequentially is doing its work, which is awesome :)
Comment #25
godotislateSome comments on the MR.
Comment #26
bbralaThink i adressed all issues, setting NR (tests are running, sorry)
Comment #27
godotislateTest failure seems unrelated, but should be re-run to make sure.
Otherwise looks good for RTBC.
Comment #28
bbralaAs per 27 rtbc
Comment #29
longwaveLooks good, I like the fact we are reusing the Symfony code directly now. Added a question about BC, and a possible followup - if we don't think the BC Is worth it this can go back to RTBC.
Comment #30
longwaveAll threads resolved, back to RTBC.
Comment #31
bbralaI know this is rtbc, but when working on https://www.drupal.org/project/drupal/issues/3535734 i ran into wanting "Required" also a composite constraint. Then i realized, why don't we initialize the nested constraints (first level ) in the ConstraintManager?
Then i wouldnt have to overwrite the Required constraint to add extra logic to the create method... and it might be able to just load composites without any overwriting?
Comment #32
benjifisherThe change record is pretty minimal. I think it would help to add "before and after" code snippets. You could use the changes to
core/modules/block/config/schema/block.schema.ymlin the current MR or use one of the examples from Comment #12.I think that removing
core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/AtLeastOneOfConstraintValidator.phpcounts as an API change. If so, then it should be listed in the issue summary and also in the change record (or a new, separate change record). It looks as though that class was added in Drupal 11.2.I fixed some typos in the issue summary.
Comment #33
bbralaUpdated the change record and added a new one.
It is kinda an API change, but the chance of breakage is pretty much zero.
Comment #34
bbralaNote about #13
Seems kinda hard. Not all composite constraints use the same property. The method to find out which property is the constraints is protected unfortunately which means we cannot know at that point which to use. A trait will work, but unless the method becomes pu b lic in symfony it's a no go without some bad magic.
Comment #35
alexpott@bbrala there's another problem - \Symfony\Component\Validator\Constraints\Composite::getCompositeOption() is not static but we need to call it in \Drupal\Core\Validation\Plugin\Validation\Constraint\AtLeastOneOfConstraint::create() which is. A trait would be possible if we get them to change the method to a static but I feel that that is unlikely. Let's open a follow-up because I think we can achieve your idea of doing this in the ConstraintManager with just a little bit of work.
Comment #36
alexpottAdded #3558181: Instantiate a composite validators constraints in the ConstraintManager
Comment #37
alexpottProved too easy to add the interface to support construction of the nested constraints in the manager... so did it here because this issue has become sort out nested constraints so they are nice to work with...
Comment #38
bbralaAdded comments, but only as indication of review. This looks very good, happy to see we don't need create anymore this way and we can add the symfony contraints easily. Still needs an overwrite of the existing constraint, which is unfortunate (and might proove very annoying when trying to implement the Collection constraint which hard codes
new Required()sometimes. But it's a big upgrade on how this works.Awesome, im happy. LGTM :D
Comment #39
bbralaNote, this blockes kinda blocks #3535734: Make block.settings.inline_block:* fully validatable, although maybe a soft block.
Comment #40
bbralaFound a possible issue when passing other options than constrainst to Composite contraints.
Comment #41
bbralaTalked to alex, creating a follow up.
Comment #42
bbrala#3558201: Composite constraints do not allow passing parameters
Comment #43
bbralaComment #44
catchHad a couple of questions but they were already answered by discussion in the MR.
Committed/pushed to 11.x and cherry-picked to 11.3.x, thanks!
Comment #48
bbralaAwesome! Thanks