diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index b4df596fa2..480d031b70 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +3.2.0 +----- + + * Deprecated the possibility to inject the Form Twig Renderer into the form + extension. Inject it on TwigRendererEngine instead. + 2.7.0 ----- diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index 78d2909aeb..016e6a9586 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -23,17 +23,26 @@ use Symfony\Component\Form\ChoiceList\View\ChoiceView; */ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface { - public function __construct(TwigRendererInterface $renderer) + private $renderer; + + public function __construct(TwigRendererInterface $renderer = null) { + if (null !== $this->renderer) { + @trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0. Pass the Twig_Environment to the TwigRendererEngine constructor instead.', static::class), E_USER_DEPRECATED); + } $this->renderer = $renderer; } /** * {@inheritdoc} + * + * To be removed in 4.0 */ public function initRuntime(\Twig_Environment $environment) { - $this->renderer->setEnvironment($environment); + if (null !== $this->renderer) { + $this->renderer->setEnvironment($environment); + } } /** diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php index 5248d5fd37..fe99929df0 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php @@ -29,6 +29,16 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE */ private $template; + public function __construct(array $defaultThemes = array(), \Twig_Environment $environment = null) + { + if (null === $environment) { + @trigger_error(sprintf('Not passing a Twig Environment as the second argument for "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0.', static::class), E_USER_DEPRECATED); + } + + parent::__construct($defaultThemes); + $this->environment = $environment; + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php b/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php index ef764a248f..c5968a1fa7 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php @@ -15,6 +15,8 @@ use Symfony\Component\Form\FormRendererEngineInterface; /** * @author Bernhard Schussek + * + * @deprecated Deprecated since version 3.2, to be removed in 4.0. */ interface TwigRendererEngineInterface extends FormRendererEngineInterface { diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php b/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php index 4682f52000..2b2172b8cc 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php @@ -15,6 +15,8 @@ use Symfony\Component\Form\FormRendererInterface; /** * @author Bernhard Schussek + * + * @deprecated Deprecated since version 3.2, to be removed in 4.0. */ interface TwigRendererInterface extends FormRendererInterface { diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php index a30e1b2421..7ebaa4c2ba 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php @@ -34,13 +34,6 @@ class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3Hori { parent::setUp(); - $rendererEngine = new TwigRendererEngine(array( - 'bootstrap_3_horizontal_layout.html.twig', - 'custom_widgets.html.twig', - )); - $this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')); - $extension = new FormExtension($this->renderer); - $loader = new StubFilesystemLoader(array( __DIR__.'/../../Resources/views/Form', __DIR__.'/Fixtures/templates/form', @@ -48,8 +41,13 @@ class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3Hori $environment = new \Twig_Environment($loader, array('strict_variables' => true)); $environment->addExtension(new TranslationExtension(new StubTranslator())); - $environment->addExtension($extension); - $extension->initRuntime($environment); + $environment->addExtension(new FormExtension()); + + $rendererEngine = new TwigRendererEngine(array( + 'bootstrap_3_horizontal_layout.html.twig', + 'custom_widgets.html.twig', + ), $environment); + $this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')); $this->registerTwigRuntimeLoader($environment, $this->renderer); } diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php index 071876f20d..f7919a44f9 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php @@ -30,13 +30,6 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest { parent::setUp(); - $rendererEngine = new TwigRendererEngine(array( - 'bootstrap_3_layout.html.twig', - 'custom_widgets.html.twig', - )); - $this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')); - $extension = new FormExtension($this->renderer); - $loader = new StubFilesystemLoader(array( __DIR__.'/../../Resources/views/Form', __DIR__.'/Fixtures/templates/form', @@ -44,8 +37,13 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest $environment = new \Twig_Environment($loader, array('strict_variables' => true)); $environment->addExtension(new TranslationExtension(new StubTranslator())); - $environment->addExtension($extension); - $extension->initRuntime($environment); + $environment->addExtension(new FormExtension()); + + $rendererEngine = new TwigRendererEngine(array( + 'bootstrap_3_layout.html.twig', + 'custom_widgets.html.twig', + ), $environment); + $this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')); $this->registerTwigRuntimeLoader($environment, $this->renderer); } diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index 90dd4c1b00..f9eb355db3 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php @@ -31,13 +31,6 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest { parent::setUp(); - $rendererEngine = new TwigRendererEngine(array( - 'form_div_layout.html.twig', - 'custom_widgets.html.twig', - )); - $this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')); - $extension = new FormExtension($this->renderer); - $loader = new StubFilesystemLoader(array( __DIR__.'/../../Resources/views/Form', __DIR__.'/Fixtures/templates/form', @@ -48,8 +41,13 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest $environment->addGlobal('global', ''); // the value can be any template that exists $environment->addGlobal('dynamic_template_name', 'child_label'); - $environment->addExtension($extension); - $extension->initRuntime($environment); + $environment->addExtension(new FormExtension()); + + $rendererEngine = new TwigRendererEngine(array( + 'form_div_layout.html.twig', + 'custom_widgets.html.twig', + ), $environment); + $this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')); $this->registerTwigRuntimeLoader($environment, $this->renderer); } diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php index 57673a0e75..a2726af439 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php @@ -30,13 +30,6 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest { parent::setUp(); - $rendererEngine = new TwigRendererEngine(array( - 'form_table_layout.html.twig', - 'custom_widgets.html.twig', - )); - $this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')); - $extension = new FormExtension($this->renderer); - $loader = new StubFilesystemLoader(array( __DIR__.'/../../Resources/views/Form', __DIR__.'/Fixtures/templates/form', @@ -45,8 +38,13 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest $environment = new \Twig_Environment($loader, array('strict_variables' => true)); $environment->addExtension(new TranslationExtension(new StubTranslator())); $environment->addGlobal('global', ''); - $environment->addExtension($extension); - $extension->initRuntime($environment); + $environment->addExtension(new FormExtension()); + + $rendererEngine = new TwigRendererEngine(array( + 'form_table_layout.html.twig', + 'custom_widgets.html.twig', + ), $environment); + $this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')); $this->registerTwigRuntimeLoader($environment, $this->renderer); } diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 6b6b412298..075788624a 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -116,14 +116,13 @@ - - - + %twig.form.resources% +