HeartbeatStreamServices.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Drupal\heartbeat8;
  3. use Drupal\Core\Entity\EntityTypeManager;
  4. use Drupal\Core\Entity\EntityTypeRepository;
  5. use Drupal\Core\Entity\Query\QueryFactory;
  6. /**
  7. * Class HeartbeatStreamServices.
  8. *
  9. * @package Drupal\heartbeat8
  10. */
  11. class HeartbeatStreamServices {
  12. /**
  13. * Drupal\Core\Entity\EntityTypeManager definition.
  14. *
  15. * @var EntityTypeManager
  16. */
  17. protected $entityTypeManager;
  18. /**
  19. * Drupal\Core\Entity\EntityTypeRepository definition.
  20. *
  21. * @var EntityTypeRepository
  22. */
  23. protected $entityTypeRepository;
  24. /**
  25. * Drupal\Core\Entity\Query\QueryFactory definition.
  26. *
  27. * @var \Drupal\Core\Entity\Query\QueryFactory
  28. */
  29. protected $entityQuery;
  30. /**
  31. * Constructor.
  32. * @param EntityTypeManager $entityTypeManager
  33. * @param EntityTypeRepository $entityTypeRepository
  34. * @param QueryFactory $entityQuery
  35. */
  36. public function __construct(EntityTypeManager $entityTypeManager, EntityTypeRepository $entityTypeRepository, QueryFactory $entityQuery) {
  37. $this->entityTypeManager = $entityTypeManager;
  38. $this->entityTypeRepository = $entityTypeRepository;
  39. $this->entityQuery = $entityQuery;
  40. }
  41. /**
  42. * Returns a loaded HeartbeatStream entity
  43. * @param $id
  44. * @return \Drupal\Core\Entity\EntityInterface|null
  45. * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
  46. */
  47. public function getEntityById($id) {
  48. return $this->entityTypeManager->getStorage('heartbeat_stream')->load($id);
  49. }
  50. /**
  51. * Returns an array of HeartbeatType strings for a given
  52. * HeartbeatStream specified by ID
  53. * @param $id
  54. * @return mixed
  55. * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
  56. */
  57. public function getTypesById($id) {
  58. return $this->entityTypeManager->getStorage('heartbeat_stream')->load($id)->get('types');
  59. }
  60. /**
  61. * Returns an array of HeartbeatStream entities
  62. * HeartbeatStream specified by ID
  63. * @return mixed
  64. */
  65. public function loadAllEntities() {
  66. $jigga = $this->entityQuery->get('heartbeat_stream');
  67. $jiggais =' nada';
  68. return $jigga;
  69. }
  70. }