Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

unset _locale parameter if matching route has been found #56

Merged
merged 1 commit into from

3 participants

@uwej711
Collaborator

See issue #55

@dbu dbu merged commit 0169143 into from
@dbu
Owner
dbu commented

thanks

@dbu
Owner
dbu commented

hm. what if there is {_locale} in the route? should we check that before unsetting?

@uwej711
Collaborator
@lsmith77
Owner

we do have the locale in the route when using the SimpleCmsBundle in the multilang mode (like we do in the SE).

@uwej711
Collaborator
@dbu
Owner
dbu commented
@lsmith77
Owner
@uwej711
Collaborator

You do it in SimpleCmsBundle\Document\MultilangRoute.php

This could be part of the RoutingExtraBundle ?

@lsmith77
Owner

sorry .. i was unclear before .. its done inside the Route itself:
https://github.com/symfony-cmf/SimpleCmsBundle/blob/master/Document/MultilangPage.php#L71

@uwej711
Collaborator

So I propose the following: we compile the route already in ContentAwareGenerator and check the variables for _locale. If it is not there, it can be safely unset. I'll try to do a PR for that.

@dbu
Owner
dbu commented
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 2 deletions.
  1. +4 −2 ContentAwareGenerator.php
View
6 ContentAwareGenerator.php
@@ -79,7 +79,7 @@ public function generate($name, $parameters = array(), $absolute = false)
*
* @throws RouteNotFoundException if there is no route found for the provided name
*/
- protected function getRouteByName($name, array $parameters)
+ protected function getRouteByName($name, array &$parameters)
{
$route = $this->provider->getRouteByName($name, $parameters);
if (empty($route)) {
@@ -98,7 +98,7 @@ protected function getRouteByName($name, array $parameters)
*
* @return SymfonyRoute either the passed route or an alternative with better locale
*/
- protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
+ protected function getBestLocaleRoute(SymfonyRoute $route, &$parameters)
{
if (! $route instanceof RouteObjectInterface) {
// this route has no content, we can't get the alternatives
@@ -111,6 +111,7 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
$routes = $content->getRoutes();
$contentRoute = $this->getRouteByLocale($routes, $locale);
if ($contentRoute) {
+ unset($parameters['_locale']);
return $contentRoute;
}
}
@@ -167,6 +168,7 @@ protected function getRouteByContent($name, &$parameters)
$route = $this->getRouteByLocale($routes, $this->getLocale($parameters));
if ($route) {
+ unset($parameters['_locale']);
return $route;
}
Something went wrong with that request. Please try again.