We need the possibility to specify custom message replacement values when defining the validation constraints. This is need to support constraint messages as field API uses in the form of "%name: Some constraint message.", but %name cannot be retrieved generically.
Once #1969728: Implement Field API "field types" as TypedData Plugins is in, this should be changed to a bug report as this patch implements a work-a-round which double-translates messages. So then, that's something that needs to be fixed.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | message-replacements-constraints-2023465-8.patch | 20.7 KB | e0ipso |
| #8 | 2023465-8-6-interdiff.txt | 1.48 KB | e0ipso |
Comments
Comment #1
yched commentedas per the OP :-)
Comment #2
andypostWorking on #2083803: Convert field type to typed data plugin for field_test module I've to implement own class to re-use validator and override of message too.
Comment #3
yched commentedBeta target - according to #2144327-37: Make all field types provide a schema(), this currently encourages field type developpers to put constraints at the field level rather than the property level (or duplicate constraints for EmailItem) in order to have the expected error messages, making it unclear "where do I put my constraints ?".
Comment #4
yched commented"beta target" -> bumping priority accordingly
Comment #5
e0ipsoComment #6
e0ipsoFirst approach. I don't really know if we can find a more general solution to add the replacements to a custom
ConstraintInterfaceand make that be used by theConstraintValidatorsin the Symfony component. Since I could not find a solution to abstract that I have copied the validators that we're currently using to make them use the replacements.Comment #8
e0ipsoThe length validator was missing some code.
Comment #9
fagoWe need to get this working without having to override all the used constraints - so we can easily reuse symfony constraints without having to rewrite all the things ;)
I've discussed that with webmozart (maintainer/author of symfony validator). Considering various ways we figured it's probably the best way to postprocess the violations in Drupal, i.e. read the values of the existing violation objects and create new (our) objects which can take care of the message replacements. That allows us to do it without having overwrite a lot / most of the symfony validator classes, which would be problematic for BC (only @api tagged stuff is guaranteed).
That means, we can add domain-specific methods to our violation objects as well. E.g. we could allow the entity system to provide each own violation classes coming with useful helpers like getEntity(), getFieldItemList(), ..
Are you at the drupal dev days? If so let's talk about it in person.
Comment #10
e0ipso@fago, cool! That was my first instinct. I'm in a workshop for the next 2h, I'll find you later some time today.
Comment #11
dawehner#2278353: Update to Symfony 2.5 is certainly a related issue.
Comment #14
ianthomas_ukAccording to @dawehner in #2278353-24: Update to Symfony 2.5 this is fixed as part of the upgrade to Symfony 2.5, can anyone confirmed if that is definitely the case?
Comment #15
yched commentedIf the version of the Symfony Validation lib we use allows custom error messages, that's way cool - but then there is some cleanup to be done to actually leverage this and remove the awkward workarounds in Fiield API ?
Comment #16
berdirIf that is possible, then I'm pretty sure he's talking about the new 2.5 validation API, which we are not yet using, there's an issue to change that.
Comment #17
berdirSee #2343035: Upgrade validator integration for Symfony versions 2.5+
Comment #18
jibran#2343035: Upgrade validator integration for Symfony versions 2.5+ is fixed.
Comment #21
xjmThis issue was marked as a beta target for the 8.0.x beta, but is not applicable as an 8.1.x beta target, so untagging.
API additions should generally be targeted for 8.2.x at this point.
Comment #27
wim leersIs this still relevant?
Comment #34
lendudePer #27, is this still relevant?
Comment #37
quietone commented4 years and also 11 months ago someone asked if this issue is still relevant. There has been no reply to either. And in #14 it it was suggested that this has been fixed. Therefor I am closing this as outdated.
Comment #38
quietone commentedForgot to change the status.