Reputation: 20456
I went looking to see how Symfony's extended Twig function form_widget
actually works. I was expecting to find the function in symfony / src / Symfony / Bridge / Twig / Extension / FormExtension.php . It's added to the function list there:
public function getFunctions()
{
return array(
...
new \Twig_SimpleFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
...
);
}
But no callable is listed (ie the 2nd arg is null). So what code is called when I use form_widget(a_form_element)
in a Twig template?
Upvotes: 4
Views: 1419
Reputation: 109
This is now depreciated but here is available code directly using methods to render form when you call eg. form_row() twig function Here it is: https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php
Upvotes: 0
Reputation: 3678
My answer is a little late but I just happened to investigate the same question. This is what I found:
The code which is called when you use form_widget()
is that produced directly by the SearchAndRenderBlockNode
class when your template is compiled. The compiled template code then results in a call to Symfony\Component\Form\FormRenderer::searchAndRenderBlock()
where the proper Twig block is located, provided with context, and rendered.
Upvotes: 3
Reputation: 2498
You can find it in FrameworkBundle/Resources/views/Form/form_widget.html.php
or it equivalent in template Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
.
Upvotes: 1
Reputation: 3656
I don't recognize the name space there. Or that code.
Mine is in Symfony\Bridge\Twig\Extension\FormExtension.php
It uses Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode
Upvotes: 0