View source
<?php
namespace Drupal\rng\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\rng\EventManagerInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class RouteSubscriber extends RouteSubscriberBase {
protected $entityManager;
protected $eventManager;
public function __construct(EntityManagerInterface $entity_manager, EventManagerInterface $event_manager) {
$this->entityManager = $entity_manager;
$this->eventManager = $event_manager;
}
protected function alterRoutes(RouteCollection $collection) {
$event_types = $this->eventManager
->getEventTypes();
foreach (array_keys($event_types) as $entity_type) {
$definition = $this->entityManager
->getDefinition($entity_type);
if ($canonical_path = $definition
->getLinkTemplate('canonical')) {
$manage_requirements = [
'_entity_access' => $entity_type . '.manage event',
'_entity_is_event' => 'TRUE',
];
$options = [];
$options['parameters'][$entity_type]['type'] = 'entity:' . $entity_type;
$options_register = $options;
$options['_admin_route'] = 'TRUE';
$route = new Route($canonical_path . '/event', array(
'_form' => '\\Drupal\\rng\\Form\\EventSettingsForm',
'_title' => 'Manage event',
'event' => $entity_type,
), $manage_requirements, $options);
$collection
->add("rng.event.{$entity_type}.event", $route);
$route = new Route($canonical_path . '/event/access', [
'_form' => '\\Drupal\\rng\\Form\\EventAccessForm',
'_title' => 'Access',
'event' => $entity_type,
], $manage_requirements, $options);
$collection
->add("rng.event.{$entity_type}.access", $route);
$route = new Route($canonical_path . '/event/access/reset', array(
'_form' => '\\Drupal\\rng\\Form\\EventAccessResetForm',
'_title' => 'Reset access to default',
'event' => $entity_type,
), $manage_requirements + [
'_event_rule_reset' => 'TRUE',
], $options);
$collection
->add("rng.event.{$entity_type}.access.reset", $route);
$route = new Route($canonical_path . '/event/messages', array(
'_form' => '\\Drupal\\rng\\Form\\MessageListForm',
'_title' => 'Messages',
'event' => $entity_type,
), $manage_requirements, $options);
$collection
->add("rng.event.{$entity_type}.messages", $route);
$route = new Route($canonical_path . '/event/messages/add', array(
'_form' => '\\Drupal\\rng\\Form\\MessageActionForm',
'_title' => 'Add message',
'event' => $entity_type,
), $manage_requirements, $options);
$collection
->add("rng.event.{$entity_type}.messages.add", $route);
$route = new Route($canonical_path . '/event/groups', array(
'_controller' => '\\Drupal\\rng\\Controller\\GroupController::listing',
'_title' => 'Groups',
'event' => $entity_type,
), $manage_requirements, $options);
$collection
->add("rng.event.{$entity_type}.group.list", $route);
$route = new Route($canonical_path . '/event/groups/add', array(
'_controller' => '\\Drupal\\rng\\Controller\\GroupController::GroupAdd',
'_title' => 'Add group',
'event' => $entity_type,
), $manage_requirements, $options);
$collection
->add("rng.event.{$entity_type}.group.add", $route);
$route = new Route($canonical_path . '/register', array(
'_controller' => '\\Drupal\\rng\\Controller\\RegistrationController::RegistrationAddPage',
'_title' => 'Register',
'event' => $entity_type,
), array(
'_registration_add_access' => 'TRUE',
), $options_register);
$collection
->add("rng.event.{$entity_type}.register.type_list", $route);
$options_register['parameters']['registration_type']['type'] = 'entity:registration_type';
$route = new Route($canonical_path . '/register/{registration_type}', array(
'_controller' => '\\Drupal\\rng\\Controller\\RegistrationController::RegistrationAdd',
'_title_callback' => '\\Drupal\\rng\\Controller\\RegistrationController::addPageTitle',
'event' => $entity_type,
), array(
'_registration_add_access' => 'TRUE',
), $options_register);
$collection
->add("rng.event.{$entity_type}.register", $route);
}
}
}
}