class IsNullConstraintValidator in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/IsNullConstraintValidator.php \Drupal\Core\Validation\Plugin\Validation\Constraint\IsNullConstraintValidator
Null 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\IsNullValidator
- class \Drupal\Core\Validation\Plugin\Validation\Constraint\IsNullConstraintValidator uses TypedDataAwareValidatorTrait
- class \Symfony\Component\Validator\Constraints\IsNullValidator
Expanded class hierarchy of IsNullConstraintValidator
File
- core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ IsNullConstraintValidator.php, line 21 - Contains \Drupal\Core\Validation\Plugin\Validation\Constraint\IsNullConstraintValidator.
Namespace
Drupal\Core\Validation\Plugin\Validation\ConstraintView source
class IsNullConstraintValidator extends IsNullValidator {
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"). | ||
IsNullConstraintValidator:: |
public | function |
Checks if the passed value is valid. Overrides IsNullValidator:: |
|
TypedDataAwareValidatorTrait:: |
public | function | Gets the typed data object for the validated value. |