TypedDataMetadata.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Drupal\Core\TypedData\Validation;
  3. use Drupal\Core\TypedData\TypedDataInterface;
  4. use Symfony\Component\Validator\Exception\BadMethodCallException;
  5. use Symfony\Component\Validator\Mapping\CascadingStrategy;
  6. use Symfony\Component\Validator\Mapping\MetadataInterface;
  7. use Symfony\Component\Validator\Mapping\TraversalStrategy;
  8. use Symfony\Component\Validator\ValidationVisitorInterface;
  9. /**
  10. * Validator metadata for typed data objects.
  11. *
  12. * @see \Drupal\Core\TypedData\Validation\RecursiveValidator::getMetadataFor()
  13. */
  14. class TypedDataMetadata implements MetadataInterface {
  15. /**
  16. * The typed data object the metadata is about.
  17. *
  18. * @var \Drupal\Core\TypedData\TypedDataInterface
  19. */
  20. protected $typedData;
  21. /**
  22. * Constructs the object.
  23. *
  24. * @param \Drupal\Core\TypedData\TypedDataInterface $typed_data
  25. * The typed data object the metadata is about.
  26. */
  27. public function __construct(TypedDataInterface $typed_data) {
  28. $this->typedData = $typed_data;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function accept(ValidationVisitorInterface $visitor, $typed_data, $group, $propertyPath) {
  34. throw new BadMethodCallException('Not supported.');
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function findConstraints($group) {
  40. return $this->getConstraints();
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function getConstraints() {
  46. return $this->typedData->getConstraints();
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function getTraversalStrategy() {
  52. return TraversalStrategy::NONE;
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function getCascadingStrategy() {
  58. // By default, never cascade into validating referenced data structures.
  59. return CascadingStrategy::NONE;
  60. }
  61. }