Skip to content

Commit ef5b740

Browse files
committed
[Form] update FormExtension registration
1 parent b03b906 commit ef5b740

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

components/form.rst

+9-4
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,25 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
194194
$vendorTwigBridgeDir.'/Resources/views/Form',
195195
)));
196196
$formEngine = new TwigRendererEngine(array($defaultFormTheme));
197-
$formEngine->setEnvironment($twig);
197+
$twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array(
198+
TwigRenderer::class => function () use ($formEngine, $csrfManager) {
199+
return new TwigRenderer($formEngine, $csrfManager);
200+
},
201+
)));
198202

199203
// ... (see the previous CSRF Protection section for more information)
200204

201205
// add the FormExtension to Twig
202-
$twig->addExtension(
203-
new FormExtension(new TwigRenderer($formEngine, $csrfManager))
204-
);
206+
$twig->addExtension(new FormExtension());
205207

206208
// create your form factory as normal
207209
$formFactory = Forms::createFormFactoryBuilder()
208210
// ...
209211
->getFormFactory();
210212

213+
.. versionadded:: 1.30
214+
The ``Twig_FactoryRuntimeLoader`` was introduced in Twig 1.30.
215+
211216
The exact details of your `Twig Configuration`_ will vary, but the goal is
212217
always to add the :class:`Symfony\\Bridge\\Twig\\Extension\\FormExtension`
213218
to Twig, which gives you access to the Twig functions for rendering forms.

0 commit comments

Comments
 (0)