You are here

public function FieldConfigBase::getConstraint in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/FieldConfigBase.php \Drupal\Core\Field\FieldConfigBase::getConstraint()
  2. 9 core/lib/Drupal/Core/Field/FieldConfigBase.php \Drupal\Core\Field\FieldConfigBase::getConstraint()

Returns a validation constraint.

See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.

Parameters

string $constraint_name: The name of the constraint, i.e. its plugin id.

Return value

array A validation constraint definition which can be used for instantiating a \Symfony\Component\Validator\Constraint object.

Overrides DataDefinitionInterface::getConstraint

See also

\Symfony\Component\Validator\Constraint

File

core/lib/Drupal/Core/Field/FieldConfigBase.php, line 506

Class

FieldConfigBase
Base class for configurable field definitions.

Namespace

Drupal\Core\Field

Code

public function getConstraint($constraint_name) {
  $constraints = $this
    ->getConstraints();
  return $constraints[$constraint_name] ?? NULL;
}