You are here

class EntityRevisionRouteEnhancer in Entity API 8.0

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 tests/src/Unit/RouteEnhancer/EntityRevisionRouteEnhancerTest.php
Contains \Drupal\Tests\Unit\RouteEnhancer\EntityRevisionRouteEnhancerTest.
1 string reference to 'EntityRevisionRouteEnhancer'
entity.services.yml in ./entity.services.yml
entity.services.yml
1 service uses EntityRevisionRouteEnhancer
route_enhancer.entity_revision in ./entity.services.yml
Drupal\entity\RouteEnhancer\EntityRevisionRouteEnhancer

File

src/RouteEnhancer/EntityRevisionRouteEnhancer.php, line 18
Contains \Drupal\entity\RouteEnhancer\EntityRevisionRouteEnhancer.

Namespace

Drupal\entity\RouteEnhancer
View source
class EntityRevisionRouteEnhancer implements RouteEnhancerInterface {

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {

    // Check whether there is any entity revision parameter.
    $parameters = $route
      ->getOption('parameters') ?: [];
    foreach ($parameters as $info) {
      if (isset($info['type']) && strpos($info['type'], 'entity_revision:') === 0) {
        return TRUE;
      }
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function enhance(array $defaults, Request $request) {

    /** @var \Symfony\Component\Routing\Route $route */
    $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
    $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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityRevisionRouteEnhancer::applies public function Declares if the route enhancer applies to the given route. Overrides RouteEnhancerInterface::applies
EntityRevisionRouteEnhancer::enhance public function Update the defaults based on its own data and the request.