3 namespace Drupal\Core\TypedData\Validation;
5 use Drupal\Core\TypedData\TypedDataInterface;
8 * Defines a trait to access the typed data object of a validated value.
10 * The trait assumes to be used on classes extending
11 * \Symfony\Component\Validator\ConstraintValidator.
13 trait TypedDataAwareValidatorTrait {
16 * Gets the typed data object for the validated value.
18 * @return \Drupal\Core\TypedData\TypedDataInterface
19 * The typed data object.
21 public function getTypedData() {
22 $context = $this->context;
23 /** @var \Symfony\Component\Validator\Context\ExecutionContextInterface $context */
24 $data = $context->getObject();
25 if (!$data instanceof TypedDataInterface) {
26 throw new \LogicException("There is no Typed Data object available.");