HeartbeatRouteController.php in Heartbeat 8
File
src/Routing/HeartbeatRouteController.php
View source
<?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 extends ControllerBase {
protected $heartbeatService;
protected $heartbeatStreamService;
protected $entityQuery;
protected $entityTypeManager;
public function __construct(HeartbeatService $heartbeatService, HeartbeatStreamServices $heartbeatStreamService, QueryFactory $entityQuery, EntityTypeManager $entityTypeManager) {
$this->heartbeatService = $heartbeatService;
$this->heartbeatStreamService = $heartbeatStreamService;
$this->entityQuery = $entityQuery;
$this->entityTypeManager = $entityTypeManager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('heartbeat'), $container
->get('heartbeatstream'), $container
->get('entity.query'), $container
->get('entity_type.manager'));
}
public function getRoutes() {
$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',
));
$routeCollection
->add('heartbeat.' . $heartbeatStream
->getName(), $route);
}
\Drupal::logger('HeartbeatRouteController')
->debug('Data is %data', array(
'%data' => $routeCollection,
));
return $routeCollection;
}
}