3 namespace Drupal\Core\Routing\Enhancer;
5 use Drupal\Core\Routing\EnhancerInterface;
6 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\Routing\Route;
11 * Adds _entity_revision to the request attributes, if possible.
13 class EntityRevisionRouteEnhancer implements EnhancerInterface {
16 * Returns whether the enhancer runs on the current route.
18 * @param \Symfony\Component\Routing\Route $route
23 protected function applies(Route $route) {
24 // Check whether there is any entity revision parameter.
25 $parameters = $route->getOption('parameters') ?: [];
26 foreach ($parameters as $info) {
27 if (isset($info['type']) && strpos($info['type'], 'entity_revision:') === 0) {
37 public function enhance(array $defaults, Request $request) {
38 /** @var \Symfony\Component\Routing\Route $route */
39 $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
40 if (!$this->applies($route)) {
44 $options = $route->getOptions();
45 if (isset($options['parameters'])) {
46 foreach ($options['parameters'] as $name => $details) {
47 if (!empty($details['type']) && strpos($details['type'], 'entity_revision:') !== FALSE) {
48 $defaults['_entity_revision'] = $defaults[$name];