You are here

public function UserMentionsFieldType::getConstraints in Tweet Feed 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldType/UserMentionsFieldType.php \Drupal\tweet_feed\Plugin\Field\FieldType\UserMentionsFieldType::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

src/Plugin/Field/FieldType/UserMentionsFieldType.php, line 92

Class

UserMentionsFieldType
Plugin implementation of the 'user_mentions_field_type' field type.

Namespace

Drupal\tweet_feed\Plugin\Field\FieldType

Code

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