function TypedDataManager::getDefaultConstraints
Same name in other branches
- 9 core/lib/Drupal/Core/TypedData/TypedDataManager.php \Drupal\Core\TypedData\TypedDataManager::getDefaultConstraints()
- 10 core/lib/Drupal/Core/TypedData/TypedDataManager.php \Drupal\Core\TypedData\TypedDataManager::getDefaultConstraints()
- 11.x core/lib/Drupal/Core/TypedData/TypedDataManager.php \Drupal\Core\TypedData\TypedDataManager::getDefaultConstraints()
Overrides TypedDataManagerInterface::getDefaultConstraints
File
-
core/
lib/ Drupal/ Core/ TypedData/ TypedDataManager.php, line 254
Class
- TypedDataManager
- Manages data type plugins.
Namespace
Drupal\Core\TypedDataCode
public function getDefaultConstraints(DataDefinitionInterface $definition) {
$constraints = [];
$type_definition = $this->getDefinition($definition->getDataType());
// Auto-generate a constraint for data types implementing a primitive
// interface.
if (is_subclass_of($type_definition['class'], '\\Drupal\\Core\\TypedData\\PrimitiveInterface')) {
$constraints['PrimitiveType'] = [];
}
// Add in constraints specified by the data type.
if (isset($type_definition['constraints'])) {
$constraints += $type_definition['constraints'];
}
// Add the NotNull constraint for required data.
if ($definition->isRequired()) {
$constraints['NotNull'] = [];
}
// Check if the class provides allowed values.
if (is_subclass_of($definition->getClass(), 'Drupal\\Core\\TypedData\\OptionsProviderInterface')) {
$constraints['AllowedValues'] = [];
}
return $constraints;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.