Skip to content

Commit 7fcc042

Browse files
[TwigBundle] Add "use_yield" option to allow opting in for this new rendering mode and skip a deprecation
1 parent 2bfac0d commit 7fcc042

34 files changed

+71
-57
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Form\FormView;
1616
use Twig\Environment;
1717
use Twig\Template;
18+
use Twig\YieldingTemplate;
1819

1920
/**
2021
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -55,7 +56,14 @@ public function renderBlock(FormView $view, $resource, string $blockName, array
5556

5657
// We do not call renderBlock here to avoid too many nested level calls
5758
// (XDebug limits the level to 100 by default)
58-
$this->template->displayBlock($blockName, $context, $this->resources[$cacheKey]);
59+
60+
if ($this->template instanceof YieldingTemplate) {
61+
foreach ($this->template->yieldBlock($blockName, $context, $this->resources[$cacheKey]) as $data) {
62+
echo $data;
63+
}
64+
} else {
65+
$this->template->displayBlock($blockName, $context, $this->resources[$cacheKey]);
66+
}
5967

6068
return ob_get_clean();
6169
}

src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public static function getDebugTemplateNameTestData()
138138
(None) templates%e%A
139139
%A
140140
@Twig templates/bundles/TwigBundle%e%A
141-
vendors/twig-bundle/Resources/views%e%A
141+
vendors/twig-bundle/Resources/views%e%A
142142
----------- -------------------------------------%A
143143
144144
@@ -305,7 +305,7 @@ public function testComplete(array $input, array $expectedSuggestions)
305305

306306
$projectDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
307307
$loader = new FilesystemLoader([], $projectDir);
308-
$environment = new Environment($loader);
308+
$environment = new Environment($loader, ['use_yield' => true]);
309309

310310
$application = new Application();
311311
$application->add(new DebugCommand($environment, $projectDir, [], null, null));
@@ -337,7 +337,7 @@ private function createCommandTester(array $paths = [], array $bundleMetadata =
337337
$loader = new ChainLoader([$loader]);
338338
}
339339

340-
$environment = new Environment($loader);
340+
$environment = new Environment($loader, ['use_yield' => true]);
341341
foreach ($globals as $name => $value) {
342342
$environment->addGlobal($name, $value);
343343
}

src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private function createCommandTester(): CommandTester
162162

163163
private function createCommand(): Command
164164
{
165-
$environment = new Environment(new FilesystemLoader(\dirname(__DIR__).'/Fixtures/templates/'));
165+
$environment = new Environment(new FilesystemLoader(\dirname(__DIR__).'/Fixtures/templates/'), ['use_yield' => true]);
166166
$environment->addFilter(new TwigFilter('deprecated_filter', function ($v) {
167167
return $v;
168168
}, ['deprecated' => true]));

src/Symfony/Bridge/Twig/Tests/ErrorRenderer/TwigErrorRendererTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testFallbackToNativeRendererIfCustomTemplateNotFound()
4040
{
4141
$exception = new NotFoundHttpException();
4242

43-
$twig = new Environment(new ArrayLoader([]));
43+
$twig = new Environment(new ArrayLoader([]), ['use_yield' => true]);
4444

4545
$nativeRenderer = $this->createMock(HtmlErrorRenderer::class);
4646
$nativeRenderer
@@ -57,7 +57,7 @@ public function testRenderCustomErrorTemplate()
5757
{
5858
$twig = new Environment(new ArrayLoader([
5959
'@Twig/Exception/error404.html.twig' => '<h1>Page Not Found</h1>',
60-
]));
60+
]), ['use_yield' => true]);
6161
$exception = (new TwigErrorRenderer($twig))->render(new NotFoundHttpException());
6262

6363
$this->assertSame('<h1>Page Not Found</h1>', $exception->getAsString());

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ public function testFormatArgsIntegration()
116116
$this->assertEquals($expected, $this->render($template, $data));
117117
}
118118

119-
120119
public function testFormatFileIntegration()
121120
{
122121
$template = <<<'TWIG'
@@ -156,7 +155,7 @@ private function render(string $template, array $context = [])
156155
{
157156
$twig = new Environment(
158157
new ArrayLoader(['index' => $template]),
159-
['debug' => true]
158+
['debug' => true, 'use_yield' => true]
160159
);
161160
$twig->addExtension($this->getExtension());
162161

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped)
3232
'debug' => $debug,
3333
'cache' => false,
3434
'optimizations' => 0,
35+
'use_yield' => true,
3536
]);
3637
$twig->addExtension($extension);
3738

@@ -72,6 +73,7 @@ public function testDump($context, $args, $expectedOutput, $debug = true)
7273
'debug' => $debug,
7374
'cache' => false,
7475
'optimizations' => 0,
76+
'use_yield' => true,
7577
]);
7678

7779
array_unshift($args, $context);
@@ -129,6 +131,7 @@ public function testCustomDumper()
129131
'debug' => true,
130132
'cache' => false,
131133
'optimizations' => 0,
134+
'use_yield' => true,
132135
]);
133136

134137
$dump = $extension->dump($twig, [], 'foo');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ExpressionExtensionTest extends TestCase
2121
public function testExpressionCreation()
2222
{
2323
$template = "{{ expression('1 == 1') }}";
24-
$twig = new Environment(new ArrayLoader(['template' => $template]), ['debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]);
24+
$twig = new Environment(new ArrayLoader(['template' => $template]), ['debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0, 'use_yield' => true]);
2525
$twig->addExtension(new ExpressionExtension());
2626

2727
$output = $twig->render('template');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function setUp(): void
4343
__DIR__.'/Fixtures/templates/form',
4444
]);
4545

46-
$environment = new Environment($loader, ['strict_variables' => true]);
46+
$environment = new Environment($loader, ['strict_variables' => true, 'use_yield' => true]);
4747
$environment->addExtension(new TranslationExtension(new StubTranslator()));
4848
$environment->addExtension(new FormExtension());
4949

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function setUp(): void
3939
__DIR__.'/Fixtures/templates/form',
4040
]);
4141

42-
$environment = new Environment($loader, ['strict_variables' => true]);
42+
$environment = new Environment($loader, ['strict_variables' => true, 'use_yield' => true]);
4343
$environment->addExtension(new TranslationExtension(new StubTranslator()));
4444
$environment->addExtension(new FormExtension());
4545

@@ -80,7 +80,7 @@ public function testMoneyWidgetInIso()
8080
$environment = new Environment(new FilesystemLoader([
8181
__DIR__.'/../../Resources/views/Form',
8282
__DIR__.'/Fixtures/templates/form',
83-
]), ['strict_variables' => true]);
83+
]), ['strict_variables' => true, 'use_yield' => true]);
8484
$environment->addExtension(new TranslationExtension(new StubTranslator()));
8585
$environment->addExtension(new FormExtension());
8686
$environment->setCharset('ISO-8859-1');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function setUp(): void
4545
__DIR__.'/Fixtures/templates/form',
4646
]);
4747

48-
$environment = new Environment($loader, ['strict_variables' => true]);
48+
$environment = new Environment($loader, ['strict_variables' => true, 'use_yield' => true]);
4949
$environment->addExtension(new TranslationExtension(new StubTranslator()));
5050
$environment->addExtension(new FormExtension());
5151

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy