"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/IsNullConstraintValidator.php" (26 Nov 2020, 877 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "IsNullConstraintValidator.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\Core\Validation\Plugin\Validation\Constraint;
    4 
    5 use Drupal\Core\TypedData\ComplexDataInterface;
    6 use Drupal\Core\TypedData\ListInterface;
    7 use Drupal\Core\TypedData\Validation\TypedDataAwareValidatorTrait;
    8 use Symfony\Component\Validator\Constraint;
    9 use Symfony\Component\Validator\Constraints\IsNullValidator;
   10 
   11 /**
   12  * Null constraint validator.
   13  *
   14  * Overrides the symfony validator to handle empty Typed Data structures.
   15  */
   16 class IsNullConstraintValidator extends IsNullValidator {
   17 
   18   use TypedDataAwareValidatorTrait;
   19 
   20   /**
   21    * {@inheritdoc}
   22    */
   23   public function validate($value, Constraint $constraint) {
   24     $typed_data = $this->getTypedData();
   25     if (($typed_data instanceof ListInterface || $typed_data instanceof ComplexDataInterface) && $typed_data->isEmpty()) {
   26       $value = NULL;
   27     }
   28     parent::validate($value, $constraint);
   29   }
   30 
   31 }