EntityRevisionRouteEnhancer.php in Entity API 8.0
File
src/RouteEnhancer/EntityRevisionRouteEnhancer.php
View source
<?php
namespace Drupal\entity\RouteEnhancer;
use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
class EntityRevisionRouteEnhancer implements RouteEnhancerInterface {
public function applies(Route $route) {
$parameters = $route
->getOption('parameters') ?: [];
foreach ($parameters as $info) {
if (isset($info['type']) && strpos($info['type'], 'entity_revision:') === 0) {
return TRUE;
}
}
return FALSE;
}
public function enhance(array $defaults, Request $request) {
$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;
}
}