From fa355977556ef5619da7b08c3c4ef7789984231d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mar=C3=ADn?= Date: Mon, 19 Aug 2013 12:49:47 +0200 Subject: [PATCH 1/2] Sets _format attribute only if it wasn't set previously by the user. Fixes #8787 --- .../HttpKernel/Fragment/InlineFragmentRenderer.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php index a4dab4c7d0..c06ee7a8dd 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php @@ -54,6 +54,12 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer // below instead) $attributes = $reference->attributes; $reference->attributes = array(); + + // Except "_format" attribute + if (isset($attributes['_format'])) { + $reference->attributes['_format'] = $attributes['_format']; + } + $uri = $this->generateFragmentUri($uri, $request); $reference->attributes = array_merge($attributes, $reference->attributes); } From 9bb7a3ddcbc5491af42d544d81f4df9a470816e9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 22 Aug 2013 07:26:17 +0200 Subject: [PATCH 2/2] fixed request format of sub-requests when explicitely set by the developer (closes #8787) --- .../TestBundle/Controller/FragmentController.php | 13 +++++++++++-- .../Tests/Functional/FragmentTest.php | 2 +- .../HttpKernel/Fragment/InlineFragmentRenderer.php | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/FragmentController.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/FragmentController.php index e03f70f25e..d57050e318 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/FragmentController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/FragmentController.php @@ -20,18 +20,27 @@ class FragmentController extends ContainerAware { $actions = $this->container->get('templating')->get('actions'); - return new Response($actions->render($actions->controller('TestBundle:Fragment:inlined', array( + $html1 = $actions->render($actions->controller('TestBundle:Fragment:inlined', array( 'options' => array( 'bar' => new Bar(), 'eleven' => 11, ), - )))); + ))); + + $html2 = $actions->render($actions->controller('TestBundle:Fragment:customformat', array('_format' => 'html'))); + + return new Response($html1.'--'.$html2); } public function inlinedAction($options, $_format) { return new Response($options['bar']->getBar().' '.$_format); } + + public function customFormatAction($_format) + { + return new Response($_format); + } } class Bar diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php index a054d7c2e2..edfb08b532 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php @@ -28,7 +28,7 @@ class FragmentTest extends WebTestCase $client->request('GET', '/fragment_home'); - $this->assertEquals('bar txt', $client->getResponse()->getContent()); + $this->assertEquals('bar txt--html', $client->getResponse()->getContent()); } public function getConfigs() diff --git a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php index c06ee7a8dd..679ef6b575 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php @@ -48,16 +48,16 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer if ($uri instanceof ControllerReference) { $reference = $uri; - // Remove attributes from the genereated URI because if not, the Symfony + // Remove attributes from the generated URI because if not, the Symfony // routing system will use them to populate the Request attributes. We don't // want that as we want to preserve objects (so we manually set Request attributes // below instead) $attributes = $reference->attributes; $reference->attributes = array(); - // Except "_format" attribute + // The request format might have been overriden by the user if (isset($attributes['_format'])) { - $reference->attributes['_format'] = $attributes['_format']; + $reference->attributes['_format'] = $attributes['_format']; } $uri = $this->generateFragmentUri($uri, $request);