function DataDefinition::getConstraints
Same name in other branches
- 9 core/lib/Drupal/Core/TypedData/DataDefinition.php \Drupal\Core\TypedData\DataDefinition::getConstraints()
- 8.9.x core/lib/Drupal/Core/TypedData/DataDefinition.php \Drupal\Core\TypedData\DataDefinition::getConstraints()
- 11.x core/lib/Drupal/Core/TypedData/DataDefinition.php \Drupal\Core\TypedData\DataDefinition::getConstraints()
Overrides DataDefinitionInterface::getConstraints
2 calls to DataDefinition::getConstraints()
- DataDefinition::getConstraint in core/
lib/ Drupal/ Core/ TypedData/ DataDefinition.php - Returns a validation constraint.
- DataReferenceTargetDefinition::getConstraints in core/
lib/ Drupal/ Core/ TypedData/ DataReferenceTargetDefinition.php - Returns an array of validation constraints.
1 method overrides DataDefinition::getConstraints()
- DataReferenceTargetDefinition::getConstraints in core/
lib/ Drupal/ Core/ TypedData/ DataReferenceTargetDefinition.php - Returns an array of validation constraints.
File
-
core/
lib/ Drupal/ Core/ TypedData/ DataDefinition.php, line 261
Class
- DataDefinition
- A typed data definition class for defining data based on defined data types.
Namespace
Drupal\Core\TypedDataCode
public function getConstraints() {
$constraints = $this->definition['constraints'] ?? [];
$constraints += $this->getTypedDataManager()
->getDefaultConstraints($this);
// If either the constraints defined on this data definition or the default
// constraints for this data definition's type contain the `NotBlank`
// constraint, then prevent a validation error from `NotBlank` if `NotNull`
// already would generate one. (When both are present, `NotBlank` should
// allow a NULL value, otherwise there will be two validation errors with
// distinct messages for the exact same problem. Automatically configuring
// `NotBlank`'s `allowNull: true` option mitigates that.)
// @see ::isRequired()
// @see \Drupal\Core\TypedData\TypedDataManager::getDefaultConstraints()
if (array_key_exists('NotBlank', $constraints) && $this->isRequired()) {
assert(array_key_exists('NotNull', $constraints));
$constraints['NotBlank']['allowNull'] = TRUE;
}
return $constraints;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.