function TestItem::getConstraints

Same name and namespace in other branches
  1. 9 core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php \Drupal\field_test\Plugin\Field\FieldType\TestItem::getConstraints()
  2. 8.9.x core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php \Drupal\field_test\Plugin\Field\FieldType\TestItem::getConstraints()
  3. 10 core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php \Drupal\field_test\Plugin\Field\FieldType\TestItem::getConstraints()

Overrides TypedData::getConstraints

File

core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php, line 121

Class

TestItem
Defines the 'test_field' entity field item.

Namespace

Drupal\field_test\Plugin\Field\FieldType

Code

public function getConstraints() {
    $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
    $constraints = parent::getConstraints();
    $constraints[] = $constraint_manager->create('ComplexData', [
        'value' => [
            'TestField' => [
                'value' => -1,
                'message' => $this->t('%name does not accept the value @value.', [
                    '%name' => $this->getFieldDefinition()
                        ->getLabel(),
                    '@value' => -1,
                ]),
            ],
        ],
    ]);
    return $constraints;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.