public FieldItemList::getConstraints()
Gets a list of validation constraints.
array Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.
Overrides TypedData::getConstraints
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; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Field!FieldItemList.php/function/FieldItemList::getConstraints/8.1.x