RouteProcessorCurrent.php in Drupal 9
File
core/lib/Drupal/Core/RouteProcessor/RouteProcessorCurrent.php
View source
<?php
namespace Drupal\Core\RouteProcessor;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\Routing\Route;
class RouteProcessorCurrent implements OutboundRouteProcessorInterface {
protected $routeMatch;
public function __construct(RouteMatchInterface $route_match) {
$this->routeMatch = $route_match;
}
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();
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 {
$route
->setPath('/');
}
}
}
}