class NotNullConstraintValidator in Zircon Profile 8.0
Same name and namespace in other branches
- 8 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 \Symfony\Component\Validator\ConstraintValidator implements ConstraintValidatorInterface
- class \Symfony\Component\Validator\Constraints\NotNullValidator
- class \Drupal\Core\Validation\Plugin\Validation\Constraint\NotNullConstraintValidator uses TypedDataAwareValidatorTrait
- class \Symfony\Component\Validator\Constraints\NotNullValidator
Expanded class hierarchy of NotNullConstraintValidator
File
- core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ NotNullConstraintValidator.php, line 21 - Contains \Drupal\Core\Validation\Plugin\Validation\Constraint\NotNullConstraintValidator.
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 |
---|---|---|---|---|
ConstraintValidator:: |
protected | property | 3 | |
ConstraintValidator:: |
protected | function | Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API. | |
ConstraintValidator:: |
protected | function | Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API. | |
ConstraintValidator:: |
protected | function | Returns a string representation of the type of the value. | |
ConstraintValidator:: |
protected | function | Returns a string representation of the value. | |
ConstraintValidator:: |
protected | function | Returns a string representation of a list of values. | |
ConstraintValidator:: |
public | function |
Initializes the constraint validator. Overrides ConstraintValidatorInterface:: |
1 |
ConstraintValidator:: |
constant | Whether to cast objects with a "__toString()" method to strings. | ||
ConstraintValidator:: |
constant | Whether to format {@link \DateTime} objects as RFC-3339 dates ("Y-m-d H:i:s"). | ||
NotNullConstraintValidator:: |
public | function |
Checks if the passed value is valid. Overrides NotNullValidator:: |
|
TypedDataAwareValidatorTrait:: |
public | function | Gets the typed data object for the validated value. |