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