add a convenience method to get the parent form in Twig templates

This commit is contained in:
Christian Flothmann 2018-10-11 09:57:27 +02:00
parent 5aa0967f9f
commit cb60642d15
2 changed files with 14 additions and 0 deletions

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
4.3.0
-----
* added the `parent_form()` function that allows to reliably retrieve the parent form in Twig templates
4.2.0
-----

View File

@ -54,6 +54,7 @@ class FormExtension extends AbstractExtension
new TwigFunction('form_start', null, ['node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => ['html']]),
new TwigFunction('form_end', null, ['node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => ['html']]),
new TwigFunction('csrf_token', ['Symfony\Component\Form\FormRenderer', 'renderCsrfToken']),
new TwigFunction('parent_form', 'Symfony\Bridge\Twig\Extension\twig_get_parent_form'),
];
}
@ -115,3 +116,11 @@ function twig_is_root_form(FormView $formView)
{
return null === $formView->parent;
}
/**
* @internal
*/
function twig_get_parent_form(FormView $formView): ?FormView
{
return $formView->parent;
}