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

Fields should optionally use PrimitiveType constraints

$
0
0

Greetings! I am running into an issue porting a module to Drupal 8 that uses the Field API. The issue is that the value my field provides is stored as a string, but at validation time, it is composed of several values that will be coerced into a string during preSave. Since it looks like TypedDataManager places the PrimitiveType constraint on all fields which extend FieldItemBase, it causes PrimitiveTypeConstraintValidator to run against your field, even if you specify a custom constraint in the @FieldType annotation.

I'm attaching a patch that will help to describe the problem by proposing a simplistic solution. I don't know if this is robust enough, but it should at least illustrate the problem a little better. The suggestion is for TypedDataManager::getDefaultConstraints() to not add the PrimitiveType constraint to all primitive types. Rather, let the fields define the constraint themselves.

Thanks!


Viewing all articles
Browse latest Browse all 301208

Trending Articles



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