diff --git a/core/core.services.yml b/core/core.services.yml index 7b31378..ca2887a 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -848,7 +848,7 @@ services: deprecated: The "%service_id%" service is deprecated. You should use the 'router.no_access_checks' service instead. router.no_access_checks: class: \Drupal\Core\Routing\Router - arguments: ['@router.route_provider', '@path.current'] + arguments: ['@router.route_provider', '@path.current', '@url_generator'] tags: - { name: service_collector, tag: non_lazy_route_enhancer, call: addRouteEnhancer } - { name: service_collector, tag: non_lazy_route_filter, call: addRouteFilter } diff --git a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php index 14dc492..c332fab 100644 --- a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php +++ b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php @@ -10,6 +10,7 @@ use Symfony\Component\Routing\Matcher\RequestMatcherInterface; use Symfony\Component\Routing\RequestContext as SymfonyRequestContext; use Symfony\Component\Routing\RequestContextAwareInterface; +use Symfony\Component\Routing\RouterInterface; /** * A router class for Drupal with access check and upcasting. @@ -57,11 +58,8 @@ public function __construct(RequestMatcherInterface $router, AccessManagerInterf * {@inheritdoc} */ public function __call($name, $arguments) { - // Ensure to call every other function to the inner router. - if (method_exists($this->router, $name)) { - return call_user_func_array([$this->router, $name], $arguments); - } - throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", $name)); + // Ensure to call every other function to the router. + return call_user_func_array([$this->router, $name], $arguments); } /** @@ -121,14 +119,18 @@ protected function checkAccess(Request $request) { * {@inheritdoc} */ public function getRouteCollection() { - throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__)); + if ($this->router instanceof RouterInterface) { + return $this->router->getRouteCollection(); + } } /** * {@inheritdoc} */ public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { - throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__)); + if ($this->router instanceof RouterInterface) { + return $this->router->generate($name, $parameters, $referenceType); + } } /** diff --git a/core/lib/Drupal/Core/Routing/Router.php b/core/lib/Drupal/Core/Routing/Router.php index f26bd99..aab9df3 100644 --- a/core/lib/Drupal/Core/Routing/Router.php +++ b/core/lib/Drupal/Core/Routing/Router.php @@ -4,13 +4,16 @@ use Drupal\Core\Path\CurrentPathStack; use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface as BaseRouteEnhancerInterface; +use Symfony\Cmf\Component\Routing\LazyRouteCollection; use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface as BaseRouteFilterInterface; use Symfony\Cmf\Component\Routing\RouteProviderInterface as BaseRouteProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Matcher\RequestMatcherInterface; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\RouterInterface; /** * Central router implementation in Drupal. @@ -35,7 +38,7 @@ * @see \Drupal\Core\Routing\UrlMatcher * @see \Symfony\Cmf\Component\Routing\NestedMatcher\NestedMatcher */ -class Router extends UrlMatcher implements RequestMatcherInterface { +class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterface { /** * The route provider responsible for the first-pass match. @@ -71,16 +74,26 @@ class Router extends UrlMatcher implements RequestMatcherInterface { protected $sortedFilters; /** + * The URL generator. + * + * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface + */ + protected $urlGenerator; + + /** * Constructs a new Router. * * @param \Symfony\Cmf\Component\Routing\RouteProviderInterface $route_provider * The route provider. * @param \Drupal\Core\Path\CurrentPathStack $current_path - * The current path stuack. + * The current path stack. + * @param \Symfony\Component\Routing\Generator\UrlGeneratorInterface $url_generator + * The URL generator. */ - public function __construct(BaseRouteProviderInterface $route_provider, CurrentPathStack $current_path) { + public function __construct(BaseRouteProviderInterface $route_provider, CurrentPathStack $current_path, UrlGeneratorInterface $url_generator) { parent::__construct($current_path); $this->routeProvider = $route_provider; + $this->urlGenerator = $url_generator; } /** @@ -265,4 +278,19 @@ protected function sortFilters() { return $sortedFilters; } + /** + * {@inheritdoc} + */ + public function getRouteCollection() { + return new LazyRouteCollection($this->routeProvider); + } + + /** + * {@inheritdoc} + */ + public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { + @trigger_error('Use the \Drupal\Core\Url object instead', E_USER_DEPRECATED); + return $this->urlGenerator->generate($name, $parameters, $referenceType); + } + }