public function RouteProcessorCurrent::processOutbound

public RouteProcessorCurrent::processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL)

Processes the outbound route.

Parameters

string $route_name: The route name.

\Symfony\Component\Routing\Route $route: The outbound route to process.

array $parameters: An array of parameters to be passed to the route compiler. Passed by reference.

\Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata: (optional) Object to collect route processors' bubbleable metadata.

Return value

The processed path.

Overrides OutboundRouteProcessorInterface::processOutbound

File

core/lib/Drupal/Core/RouteProcessor/RouteProcessorCurrent.php, line 34

Class

RouteProcessorCurrent
Provides a route processor to replace <current>.

Namespace

Drupal\Core\RouteProcessor

Code

public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) {
  if ($route_name === '<current>') {
    if ($current_route = $this->routeMatch->getRouteObject()) {
      $requirements = $current_route->getRequirements();
      // Setting _method and _schema is deprecated since 2.7. Using
      // setMethods() and setSchemes() are now the recommended ways.
      unset($requirements['_method']);
      unset($requirements['_schema']);
      $route->setRequirements($requirements);

      $route->setPath($current_route->getPath());
      $route->setSchemes($current_route->getSchemes());
      $route->setMethods($current_route->getMethods());
      $route->setOptions($current_route->getOptions());
      $route->setDefaults($current_route->getDefaults());
      $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
      if ($bubbleable_metadata) {
        $bubbleable_metadata->addCacheContexts(['route']);
      }
    }
    else {
      // If we have no current route match available, point to the frontpage.
      $route->setPath('/');
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!RouteProcessor!RouteProcessorCurrent.php/function/RouteProcessorCurrent::processOutbound/8.1.x