8000 [Form][FrameworkBundle][TwigBundle] Fixed: CSRF fields are not render… · ivanrey/symfony@990bef8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 990bef8

Browse files
committed
[Form][FrameworkBundle][TwigBundle] Fixed: CSRF fields are not rendered for nested forms anymore
1 parent 8fe2128 commit 990bef8

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php if (!$form->hasParent() || !$form->getParent()->hasParent()): ?>
2+
<input type="hidden"
3+
<?php echo $view['form']->attributes() ?>
4+
name="<?php echo $name ?>"
5+
value="<?php echo $value ?>"
6+
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
7+
/>
8+
<?php endif ?>

src/Symfony/Bundle/TwigBundle/Resources/views/Form/div_layout.html.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@
7474
{{ block('field__widget') }}
7575
{% endblock hidden__widget %}
7676

77+
{% block csrf__widget %}
78+
{% if not form.hasParent or not form.getParent.hasParent %}
79+
{% set type = type|default('hidden') %}
80+
{{ block('field__widget') }}
81+
{% endif %}
82+
{% endblock csrf__widget %}
83+
7784
{% block hidden__row %}
7885
{{ form_widget(form) }}
7986
{% endblock hidden__row %}

tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,17 @@ public function testCsrf()
426426
);
427427
}
428428

429+
public function testCsrfWithNonRootParent()
430+
{
431+
$form = $this->factory->create('csrf', 'name');
432+
$form->setParent($this->factory->create('form'));
433+
$form->getParent()->setParent($this->factory->create('form'));
434+
435+
$html = $this->renderWidget($form->createView());
436+
437+
$this->assertEquals('', trim($html));
438+
}
439+
429440
public function testDateTime()
430441
{
431442
$form = $this->factory->create('datetime', 'name', array(

0 commit comments

Comments
 (0)
0