You are here

public function CountryItem::getConstraints in Country 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/CountryItem.php, line 67

Class

CountryItem
Plugin implementation of the 'country' field type.

Namespace

Drupal\country\Plugin\Field\FieldType

Code

public function getConstraints() {
  $constraint_manager = \Drupal::typedDataManager()
    ->getValidationConstraintManager();
  $constraints = parent::getConstraints();
  $constraints[] = $constraint_manager
    ->create('ComplexData', [
    'value' => [
      'Length' => [
        'max' => static::COUNTRY_ISO_MAXLENGTH,
        'maxMessage' => t('%name: the country iso-2 code may not be longer than @max characters.', [
          '%name' => $this
            ->getFieldDefinition()
            ->getLabel(),
          '@max' => static::COUNTRY_ISO_MAXLENGTH,
        ]),
      ],
    ],
  ]);
  return $constraints;
}