Skip to content

Commit

Permalink
Fixed issue #6932 - Inconsistent locale handling in subrequests
Browse files Browse the repository at this point in the history
The fix consists in passing the locale in the controller reference,
by making the controller twig function aware of the current context.
There are a few additional checks for the request scope, in order
not to break compatibility when using the console.
  • Loading branch information
csarrazi committed Jul 13, 2013
1 parent 63e6368 commit b239dd7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php
Expand Up @@ -38,7 +38,7 @@ public function getFunctions()
return array(
'render' => new \Twig_Function_Method($this, 'renderFragment', array('is_safe' => array('html'))),
'render_*' => new \Twig_Function_Method($this, 'renderFragmentStrategy', array('is_safe' => array('html'))),
'controller' => new \Twig_Function_Method($this, 'controller'),
'controller' => new \Twig_Function_Method($this, 'controller', array('needs_context' => true)),
);
}

Expand Down Expand Up @@ -76,8 +76,12 @@ public function renderFragmentStrategy($strategy, $uri, $options = array())
return $this->handler->render($uri, $strategy, $options);
}

public function controller($controller, $attributes = array(), $query = array())
public function controller(array $context, $controller, $attributes = array(), $query = array())
{
if (isset($context['app'])) {
$attributes['_locale'] = $context['app']->getRequest()->getLocale();
}

return new ControllerReference($controller, $attributes, $query);
}

Expand Down

0 comments on commit b239dd7

Please sign in to comment.