You are here

class IsNullConstraintValidator in Drupal 9

Same name and namespace in other branches
  1. 8 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

Expanded class hierarchy of IsNullConstraintValidator

File

core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/IsNullConstraintValidator.php, line 16

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint
View 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

Namesort descending Modifiers Type Description Overrides
IsNullConstraintValidator::validate public function
TypedDataAwareValidatorTrait::getTypedData public function Gets the typed data object for the validated value.