function TelephoneItem::getConstraints

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()
  2. 8.9.x core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem::getConstraints()
  3. 10 core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem::getConstraints()

Overrides TypedData::getConstraints

File

core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php, line 65

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();
  $constraints[] = $constraint_manager->create('ComplexData', [
    'value' => [
      'Length' => [
        'max' => self::MAX_LENGTH,
        'maxMessage' => $this->t('%name: the telephone number may not be longer than @max characters.', [
          '%name' => $this->getFieldDefinition()
            ->getLabel(),
          '@max' => self::MAX_LENGTH,
        ]),
      ],
    ],
  ]);
  return $constraints;
}

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