8000 fixed circular reference in Twig Form integration · symfony/symfony@768427d · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 768427d

Browse files
committed
fixed circular reference in Twig Form integration
1 parent 448cda7 commit 768427d

File tree

12 files changed

+60
-44
lines changed

12 files changed

+60
-44
lines changed

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
3.2.0
5+
-----
6+
7+
* Deprecated the possibility to inject the Form Twig Renderer into the form
8+
extension. Inject it on TwigRendererEngine instead.
9+
410
2.7.0
511
-----
612

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,26 @@
2323
*/
2424
class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
2525
{
26-
public function __construct(TwigRendererInterface $renderer)
26+
private $renderer;
27+
28+
public function __construct(TwigRendererInterface $renderer = null)
2729
{
30+
if (null !== $this->renderer) {
31+
@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);
32+
}
2833
$this->renderer = $renderer;
2934
}
3035

3136
/**
3237
* {@inheritdoc}
38+
*
39+
* To be removed in 4.0
3340
*/
3441
public function initRuntime(\Twig_Environment $environment)
3542
{
36-
$this->renderer->setEnvironment($environment);
43+
if (null !== $this->renderer) {
44+
$this->renderer->setEnvironment($environment);
45+
}
3746
}
3847

3948
/**

src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
2929
*/
3030
private $template;
3131

32+
public function __construct(array $defaultThemes = array(), \Twig_Environment $environment = null)
33+
{
34+
parent::__construct($defaultThemes);
35+
$this->environment = $environment;
36+
}
37+
3238
/**
3339
* {@inheritdoc}
3440
*/

src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* @author Bernhard Schussek <bschussek@gmail.com>
18+
*
19+
* @deprecated Deprecated since version 3.2, to be removed in 4.0.
1820
*/
1921
interface TwigRendererEngineInterface extends FormRendererEngineInterface
2022
{

src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* @author Bernhard Schussek <bschussek@gmail.com>
18+
*
19+
* @deprecated Deprecated since version 3.2, to be removed in 4.0.
1820
*/
1921
interface TwigRendererInterface extends FormRendererInterface
2022
{

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,20 @@ protected function setUp()
3434
{
3535
parent::setUp();
3636

37-
$rendererEngine = new TwigRendererEngine(array(
38-
'bootstrap_3_horizontal_layout.html.twig',
39-
'custom_widgets.html.twig',
40-
));
41-
$this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
42-
$extension = new FormExtension($this->renderer);
43-
4437
$loader = new StubFilesystemLoader(array(
4538
__DIR__.'/../../Resources/views/Form',
4639
__DIR__.'/Fixtures/templates/form',
4740
));
4841

4942
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
5043
$environment->addExtension(new TranslationExtension(new StubTranslator()));
51-
$environment->addExtension($extension);
52-
$extension->initRuntime($environment);
44+
$environment->addExtension(new FormExtension());
45+
46+
$rendererEngine = new TwigRendererEngine(array(
47+
'bootstrap_3_horizontal_layout.html.twig',
48+
'custom_widgets.html.twig',
49+
), $environment);
50+
$this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
5351
$this->registerTwigRuntimeLoader($environment, $this->renderer);
5452
}
5553

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,20 @@ protected function setUp()
3030
{
3131
parent::setUp();
3232

33-
$rendererEngine = new TwigRendererEngine(array(
34-
'bootstrap_3_layout.html.twig',
35-
'custom_widgets.html.twig',
36-
));
37-
$this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
38-
$extension = new FormExtension($this->renderer);
39-
4033
$loader = new StubFilesystemLoader(array(
4134
__DIR__.'/../../Resources/views/Form',
4235
__DIR__.'/Fixtures/templates/form',
4336
));
4437

4538
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
4639
$environment->addExtension(new TranslationExtension(new StubTranslator()));
47-
$environment->addExtension($extension);
48-
$extension->initRuntime($environment);
40+
$environment->addExtension(new FormExtension());
41+
42+
$rendererEngine = new TwigRendererEngine(array(
43+
'bootstrap_3_layout.html.twig',
44+
'custom_widgets.html.twig',
45+
), $environment);
46+
$this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
4947
$this->registerTwigRuntimeLoader($environment, $this->renderer);
5048
}
5149

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ protected function setUp()
3131
{
3232
parent::setUp();
3333

34-
$rendererEngine = new TwigRendererEngine(array(
35-
'form_div_layout.html.twig',
36-
'custom_widgets.html.twig',
37-
));
38-
$this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
39-
$extension = new FormExtension($this->renderer);
40-
4134
$loader = new StubFilesystemLoader(array(
4235
__DIR__.'/../../Resources/views/Form',
4336
__DIR__.'/Fixtures/templates/form',
@@ -48,8 +41,13 @@ protected function setUp()
4841
$environment->addGlobal('global', '');
4942
// the value can be any template that exists
5043
$environment->addGlobal('dynamic_template_name', 'child_label');
51-
$environment->addExtension($extension);
52-
$extension->initRuntime($environment);
44+
$environment->addExtension(new FormExtension());
45+
46+
$rendererEngine = new TwigRendererEngine(array(
47+
'form_div_layout.html.twig',
48+
'custom_widgets.html.twig',
49+
), $environment);
50+
$this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
5351
$this->registerTwigRuntimeLoader($environment, $this->renderer);
5452
}
5553

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ protected function setUp()
3030
{
3131
parent::setUp();
3232

33-
$rendererEngine = new TwigRendererEngine(array(
34-
'form_table_layout.html.twig',
35-
'custom_widgets.html.twig',
36-
));
37-
$this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
38-
$extension = new FormExtension($this->renderer);
39-
4033
$loader = new StubFilesystemLoader(array(
4134
__DIR__.'/../../Resources/views/Form',
4235
__DIR__.'/Fixtures/templates/form',
@@ -45,8 +38,13 @@ protected function setUp()
4538
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
4639
$environment->addExtension(new TranslationExtension(new StubTranslator()));
4740
$environment->addGlobal('global', '');
48-
$environment->addExtension($extension);
49-
$extension->initRuntime($environment);
41+
$environment->addExtension(new FormExtension());
42+
43+
$rendererEngine = new TwigRendererEngine(array(
44+
'form_table_layout.html.twig',
45+
'custom_widgets.html.twig',
46+
), $environment);
47+
$this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'));
5048
$this->registerTwigRuntimeLoader($environment, $this->renderer);
5149
}
5250

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"symfony/http-foundation": "~2.8|~3.0",
3232
"symfony/security-acl": "~2.8|~3.0",
3333
"symfony/templating": "~2.8|~3.0",
34-
"symfony/twig-bundle": "~2.8|~3.0",
35-
"symfony/twig-bridge": "~2.8|~3.0",
34+
"symfony/twig-bundle": "~3.2",
35+
"symfony/twig-bridge": "~3.2",
3636
"symfony/process": "~2.8|~3.0",
3737
"symfony/templating": "~2.8|~3.0",
3838
"symfony/validator": "~2.8|~3.0",

0 commit comments

Comments
 (0)
0