trait TypedDataAwareValidatorTrait

Same name in other branches
  1. 9 core/lib/Drupal/Core/TypedData/Validation/TypedDataAwareValidatorTrait.php \Drupal\Core\TypedData\Validation\TypedDataAwareValidatorTrait
  2. 8.9.x core/lib/Drupal/Core/TypedData/Validation/TypedDataAwareValidatorTrait.php \Drupal\Core\TypedData\Validation\TypedDataAwareValidatorTrait
  3. 11.x core/lib/Drupal/Core/TypedData/Validation/TypedDataAwareValidatorTrait.php \Drupal\Core\TypedData\Validation\TypedDataAwareValidatorTrait

Defines a trait to access the typed data object of a validated value.

The trait assumes to be used on classes extending \Symfony\Component\Validator\ConstraintValidator.

Hierarchy

5 files declare their use of TypedDataAwareValidatorTrait
AllowedValuesConstraintValidator.php in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/AllowedValuesConstraintValidator.php
ComplexDataConstraintValidator.php in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraintValidator.php
IsNullConstraintValidator.php in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/IsNullConstraintValidator.php
NotNullConstraintValidator.php in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/NotNullConstraintValidator.php
PrimitiveTypeConstraintValidator.php in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraintValidator.php

File

core/lib/Drupal/Core/TypedData/Validation/TypedDataAwareValidatorTrait.php, line 13

Namespace

Drupal\Core\TypedData\Validation
View source
trait TypedDataAwareValidatorTrait {
    
    /**
     * Gets the typed data object for the validated value.
     *
     * @return \Drupal\Core\TypedData\TypedDataInterface
     *   The typed data object.
     */
    public function getTypedData() {
        $context = $this->context;
        
        /** @var \Symfony\Component\Validator\Context\ExecutionContextInterface $context */
        $data = $context->getObject();
        if (!$data instanceof TypedDataInterface) {
            throw new \LogicException("There is no Typed Data object available.");
        }
        return $data;
    }

}

Members

Title Sort descending Modifiers Object type Summary
TypedDataAwareValidatorTrait::getTypedData public function Gets the typed data object for the validated value.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.