From ef5b74049e3b67e90a677484aa5e7b8a905c2b3f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 27 Dec 2016 15:07:08 +0100 Subject: [PATCH] [Form] update FormExtension registration --- components/form.rst | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/components/form.rst b/components/form.rst index 334620b7a73..80caaf23357 100644 --- a/components/form.rst +++ b/components/form.rst @@ -194,20 +194,25 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension $vendorTwigBridgeDir.'/Resources/views/Form', ))); $formEngine = new TwigRendererEngine(array($defaultFormTheme)); - $formEngine->setEnvironment($twig); + $twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array( + TwigRenderer::class => function () use ($formEngine, $csrfManager) { + return new TwigRenderer($formEngine, $csrfManager); + }, + ))); // ... (see the previous CSRF Protection section for more information) // add the FormExtension to Twig - $twig->addExtension( - new FormExtension(new TwigRenderer($formEngine, $csrfManager)) - ); + $twig->addExtension(new FormExtension()); // create your form factory as normal $formFactory = Forms::createFormFactoryBuilder() // ... ->getFormFactory(); +.. versionadded:: 1.30 + The ``Twig_FactoryRuntimeLoader`` was introduced in Twig 1.30. + The exact details of your `Twig Configuration`_ will vary, but the goal is always to add the :class:`Symfony\\Bridge\\Twig\\Extension\\FormExtension` to Twig, which gives you access to the Twig functions for rendering forms.