You are here

public function EntityRevisionRouteEnhancer::enhance in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php \Drupal\Core\Routing\Enhancer\EntityRevisionRouteEnhancer::enhance()

Updates the defaults for a route definition based on the request.

Parameters

array $defaults: The defaults, maps to '_defaults' in the route definition YAML.

\Symfony\Component\HttpFoundation\Request $request: The Request instance.

Return value

array The modified defaults. Each enhancer MUST return the $defaults but may add or remove values.

Overrides EnhancerInterface::enhance

File

core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php, line 37

Class

EntityRevisionRouteEnhancer
Adds _entity_revision to the request attributes, if possible.

Namespace

Drupal\Core\Routing\Enhancer

Code

public function enhance(array $defaults, Request $request) {

  /** @var \Symfony\Component\Routing\Route $route */
  $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
  if (!$this
    ->applies($route)) {
    return $defaults;
  }
  $options = $route
    ->getOptions();
  if (isset($options['parameters'])) {
    foreach ($options['parameters'] as $name => $details) {
      if (!empty($details['type']) && strpos($details['type'], 'entity_revision:') !== FALSE) {
        $defaults['_entity_revision'] = $defaults[$name];
        break;
      }
    }
  }
  return $defaults;
}