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.

Comments

yched’s picture

Category: task » bug

as per the OP :-)

andypost’s picture

Working 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.

yched’s picture

Issue summary: View changes
Issue tags: +beta target

Beta 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 ?".

yched’s picture

Priority: Normal » Major

"beta target" -> bumping priority accordingly

e0ipso’s picture

Assigned: Unassigned » e0ipso
e0ipso’s picture

Assigned: e0ipso » Unassigned
Status: Active » Needs review
StatusFileSize
new20.62 KB

First approach. I don't really know if we can find a more general solution to add the replacements to a custom ConstraintInterface and make that be used by the ConstraintValidators in 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.

Status: Needs review » Needs work

The last submitted patch, 6: message-replacements-constraints-2023465-6.patch, failed testing.

e0ipso’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB
new20.7 KB

The length validator was missing some code.

fago’s picture

Status: Needs review » Needs work

We 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.

e0ipso’s picture

@fago, cool! That was my first instinct. I'm in a workshop for the next 2h, I'll find you later some time today.

dawehner’s picture

#2278353: Update to Symfony 2.5 is certainly a related issue.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: message-replacements-constraints-2023465-8.patch, failed testing.

ianthomas_uk’s picture

According 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?

yched’s picture

If 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 ?

berdir’s picture

If 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.

berdir’s picture

jibran’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: message-replacements-constraints-2023465-8.patch, failed testing.

xjm’s picture

Version: 8.0.x-dev » 8.2.x-dev
Issue tags: -beta target

This 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.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Is this still relevant?

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lendude’s picture

Status: Needs work » Postponed (maintainer needs more info)

Per #27, is this still relevant?

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue tags: +Bug Smash Initiative

4 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.

quietone’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Forgot to change the status.