merged branch fabpot/inline-fragment-format (PR #8821)
This PR was merged into the 2.2 branch. Discussion ---------- Sets _format attribute only if it wasn't set previously by the user | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8787, #8791 | License | MIT | Doc PR | Commits -------9bb7a3d
fixed request format of sub-requests when explicitely set by the developer (closes #8787)fa35597
Sets _format attribute only if it wasn't set previously by the user.
This commit is contained in:
commit
1ad64ee7a3
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -48,12 +48,18 @@ 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();
|
||||
|
||||
// The request format might have been overriden by the user
|
||||
if (isset($attributes['_format'])) {
|
||||
$reference->attributes['_format'] = $attributes['_format'];
|
||||
}
|
||||
|
||||
$uri = $this->generateFragmentUri($uri, $request);
|
||||
$reference->attributes = array_merge($attributes, $reference->attributes);
|
||||
}
|
||||
|
|
Reference in New Issue