You are here

public function TimeZoneItem::getConstraints in Time Zone Field 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/TimeZoneItem.php, line 59

Class

TimeZoneItem
Plugin implementation of the time zone field type.

Namespace

Drupal\tzfield\Plugin\Field\FieldType

Code

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