Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Drupal provides the country list via the CountryManager. Entity properties sometimes have a need to store the country.
There is no constraint/validator that would validate the country against Drupal's country list.
Symfony Form has one, but it only works for symfony/intl, which we aren't using.
So, let's add our own constraint for this.
Beta phase evaluation
This is a non-prioritized normal task. It introduces no disruption, only adds a missing validator.
Comment | File | Size | Author |
---|---|---|---|
#9 | 2434095-9-add-country-constraint.patch | 5.56 KB | bojanz |
#8 | interdiff-6-7.txt | 938 bytes | martin107 |
#8 | 2434095-7-add-country-constraint.patch | 5.56 KB | martin107 |
#6 | 2434095-6-add-country-constraint.patch | 5.56 KB | bojanz |
#2 | 2434095-2-add-country-constraint.patch | 4.77 KB | bojanz |
Comments
Comment #1
bojanz CreditAttribution: bojanz commentedComment #2
bojanz CreditAttribution: bojanz commentedComment #3
dawehnerDo we usually require such a strict policy in validators?
Comment #4
bojanz CreditAttribution: bojanz commented@dawehner
The validator code is very close to the Symfony class, so I just copied what they do.
In core I see that ComplexDataConstraintValidator throws the same exception, others don't.
Comment #5
dawehnerAlright, well in case we have the code we should also cover it in the unit test :p
Comment #6
bojanz CreditAttribution: bojanz commentedHere we go, improved and expanded test.
Comment #7
dawehnerThank you
Comment #8
martin107 CreditAttribution: martin107 commentedJust brushing up a couple of nits.
Comment #9
bojanz CreditAttribution: bojanz commentedGood catch martin107, I was too quick in my copy-paste.
The interdiff shows that CountryConstraintValidator needs a newline after {, so I've added it.
Comment #10
pcambraGreen, let's go back to RTBC
Comment #11
alexpottIs this really a bug?
I think this issue is a normal task so we need to outline how it fits within the allowable Drupal 8 beta criteria. Can someone add Drupal 8 beta phase evaluation template to the issue summary. Afaics a module which provides an entity could easily add this themselves.
Comment #12
bojanz CreditAttribution: bojanz commentedYou're right. I've added the beta phase evaluation, clarifying that this is a non-prioritized, non-disruptive normal task.
Comment #13
webchickBack to Alex.
Comment #14
alexpott@bojanz why do you think core should add this validator? We could add hundreds of potential validators. According to the beta policy we shouldn't be making this kind of change, yes there is no disruption but that on it's own is not enough to commit this.
Comment #15
bojanz CreditAttribution: bojanz commentedSymfony provides both a country list (via symfony/intl which we aren't using) and a validator.
Drupal provides only the country list. The validator is missing.
Anyway, this can easily live in Address module, and we can revisit for next release.
Comment #16
martin107 CreditAttribution: martin107 commentedThis is something I would like to see implemented eventually.
Just kicking can/code down the road.