EntityTypeConstraint.php 775 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Drupal\Core\Entity\Plugin\Validation\Constraint;
  3. use Symfony\Component\Validator\Constraint;
  4. /**
  5. * Checks if a value is a valid entity type.
  6. *
  7. * @Constraint(
  8. * id = "EntityType",
  9. * label = @Translation("Entity type", context = "Validation"),
  10. * type = { "entity", "entity_reference" }
  11. * )
  12. */
  13. class EntityTypeConstraint extends Constraint {
  14. /**
  15. * The default violation message.
  16. *
  17. * @var string
  18. */
  19. public $message = 'The entity must be of type %type.';
  20. /**
  21. * The entity type option.
  22. *
  23. * @var string
  24. */
  25. public $type;
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function getDefaultOption() {
  30. return 'type';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function getRequiredOptions() {
  36. return ['type'];
  37. }
  38. }