HeartbeatRouteController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Drupal\heartbeat\Routing;
  3. use Drupal\Core\Controller\ControllerBase;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Symfony\Component\Routing\Route;
  6. use Symfony\Component\Routing\RouteCollection;
  7. use Drupal\heartbeat\HeartbeatStream;
  8. use Drupal\heartbeat\HeartbeatService;
  9. use Drupal\heartbeat\HeartbeatStreamServices;
  10. use Drupal\Core\Entity\Query\QueryFactory;
  11. use Drupal\Core\Entity\EntityTypeManager;
  12. /**
  13. * Class HeartbeatRouteController.
  14. *
  15. * @package Drupal\heartbeat\Controller
  16. */
  17. class HeartbeatRouteController extends ControllerBase {
  18. /**
  19. * Drupal\heartbeat\HeartbeatService definition.
  20. *
  21. * @var \Drupal\heartbeat\HeartbeatService
  22. */
  23. protected $heartbeatService;
  24. /**
  25. * Drupal\heartbeat\HeartbeatStreamServices definition.
  26. *
  27. * @var \Drupal\heartbeat\HeartbeatStreamServices
  28. */
  29. protected $heartbeatStreamService;
  30. /**
  31. * Drupal\Core\Entity\Query\QueryFactory definition.
  32. *
  33. * @var \Drupal\Core\Entity\Query\QueryFactory
  34. */
  35. protected $entityQuery;
  36. /**
  37. * Drupal\Core\Entity\EntityTypeManager definition.
  38. *
  39. * @var \Drupal\Core\Entity\EntityTypeManager
  40. */
  41. protected $entityTypeManager;
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function __construct(HeartbeatService $heartbeatService, HeartbeatStreamServices $heartbeatStreamService, QueryFactory $entityQuery, EntityTypeManager $entityTypeManager) {
  46. $this->heartbeatService = $heartbeatService;
  47. $this->heartbeatStreamService = $heartbeatStreamService;
  48. $this->entityQuery = $entityQuery;
  49. $this->entityTypeManager = $entityTypeManager;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public static function create(ContainerInterface $container) {
  55. return new static(
  56. $container->get('heartbeat'),
  57. $container->get('heartbeatstream'),
  58. $container->get('entity.query'),
  59. $container->get('entity_type.manager')
  60. );
  61. }
  62. /**
  63. * Getroutes.
  64. *
  65. * @return string
  66. * Return Hello string.
  67. */
  68. public function getRoutes() {
  69. \Drupal::logger('HeartbeatRouteController')->debug('We getting called, yo');
  70. $routeCollection = new RouteCollection();
  71. foreach ($this->heartbeatStreamService->getAllStreams() as $heartbeatStream) {
  72. $route = new Route(
  73. $heartbeatStream->getPath()->getValue()[0]['value'],
  74. array(
  75. '_controller' => '\Drupal\heartbeat\Controller\HeartbeatStreamController::createRoute',
  76. '_title' => $heartbeatStream->getName(),
  77. 'heartbeatStreamId' => $heartbeatStream->id(),
  78. ),
  79. array(
  80. '_permission' => 'access content',
  81. )
  82. );
  83. // Add the route under the name 'example.content'.
  84. $routeCollection->add('heartbeat.' . $heartbeatStream->getName(), $route);
  85. }
  86. \Drupal::logger('HeartbeatRouteController')->debug('Data is %data', array('%data' => $routeCollection));
  87. return $routeCollection;
  88. }
  89. }