Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints()
  2. 9 core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints()

Returns an array of validation constraints.

The validation constraints of a definition consist of any for it defined constraints and default constraints, which are generated based on the definition and its data type. See \Drupal\Core\TypedData\TypedDataManager::getDefaultConstraints().

Constraints are defined via an array, having constraint plugin IDs as key and constraint options as values, e.g.

$constraints = array(
  'Range' => array(
    'min' => 5,
    'max' => 10,
  ),
  'NotBlank' => array(),
);

Options have to be specified using another array if the constraint has more than one or zero options. If it has exactly one option, the value should be specified without nesting it into another array:

$constraints = array(
  'EntityType' => 'node',
  'Bundle' => 'article',
);

Note that the specified constraints must be compatible with the data type, e.g. for data of type 'entity' the 'EntityType' and 'Bundle' constraints may be specified.

Return value

array[] An array of validation constraint definitions, keyed by constraint name. Each constraint definition can be used for instantiating \Symfony\Component\Validator\Constraint objects.

See also

\Drupal\Core\Validation\ConstraintManager

\Symfony\Component\Validator\Constraint

2 methods override DataDefinitionInterface::getConstraints()
DataDefinition::getConstraints in core/lib/Drupal/Core/TypedData/DataDefinition.php
Returns an array of validation constraints.
FieldConfigBase::getConstraints in core/lib/Drupal/Core/Field/FieldConfigBase.php
Returns an array of validation constraints.

File

core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php, line 189

Class

DataDefinitionInterface
Interface for data definitions.

Namespace

Drupal\Core\TypedData

Code

public function getConstraints();