class EntityRevisionRouteEnhancer

Same name in other branches
  1. 9 core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php \Drupal\Core\Routing\Enhancer\EntityRevisionRouteEnhancer
  2. 8.9.x core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php \Drupal\Core\Routing\Enhancer\EntityRevisionRouteEnhancer
  3. 11.x core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php \Drupal\Core\Routing\Enhancer\EntityRevisionRouteEnhancer

Adds _entity_revision to the request attributes, if possible.

Hierarchy

Expanded class hierarchy of EntityRevisionRouteEnhancer

1 file declares its use of EntityRevisionRouteEnhancer
EntityRevisionRouteEnhancerTest.php in core/tests/Drupal/Tests/Core/Enhancer/EntityRevisionRouteEnhancerTest.php
1 string reference to 'EntityRevisionRouteEnhancer'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses EntityRevisionRouteEnhancer
route_enhancer.entity_revision in core/core.services.yml
Drupal\Core\Routing\Enhancer\EntityRevisionRouteEnhancer

File

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

Namespace

Drupal\Core\Routing\Enhancer
View source
class EntityRevisionRouteEnhancer implements EnhancerInterface {
    
    /**
     * Returns whether the enhancer runs on the current route.
     *
     * @param \Symfony\Component\Routing\Route $route
     *   The current route.
     *
     * @return bool
     */
    protected function applies(Route $route) {
        // Check whether there is any entity revision parameter.
        $parameters = $route->getOption('parameters') ?: [];
        foreach ($parameters as $info) {
            if (isset($info['type']) && str_starts_with($info['type'], 'entity_revision:')) {
                return TRUE;
            }
        }
        return FALSE;
    }
    
    /**
     * {@inheritdoc}
     */
    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']) && str_contains($details['type'], 'entity_revision:')) {
                    $defaults['_entity_revision'] = $defaults[$name];
                    break;
                }
            }
        }
        return $defaults;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
EntityRevisionRouteEnhancer::applies protected function Returns whether the enhancer runs on the current route.
EntityRevisionRouteEnhancer::enhance public function Updates the defaults for a route definition based on the request. Overrides EnhancerInterface::enhance

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.