class NotNullConstraintValidator in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/NotNullConstraintValidator.php \Drupal\Core\Validation\Plugin\Validation\Constraint\NotNullConstraintValidator
NotNull constraint validator.
Overrides the symfony validator to handle empty Typed Data structures.
Hierarchy
- class \Drupal\Core\Validation\Plugin\Validation\Constraint\NotNullConstraintValidator extends \Symfony\Component\Validator\Constraints\NotNullValidator uses TypedDataAwareValidatorTrait
Expanded class hierarchy of NotNullConstraintValidator
File
- core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ NotNullConstraintValidator.php, line 16
Namespace
Drupal\Core\Validation\Plugin\Validation\ConstraintView source
class NotNullConstraintValidator extends NotNullValidator {
use TypedDataAwareValidatorTrait;
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
$typed_data = $this
->getTypedData();
if (($typed_data instanceof ListInterface || $typed_data instanceof ComplexDataInterface) && $typed_data
->isEmpty()) {
$value = NULL;
}
parent::validate($value, $constraint);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NotNullConstraintValidator:: |
public | function | Checks if the passed value is valid. | |
TypedDataAwareValidatorTrait:: |
public | function | Gets the typed data object for the validated value. |