HeartbeatTypeServices.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Drupal\heartbeat;
  3. use Drupal\Core\Entity\ContentEntityType;
  4. use Drupal\Core\Entity\EntityTypeManager;
  5. use Drupal\Core\Entity\EntityTypeBundleInfo;
  6. use Drupal\Core\Entity\Query\QueryFactory;
  7. /**
  8. * Class HeartbeatTypeServices.
  9. *
  10. * @package Drupal\heartbeat
  11. */
  12. class HeartbeatTypeServices {
  13. /**
  14. * Drupal\Core\Entity\EntityTypeManager definition.
  15. *
  16. * @var EntityTypeManager
  17. */
  18. protected $entityTypeManager;
  19. /**
  20. + * Drupal\Core\Entity\EntityTypeBundleInfo definition.
  21. + *
  22. + * @var EntityTypeBundleInfo
  23. + */
  24. protected $entityTypeBundleInfo;
  25. /**
  26. * Drupal\Core\Entity\Query\QueryFactory definition.
  27. *
  28. * @var \Drupal\Core\Entity\Query\QueryFactory
  29. */
  30. protected $entityQuery;
  31. /**
  32. * Constructor.
  33. * @param EntityTypeManager $entityTypeManager
  34. * @param EntityTypeBundleInfo $entityTypeBundleInfo
  35. * @param QueryFactory $entity_query
  36. */
  37. public function __construct(EntityTypeManager $entityTypeManager, EntityTypeBundleInfo $entityTypeBundleInfo, QueryFactory $entity_query) {
  38. $this->entityTypeManager = $entityTypeManager;
  39. $this->entityTypeBundleInfo = $entityTypeBundleInfo;
  40. $this->entityQuery = $entity_query;
  41. }
  42. public function getTypes() {
  43. return $this->entityQuery->get('heartbeat_type')->sort('weight', 'ASC')->execute();
  44. }
  45. public function load($id) {
  46. return $this->entityTypeManager->getStorage('heartbeat_type')->load($id);
  47. }
  48. public function getEntityBundles(ContentEntityType $entity) {
  49. return $this->entityTypeBundleInfo->getBundleInfo($entity->id());
  50. }
  51. }