EntityType.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Drupal\Core\Entity\Annotation;
  3. use Drupal\Component\Annotation\Plugin;
  4. use Drupal\Core\StringTranslation\StringTranslationTrait;
  5. /**
  6. * Defines an Entity type annotation object.
  7. *
  8. * Entity type plugins use an object-based annotation method, rather than an
  9. * array-type annotation method (as commonly used on other annotation types).
  10. * The annotation properties of entity types are found on
  11. * \Drupal\Core\Entity\EntityType and are accessed using get/set methods defined
  12. * in \Drupal\Core\Entity\EntityTypeInterface.
  13. *
  14. * @ingroup entity_api
  15. *
  16. * @Annotation
  17. */
  18. class EntityType extends Plugin {
  19. use StringTranslationTrait;
  20. /**
  21. * The class used to represent the entity type.
  22. *
  23. * It must implement \Drupal\Core\Entity\EntityTypeInterface.
  24. *
  25. * @var string
  26. */
  27. public $entity_type_class = 'Drupal\Core\Entity\EntityType';
  28. /**
  29. * The group machine name.
  30. *
  31. * @var string
  32. */
  33. public $group = 'default';
  34. /**
  35. * The group label.
  36. *
  37. * @var \Drupal\Core\Annotation\Translation
  38. *
  39. * @ingroup plugin_translatable
  40. */
  41. public $group_label = '';
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function get() {
  46. $values = $this->definition;
  47. // Use the specified entity type class, and remove it before instantiating.
  48. $class = $values['entity_type_class'];
  49. unset($values['entity_type_class']);
  50. return new $class($values);
  51. }
  52. }