You are here

public function TelephoneItem::getConstraints in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem::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/telephone/src/Plugin/Field/FieldType/TelephoneItem.php, line 60

Class

TelephoneItem
Plugin implementation of the 'telephone' field type.

Namespace

Drupal\telephone\Plugin\Field\FieldType

Code

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