protected function RouterPathTranslatorSubscriber::findEntityTypeFromRoute in Decoupled Router 2.x
Same name and namespace in other branches
- 8 src/EventSubscriber/RouterPathTranslatorSubscriber.php \Drupal\decoupled_router\EventSubscriber\RouterPathTranslatorSubscriber::findEntityTypeFromRoute()
Extracts the entity type for the route parameters.
If there are more than one parameter, this function will return the first one.
Parameters
\Symfony\Component\Routing\Route $route: The route.
Return value
string|null The entity type ID or NULL if not found.
1 call to RouterPathTranslatorSubscriber::findEntityTypeFromRoute()
- RouterPathTranslatorSubscriber::findEntityAndKeys in src/
EventSubscriber/ RouterPathTranslatorSubscriber.php - Get the underlying entity and the type of ID param enhancer for the routes.
File
- src/
EventSubscriber/ RouterPathTranslatorSubscriber.php, line 346
Class
- RouterPathTranslatorSubscriber
- Event subscriber that processes a path translation with the router info.
Namespace
Drupal\decoupled_router\EventSubscriberCode
protected function findEntityTypeFromRoute(Route $route) {
$parameters = (array) $route
->getOption('parameters');
// Find the entity type for the first parameter that has one.
return array_reduce($parameters, function ($carry, $parameter) {
if (!$carry && !empty($parameter['type'])) {
$parts = explode(':', $parameter['type']);
// We know that the parameter is for an entity if the type is set to
// 'entity:<entity-type-id>'.
if ($parts[0] === 'entity' && !empty($parts[1])) {
$carry = $parts[1];
}
}
return $carry;
}, NULL);
}