comparison core/modules/config_translation/src/Routing/RouteSubscriber.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\config_translation\Routing;
4
5 use Drupal\Core\Routing\RouteSubscriberBase;
6 use Drupal\config_translation\ConfigMapperManagerInterface;
7 use Drupal\Core\Routing\RoutingEvents;
8 use Symfony\Component\Routing\RouteCollection;
9
10 /**
11 * Listens to the dynamic route events.
12 */
13 class RouteSubscriber extends RouteSubscriberBase {
14
15 /**
16 * The mapper plugin discovery service.
17 *
18 * @var \Drupal\config_translation\ConfigMapperManagerInterface
19 */
20 protected $mapperManager;
21
22 /**
23 * Constructs a new RouteSubscriber.
24 *
25 * @param \Drupal\config_translation\ConfigMapperManagerInterface $mapper_manager
26 * The mapper plugin discovery service.
27 */
28 public function __construct(ConfigMapperManagerInterface $mapper_manager) {
29 $this->mapperManager = $mapper_manager;
30 }
31
32 /**
33 * {@inheritdoc}
34 */
35 protected function alterRoutes(RouteCollection $collection) {
36 $mappers = $this->mapperManager->getMappers($collection);
37
38 foreach ($mappers as $mapper) {
39 $collection->add($mapper->getOverviewRouteName(), $mapper->getOverviewRoute());
40 $collection->add($mapper->getAddRouteName(), $mapper->getAddRoute());
41 $collection->add($mapper->getEditRouteName(), $mapper->getEditRoute());
42 $collection->add($mapper->getDeleteRouteName(), $mapper->getDeleteRoute());
43 }
44 }
45
46 /**
47 * {@inheritdoc}
48 */
49 public static function getSubscribedEvents() {
50 // Come after field_ui.
51 $events[RoutingEvents::ALTER] = ['onAlterRoutes', -110];
52 return $events;
53 }
54
55 }