public FieldItemList::getConstraints()
Gets a list of validation constraints.
Return value
array Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.
Overrides TypedData::getConstraints
File
- core/lib/Drupal/Core/Field/FieldItemList.php, line 272
Class
- FieldItemList
- Represents an entity field; that is, a list of field item objects.
Namespace
Drupal\Core\Field
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public function getConstraints() { $constraints = parent::getConstraints(); // Check that the number of values doesn't exceed the field cardinality. For // form submitted values, this can only happen with 'multiple value' // widgets. $cardinality = $this ->getFieldDefinition()->getFieldStorageDefinition()->getCardinality(); if ( $cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) { $constraints [] = $this ->getTypedDataManager() ->getValidationConstraintManager() ->create( 'Count' , array ( 'max' => $cardinality , 'maxMessage' => t( '%name: this field cannot hold more than @count values.' , array ( '%name' => $this ->getFieldDefinition()->getLabel(), '@count' => $cardinality )), )); } return $constraints ; } |
Please login to continue.