Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Entity/RouteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,21 @@ public function findRouteByUrl($url)
/**
* {@inheritDoc}
*/
public function getRouteByName($name, $parameters = array())
public function getRouteByName($name, $parameters = array(), $config = array())
{
$route = $this->findOneByName($name);
$locale = $config['locale'];
$defaultLocale = $config['defaultLocale'];

$route = $this->findOneBy(array('name' => $name, 'locale' => $locale));

if (!$route) {
$route = $this->findOneBy(array('name' => $name, 'locale' => substr($locale, 0, 2)));
}

if (!$route) {
$route = $this->findOneBy(array('name' => $name, 'locale' => $defaultLocale));
}

if (!$route) {
throw new RouteNotFoundException("No route found for name '$name'");
}
Expand Down
5 changes: 3 additions & 2 deletions Routing/Base/DynamicRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ public function generate($name, $parameters = array(), $absolute = false)
$route = $parameters['route'];
unset($parameters['route']);
} elseif ($name) {

$route = $this->routeRepository->getRouteByName($name, $parameters);
$config['locale'] = $this->getLocale($parameters);
$config['defaultLocale'] = $this->container->getParameter('locale');
$route = $this->routeRepository->getRouteByName($name, $parameters, $config);
} else {
$route = $this->getRouteFromContent($parameters);
unset($parameters['route']); // could be an empty string
Expand Down