public function generate($name, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
// Direct access to Location
if ($name instanceof Location) {
return $this->generator->generate($name, $parameters, $referenceType);
}
// Normal route name
if ($name === self::URL_ALIAS_ROUTE_NAME) {
if (isset($parameters['location']) || isset($parameters['locationId'])) {
// Check if location is a valid Location object
if (isset($parameters['location']) && !$parameters['location'] instanceof Location) {
throw new LogicException("When generating an UrlAlias route, 'location' parameter must be a valid eZ\\Publish\\API\\Repository\\Values\\Content\\Location.");
}
$location = isset($parameters['location']) ? $parameters['location'] : $this->locationService->loadLocation($parameters['locationId']);
unset($parameters['location'], $parameters['locationId'], $parameters['viewType'], $parameters['layout']);
return $this->generator->generate($location, $parameters, $referenceType);
}
if (isset($parameters['contentId'])) {
$contentInfo = $this->contentService->loadContentInfo($parameters['contentId']);
unset($parameters['contentId'], $parameters['viewType'], $parameters['layout']);
if (empty($contentInfo->mainLocationId)) {
throw new LogicException('Cannot generate an UrlAlias route for content without main location.');
}
return $this->generator->generate($this->locationService->loadLocation($contentInfo->mainLocationId), $parameters, $referenceType);
}
throw new InvalidArgumentException("When generating an UrlAlias route, either 'location', 'locationId' or 'contentId' must be provided.");
}
throw new RouteNotFoundException('Could not match route');
}