Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291043

'type' constraints generate crappy error messages.

$
0
0

Context

Spin-off from #1992138: Helper issue for "field types as TypedData Plugins" / #1969728: Implement Field API "field types" as TypedData Plugins.

That issue adds actual validation on entity fields.
This means that implicit or explicit constraints contained in FieldItem::getPropertyDefinitions() (e.g 'type' => 'uri' in LinkItem, 'type' => 'integer' for 'tid' in TaxonomyTermReferenceItem...) that were just "dormant" so far in HEAD, are now fired.

Issue

When failed, the 'type' constraints generate messages like : "this value should be of type 3" :-)
That's because internally the 'types' that are used by the PrimitiveTypeConstraintValidator are integer-based class constants in the Primitive class (Primitive::INTEGER is 3, Primitive::URI is 7...)

Also, this bug aside, those messages are not ideal UX-wise.
- We typically prefix the validation errors reported in forms with the name of the field:
"My custom link: this value should be..."
- The unique common template for those error messages makes awkward formulations:
"... should be of type integer / ... should be of type uri / ..."
We tend to generate more nicely put feedback: "this should be an integer, this should be a URL", but that's difficult to capture in one single fits-all message template.
I guess each primitive type could define its own error message ? Possibly even overridable in the propertyDefinition itself ?


Viewing all articles
Browse latest Browse all 291043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>