fixed locale of sub-requests when explicitely set by the developer (refs #8821)

This commit is contained in:
Fabien Potencier 2013-08-22 08:48:41 +02:00
parent 1ad64ee7a3
commit b3c31593c7
3 changed files with 15 additions and 5 deletions

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller; namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\DependencyInjection\ContainerAware;
@ -29,7 +30,9 @@ class FragmentController extends ContainerAware
$html2 = $actions->render($actions->controller('TestBundle:Fragment:customformat', array('_format' => 'html'))); $html2 = $actions->render($actions->controller('TestBundle:Fragment:customformat', array('_format' => 'html')));
return new Response($html1.'--'.$html2); $html3 = $actions->render($actions->controller('TestBundle:Fragment:customlocale', array('_locale' => 'es')));
return new Response($html1.'--'.$html2.'--'.$html3);
} }
public function inlinedAction($options, $_format) public function inlinedAction($options, $_format)
@ -41,6 +44,11 @@ class FragmentController extends ContainerAware
{ {
return new Response($_format); return new Response($_format);
} }
public function customLocaleAction(Request $request)
{
return new Response($request->getLocale());
}
} }
class Bar class Bar

View File

@ -28,7 +28,7 @@ class FragmentTest extends WebTestCase
$client->request('GET', '/fragment_home'); $client->request('GET', '/fragment_home');
$this->assertEquals('bar txt--html', $client->getResponse()->getContent()); $this->assertEquals('bar txt--html--es', $client->getResponse()->getContent());
} }
public function getConfigs() public function getConfigs()

View File

@ -55,9 +55,11 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
$attributes = $reference->attributes; $attributes = $reference->attributes;
$reference->attributes = array(); $reference->attributes = array();
// The request format might have been overriden by the user // The request format and locale might have been overriden by the user
if (isset($attributes['_format'])) { foreach (array('_format', '_locale') as $key) {
$reference->attributes['_format'] = $attributes['_format']; if (isset($attributes[$key])) {
$reference->attributes[$key] = $attributes[$key];
}
} }
$uri = $this->generateFragmentUri($uri, $request); $uri = $this->generateFragmentUri($uri, $request);