5 * Contains \Drupal\drupalmoduleupgrader\Converter\Routing\Drupal8\Route.
8 namespace Drupal\drupalmoduleupgrader\Routing\Drupal8;
10 use Drupal\Core\Routing\RouteProviderInterface;
11 use Drupal\drupalmoduleupgrader\Routing\RouterBuiltEvent;
12 use Drupal\drupalmoduleupgrader\Routing\RouteWrapperInterface;
13 use Drupal\drupalmoduleupgrader\Utility\Path\Drupal8\PathUtility;
14 use Symfony\Component\Routing\Route;
17 * Wraps around a Symfony Route object, providing helper methods.
19 class RouteWrapper implements RouteWrapperInterface {
27 * @var \Symfony\Component\Routing\Route
32 * @var \Drupal\drupalmoduleupgrader\Utility\Path\Drupal8\PathUtility
37 * @var \Drupal\Core\Routing\RouteProviderInterface
39 protected $routeProvider;
42 * @var \Symfony\Component\Routing\RouteCollection
52 * Constructs a Route object.
54 public function __construct($name, Route $route, RouteProviderInterface $route_provider) {
56 $this->route = $route;
57 $this->routeProvider = $route_provider ? $route_provider: \Drupal::service('router.route_provider');
58 $this->path = new PathUtility($route->getPath());
62 * Forwards unknown function calls to the wrapped Route.
64 public function __call($method, array $arguments) {
65 return call_user_func_array([ $this->route, $method ], $arguments);
71 public function getIdentifier() {
78 public function getPath() {
85 public function hasParent() {
86 return isset($this->parent);
92 public function getParent() {
99 public function unwrap() {
106 public function onRouterBuilt(RouterBuiltEvent $event) {
107 $this->router = $event->getRouter();
110 $parent = $this->getPath()->getParent()->__toString();
112 catch (\LengthException $e) {
116 // First, search the injected router for the parent route.
117 foreach ($this->router as $route) {
118 if ($route->getPath() == $parent) {
119 $this->parent = $route;
123 // Next, search the core route provider if no parent was found.
124 if (empty($this->parent)) {
125 $parents = $this->routeProvider->getRoutesByPattern($parent)->getIterator();
127 if (sizeof($parents) > 0) {
128 $this->parent = new static($parents->key(), $parents->current(), $this->routeProvider);