I'm upgrading a project from 3.1 to latest 3.4 (3.4.15 at this time).
I've managed to upgrade all components and now I'm dealing with deprecations. In one controller, I have this function:
protected function themeForm(FormInterface $form)
{
$themeFormView = $form->createView();
$this
->get('twig.form.renderer')
->getExtension(FormExtension::class)
->renderer
->setTheme($themeFormView, '@admin/form/form.html.twig');
return $themeFormView;
}
I've read the upgrade doc and I see that to remove the deprecation warning message, I have to use Symfony\Component\Form\FormRenderer instead of twig.form.renderer. However, the use case the example shows is different and I don't know how to remove the deprecation warning. I've searched for an alias, but I haven't found any. I've created an alias, but I get an error when trying to instantiate the class. As a result, I'd like to remove this warning. Can anybody help me with this? Thanks in advance.
The solution is to create a constructor:
protected $twig;
public function __construct(FormRenderer $twig)
{
$this->twig = $twig;
}
and call the property later:
$this->twig
->setTheme($themeFormView, '@admin/form/form.html.twig');
With this, I still can see the warning, so I have created a public alias in services.yml:
Symfony\Component\Form\FormRenderer:
alias: 'twig.form.renderer'
public: true
I can't see the deprecation warning now.