comparison core/modules/layout_builder/src/Routing/LayoutBuilderRoutes.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children af1871eacc83
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2
3 namespace Drupal\layout_builder\Routing;
4
5 use Drupal\Core\Routing\RouteBuildEvent;
6 use Drupal\Core\Routing\RoutingEvents;
7 use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10 /**
11 * Provides routes for the Layout Builder UI.
12 *
13 * @internal
14 */
15 class LayoutBuilderRoutes implements EventSubscriberInterface {
16
17 /**
18 * The section storage manager.
19 *
20 * @var \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface
21 */
22 protected $sectionStorageManager;
23
24 /**
25 * Constructs a new LayoutBuilderRoutes.
26 *
27 * @param \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface $section_storage_manager
28 * The section storage manager.
29 */
30 public function __construct(SectionStorageManagerInterface $section_storage_manager) {
31 $this->sectionStorageManager = $section_storage_manager;
32 }
33
34 /**
35 * Alters existing routes for a specific collection.
36 *
37 * @param \Drupal\Core\Routing\RouteBuildEvent $event
38 * The route build event.
39 */
40 public function onAlterRoutes(RouteBuildEvent $event) {
41 $collection = $event->getRouteCollection();
42 foreach ($this->sectionStorageManager->getDefinitions() as $plugin_id => $definition) {
43 $this->sectionStorageManager->loadEmpty($plugin_id)->buildRoutes($collection);
44 }
45 }
46
47 /**
48 * {@inheritdoc}
49 */
50 public static function getSubscribedEvents() {
51 // Run after \Drupal\field_ui\Routing\RouteSubscriber.
52 $events[RoutingEvents::ALTER] = ['onAlterRoutes', -110];
53 return $events;
54 }
55
56 }