Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / layout_builder / src / Routing / LayoutBuilderRoutes.php
diff --git a/web/core/modules/layout_builder/src/Routing/LayoutBuilderRoutes.php b/web/core/modules/layout_builder/src/Routing/LayoutBuilderRoutes.php
new file mode 100644 (file)
index 0000000..1046579
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+namespace Drupal\layout_builder\Routing;
+
+use Drupal\Core\Routing\RouteBuildEvent;
+use Drupal\Core\Routing\RoutingEvents;
+use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Provides routes for the Layout Builder UI.
+ *
+ * @internal
+ */
+class LayoutBuilderRoutes implements EventSubscriberInterface {
+
+  /**
+   * The section storage manager.
+   *
+   * @var \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface
+   */
+  protected $sectionStorageManager;
+
+  /**
+   * Constructs a new LayoutBuilderRoutes.
+   *
+   * @param \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface $section_storage_manager
+   *   The section storage manager.
+   */
+  public function __construct(SectionStorageManagerInterface $section_storage_manager) {
+    $this->sectionStorageManager = $section_storage_manager;
+  }
+
+  /**
+   * Alters existing routes for a specific collection.
+   *
+   * @param \Drupal\Core\Routing\RouteBuildEvent $event
+   *   The route build event.
+   */
+  public function onAlterRoutes(RouteBuildEvent $event) {
+    $collection = $event->getRouteCollection();
+    foreach ($this->sectionStorageManager->getDefinitions() as $plugin_id => $definition) {
+      $this->sectionStorageManager->loadEmpty($plugin_id)->buildRoutes($collection);
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    // Run after \Drupal\field_ui\Routing\RouteSubscriber.
+    $events[RoutingEvents::ALTER] = ['onAlterRoutes', -110];
+    return $events;
+  }
+
+}