Skip to content

Commit 8dc79b8

Browse files
committed
add a convenience method to get the parent form in Twig templates
1 parent 7da80fd commit 8dc79b8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* added the `parent_form()` function that allows to reliably retrieve the parent form in Twig templates
8+
49
4.2.0
510
-----
611

Extension/FormExtension.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function getFunctions()
5454
new TwigFunction('form_start', null, ['node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => ['html']]),
5555
new TwigFunction('form_end', null, ['node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => ['html']]),
5656
new TwigFunction('csrf_token', ['Symfony\Component\Form\FormRenderer', 'renderCsrfToken']),
57+
new TwigFunction('parent_form', 'Symfony\Bridge\Twig\Extension\twig_get_parent_form'),
5758
];
5859
}
5960

@@ -115,3 +116,11 @@ function twig_is_root_form(FormView $formView)
115116
{
116117
return null === $formView->parent;
117118
}
119+
120+
/**
121+
* @internal
122+
*/
123+
function twig_get_parent_form(FormView $formView): ?FormView
124+
{
125+
return $formView->parent;
126+
}

0 commit comments

Comments
 (0)