public function TextItem::getConstraints in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/text/src/Plugin/Field/FieldType/TextItem.php \Drupal\text\Plugin\Field\FieldType\TextItem::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/
modules/ text/ src/ Plugin/ Field/ FieldType/ TextItem.php, line 60 - Contains \Drupal\text\Plugin\Field\FieldType\TextItem.
Class
- TextItem
- Plugin implementation of the 'text' field type.
Namespace
Drupal\text\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints = parent::getConstraints();
if ($max_length = $this
->getSetting('max_length')) {
$constraints[] = $constraint_manager
->create('ComplexData', array(
'value' => array(
'Length' => array(
'max' => $max_length,
'maxMessage' => t('%name: the text may not be longer than @max characters.', array(
'%name' => $this
->getFieldDefinition()
->getLabel(),
'@max' => $max_length,
)),
),
),
));
}
return $constraints;
}