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.
Problem/Motivation
As discovered in #3027745: UniqueFieldConstraint doesn't work for entities with string IDs, the UniqueFieldValueValidator
lowerify the label of field when generating the message of violation.
See https://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Validation/...
$this->context->addViolation($constraint->message, [
'%value' => $item->value,
'@entity_type' => $entity->getEntityType()->getLowercaseLabel(),
'@field_name' => mb_strtolower($items->getFieldDefinition()->getLabel()),
]);
This is unnecessary as the Label should be displayed as seen in the Drupal UI.
Proposed resolution
Remove the mb_strtolower
.
Remaining tasks
Write a patchWrite test(s)- Review
User interface changes
- On violation of
UniqueFieldValueValidator
, the field name will be displayed as seen on the Admin and will not anymore be altered.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
Comment | File | Size | Author |
---|---|---|---|
#34 | 3029782-34.patch | 2.51 KB | karishmaamin |
#26 | 3029782-26.patch | 2.53 KB | yogeshmpawar |
#12 | 3029782-12.patch | 2.49 KB | wengerk |
#12 | interdiff-3029782-06-12.txt | 1.67 KB | wengerk |
Comments
Comment #2
knyshuk.vova CreditAttribution: knyshuk.vova at Internetdevels, Drupal Ukraine Community commentedComment #3
knyshuk.vova CreditAttribution: knyshuk.vova at Internetdevels, Drupal Ukraine Community commentedRemoved the
mb_strtolower
.Comment #4
abrammAdding #2999225: Unique field constraint does not validated field values on delta greater than 0 as relation since the mentioned issue adds UniqueFileValueValidator test which may need to be updated as well.
Comment #6
wengerkHere the fix for tests.
Comment #7
abramm#6 looks good for me, as long as CI passes.
Comment #8
abrammComment #10
PanchoWas green until yesterday. Testbot is heavily confused. Back to previous status.
Comment #12
wengerkHere a reroll, let's try it !
Comment #15
PanchoTestbot is green now.
Comment #16
wengerkUpdate remaining tasks
Comment #17
wengerkComment #18
claudiu.cristeaThis is legit. Labels should not be lowercased because they may look wrong in some languages, such as German. For example there's no lowercase for Apfel.
Comment #20
alexpottI think we need to step back and have a more general re-think about labels and cases. If you look at the code we're fixing just above we call
$entity->getEntityType()->getLowercaseLabel(),
... which doesmb_strtolower($this->getLabel());
- also wrong in German and other languages. Fixing this piecemeal is going to end up with lots of inconsistencies. As in why is the resulting violation got an uppercase field name but a lowercase entity type name.Yes we do need to fix the use of lowercasing in core and make it something that languages can override. So please don't take this comment as no we shouldn't do this.
Comment #25
longwave@alexpott's concerns in #20 have been addressed in that
getLowercaseLabel()
has been removed in #2507235: EntityType::getLowercaseLabel() breaks translation -getSingularLabel()
is used instead now in this class.However, the
mb_strtolower()
still exists so as per the original report I think we can reroll the patch here to fix this, and then this should be acceptable to be committed to core.Comment #26
yogeshmpawarA working patch against 9.3.x branch.
Comment #27
longwaveThanks!
Comment #30
claudiu.cristeaUnrelated failure
Comment #32
claudiu.cristeaComment #33
quietone CreditAttribution: quietone at PreviousNext commentedNeeds a reroll.
Comment #34
karishmaamin CreditAttribution: karishmaamin at Specbee commentedRe-rolled against 9.4.x.Please review
Comment #35
longwave#26 and #34 look identical to me, not sure this needed a reroll - back to RTBC either way.
Comment #37
longwaveUnrelated fail, back to RTBC.
Comment #41
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedStrange reset, let's try again.
Comment #42
alexpottCommitted and pushed ac84424e52 to 10.1.x and 904319041f to 10.0.x and 403eb8dddc to 9.5.x. Thanks!