X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FRouting%2FDrupal8%2FRouteWrapper.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FRouting%2FDrupal8%2FRouteWrapper.php;h=5266b4d54933a8abc9eb9489979e06c5b48e96ff;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Routing/Drupal8/RouteWrapper.php b/web/modules/contrib/drupalmoduleupgrader/src/Routing/Drupal8/RouteWrapper.php new file mode 100644 index 000000000..5266b4d54 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Routing/Drupal8/RouteWrapper.php @@ -0,0 +1,133 @@ +name = $name; + $this->route = $route; + $this->routeProvider = $route_provider ? $route_provider: \Drupal::service('router.route_provider'); + $this->path = new PathUtility($route->getPath()); + } + + /** + * Forwards unknown function calls to the wrapped Route. + */ + public function __call($method, array $arguments) { + return call_user_func_array([ $this->route, $method ], $arguments); + } + + /** + * {@inheritdoc} + */ + public function getIdentifier() { + return $this->name; + } + + /** + * {@inheritdoc} + */ + public function getPath() { + return $this->path; + } + + /** + * {@inheritdoc} + */ + public function hasParent() { + return isset($this->parent); + } + + /** + * {@inheritdoc} + */ + public function getParent() { + return $this->parent; + } + + /** + * {@inheritdoc} + */ + public function unwrap() { + return $this->route; + } + + /** + * {@inheritdoc} + */ + public function onRouterBuilt(RouterBuiltEvent $event) { + $this->router = $event->getRouter(); + + try { + $parent = $this->getPath()->getParent()->__toString(); + } + catch (\LengthException $e) { + return; + } + + // First, search the injected router for the parent route. + foreach ($this->router as $route) { + if ($route->getPath() == $parent) { + $this->parent = $route; + } + } + + // Next, search the core route provider if no parent was found. + if (empty($this->parent)) { + $parents = $this->routeProvider->getRoutesByPattern($parent)->getIterator(); + + if (sizeof($parents) > 0) { + $this->parent = new static($parents->key(), $parents->current(), $this->routeProvider); + } + } + } + +}