123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace Drupal\heartbeat\Routing;
- use Drupal\Core\Controller\ControllerBase;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- use Symfony\Component\Routing\Route;
- use Symfony\Component\Routing\RouteCollection;
- use Drupal\heartbeat\HeartbeatStream;
- use Drupal\heartbeat\HeartbeatService;
- use Drupal\heartbeat\HeartbeatStreamServices;
- use Drupal\Core\Entity\Query\QueryFactory;
- use Drupal\Core\Entity\EntityTypeManager;
- /**
- * Class HeartbeatRouteController.
- *
- * @package Drupal\heartbeat\Controller
- */
- class HeartbeatRouteController extends ControllerBase {
- /**
- * Drupal\heartbeat\HeartbeatService definition.
- *
- * @var \Drupal\heartbeat\HeartbeatService
- */
- protected $heartbeatService;
- /**
- * Drupal\heartbeat\HeartbeatStreamServices definition.
- *
- * @var \Drupal\heartbeat\HeartbeatStreamServices
- */
- protected $heartbeatStreamService;
- /**
- * Drupal\Core\Entity\Query\QueryFactory definition.
- *
- * @var \Drupal\Core\Entity\Query\QueryFactory
- */
- protected $entityQuery;
- /**
- * Drupal\Core\Entity\EntityTypeManager definition.
- *
- * @var \Drupal\Core\Entity\EntityTypeManager
- */
- protected $entityTypeManager;
- /**
- * {@inheritdoc}
- */
- public function __construct(HeartbeatService $heartbeatService, HeartbeatStreamServices $heartbeatStreamService, QueryFactory $entityQuery, EntityTypeManager $entityTypeManager) {
- $this->heartbeatService = $heartbeatService;
- $this->heartbeatStreamService = $heartbeatStreamService;
- $this->entityQuery = $entityQuery;
- $this->entityTypeManager = $entityTypeManager;
- }
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container) {
- return new static(
- $container->get('heartbeat'),
- $container->get('heartbeatstream'),
- $container->get('entity.query'),
- $container->get('entity_type.manager')
- );
- }
- /**
- * Getroutes.
- *
- * @return string
- * Return Hello string.
- */
- public function getRoutes() {
- \Drupal::logger('HeartbeatRouteController')->debug('We getting called, yo');
- $routeCollection = new RouteCollection();
- foreach ($this->heartbeatStreamService->getAllStreams() as $heartbeatStream) {
- $route = new Route(
- $heartbeatStream->getPath()->getValue()[0]['value'],
- array(
- '_controller' => '\Drupal\heartbeat\Controller\HeartbeatStreamController::createRoute',
- '_title' => $heartbeatStream->getName(),
- 'heartbeatStreamId' => $heartbeatStream->id(),
- ),
- array(
- '_permission' => 'access content',
- )
- );
- // Add the route under the name 'example.content'.
- $routeCollection->add('heartbeat.' . $heartbeatStream->getName(), $route);
- }
- \Drupal::logger('HeartbeatRouteController')->debug('Data is %data', array('%data' => $routeCollection));
- return $routeCollection;
- }
- }
|