class EntityRevisionRouteEnhancer in Entity API 8.0
Adds _entity_revision to the request attributes, if possible.
Hierarchy
- class \Drupal\entity\RouteEnhancer\EntityRevisionRouteEnhancer implements RouteEnhancerInterface
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'
1 service uses EntityRevisionRouteEnhancer
File
- src/
RouteEnhancer/ EntityRevisionRouteEnhancer.php, line 18 - Contains \Drupal\entity\RouteEnhancer\EntityRevisionRouteEnhancer.
Namespace
Drupal\entity\RouteEnhancerView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityRevisionRouteEnhancer:: |
public | function |
Declares if the route enhancer applies to the given route. Overrides RouteEnhancerInterface:: |
|
EntityRevisionRouteEnhancer:: |
public | function | Update the defaults based on its own data and the request. |