Get the route based on the $name that is a RouteAwareInterface or a RouteAwareInterface content found in the content repository with the content_id specified in parameters.
Called in generate when there is no route given in the parameters.
If there is more than one route for the content, tries to find the first one that matches the _locale (provided in $parameters or otherwise defaulting to the request locale).
If no route with matching locale is found, falls back to just return the first route.
mixed $name:
array $parameters which should contain a content field containing a RouteAwareInterface object:
SymfonyRoute the route instance
RouteNotFoundException if no route can be determined
protected function getRouteByContent($name, &$parameters) {
if ($name instanceof RouteAwareInterface) {
$content = $name;
}
elseif (isset($parameters['content_id']) && null !== $this->contentRepository) {
$content = $this->contentRepository
->findById($parameters['content_id']);
if (empty($content)) {
throw new RouteNotFoundException('The content repository found nothing at id ' . $parameters['content_id']);
}
if (!$content instanceof RouteAwareInterface) {
throw new RouteNotFoundException('Content repository did not return a RouteAwareInterface for id ' . $parameters['content_id']);
}
}
else {
$hint = is_object($name) ? get_class($name) : gettype($name);
throw new RouteNotFoundException("The route name argument '{$hint}' is not RouteAwareInterface and there is no 'content_id' parameter");
}
$routes = $content
->getRoutes();
if (empty($routes)) {
$hint = $this->contentRepository && $this->contentRepository
->getContentId($content) ? $this->contentRepository
->getContentId($content) : get_class($content);
throw new RouteNotFoundException('Content document has no route: ' . $hint);
}
unset($parameters['content_id']);
$route = $this
->getRouteByLocale($routes, $this
->getLocale($parameters));
if ($route) {
return $route;
}
// if none matched, continue and randomly return the first one
return reset($routes);
}