You are here

public function TelephoneItem::getConstraints in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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 65
Contains \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem.

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