public function TestItem::getConstraints in Drupal 10
Same name and namespace in other branches
- 8 core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php \Drupal\field_test\Plugin\Field\FieldType\TestItem::getConstraints()
- 9 core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php \Drupal\field_test\Plugin\Field\FieldType\TestItem::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/ field/ tests/ modules/ field_test/ src/ Plugin/ Field/ FieldType/ TestItem.php, line 114
Class
- TestItem
- Defines the 'test_field' entity field item.
Namespace
Drupal\field_test\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $constraint_manager
->create('ComplexData', [
'value' => [
'TestField' => [
'value' => -1,
'message' => t('%name does not accept the value @value.', [
'%name' => $this
->getFieldDefinition()
->getLabel(),
'@value' => -1,
]),
],
],
]);
return $constraints;
}