public function VoteUpDownField::getConstraints in Vote Up/Down 8
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
- src/
Plugin/ Field/ FieldType/ VoteUpDownField.php, line 87
Class
- VoteUpDownField
- Plugin implementation of the 'vote_up_down_field' field type.
Namespace
Drupal\vud\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraints = parent::getConstraints();
if ($max_length = $this
->getSetting('max_length')) {
$constraint_manager = \Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints[] = $constraint_manager
->create('ComplexData', [
'value' => [
'Length' => [
'max' => $max_length,
'maxMessage' => $this
->t('%name: may not be longer than @max characters.', [
'%name' => $this
->getFieldDefinition()
->getLabel(),
'@max' => $max_length,
]),
],
],
]);
}
return $constraints;
}