Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NotBlankValidator.php

function NotBlankValidator::validate

Overrides ConstraintValidatorInterface::validate

File

vendor/symfony/validator/Constraints/NotBlankValidator.php, line 24

Class

NotBlankValidator
@author Bernhard Schussek <bschussek@gmail.com> @author Kévin Dunglas <dunglas@gmail.com>

Namespace

Symfony\Component\Validator\Constraints

Code

public function validate(mixed $value, Constraint $constraint) : void {
    if (!$constraint instanceof NotBlank) {
        throw new UnexpectedTypeException($constraint, NotBlank::class);
    }
    if ($constraint->allowNull && null === $value) {
        return;
    }
    if (\is_string($value) && null !== $constraint->normalizer) {
        $value = ($constraint->normalizer)($value);
    }
    if (false === $value || !$value && '0' != $value) {
        $this->context
            ->buildViolation($constraint->message)
            ->setParameter('{{ value }}', $this->formatValue($value))
            ->setCode(NotBlank::IS_BLANK_ERROR)
            ->addViolation();
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal