3 namespace Drupal\Core\RouteProcessor;
5 use Drupal\Core\Render\BubbleableMetadata;
6 use Drupal\Core\Routing\RouteMatchInterface;
7 use Symfony\Component\Routing\Route;
10 * Provides a route processor to replace <current>.
12 class RouteProcessorCurrent implements OutboundRouteProcessorInterface {
15 * The current route match.
17 * @var \Drupal\Core\Routing\RouteMatchInterface
19 protected $routeMatch;
22 * Constructs a new RouteProcessorCurrent.
24 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
25 * The current route match.
27 public function __construct(RouteMatchInterface $route_match) {
28 $this->routeMatch = $route_match;
34 public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) {
35 if ($route_name === '<current>') {
36 if ($current_route = $this->routeMatch->getRouteObject()) {
37 $requirements = $current_route->getRequirements();
38 // Setting _method and _schema is deprecated since 2.7. Using
39 // setMethods() and setSchemes() are now the recommended ways.
40 unset($requirements['_method']);
41 unset($requirements['_schema']);
42 $route->setRequirements($requirements);
44 $route->setPath($current_route->getPath());
45 $route->setSchemes($current_route->getSchemes());
46 $route->setMethods($current_route->getMethods());
47 $route->setOptions($current_route->getOptions());
48 $route->setDefaults($current_route->getDefaults());
49 $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
50 if ($bubbleable_metadata) {
51 $bubbleable_metadata->addCacheContexts(['route']);
55 // If we have no current route match available, point to the frontpage.