8000 merged branch fabpot/twig-form-renderer-fix (PR #9010) · symfony/symfony@8e5a9b0 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 8e5a9b0

Browse files
committed
merged branch fabpot/twig-form-renderer-fix (PR #9010)
This PR was merged into the 2.2 branch. Discussion ---------- [TwigBridge] fixed form rendering when used in a template with dynamic inheritance | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #5284 | License | MIT | Doc PR | n/a Commits ------- 4c1dbc7 [TwigBridge] fixed form rendering when used in a template with dynamic inheritance
2 parents 6c10b69 + 4c1dbc7 commit 8e5a9b0

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ protected function loadResourcesFromTheme($cacheKey, &$theme)
167167
// theme is a reference and we don't want to change it.
168168
$currentTheme = $theme;
169169

170+
$context = $this->environment->mergeGlobals(array());
171+
170172
// The do loop takes care of template inheritance.
171173
// Add blocks from all templates in the inheritance tree, but avoid
172174
// overriding blocks already set.
@@ -178,6 +180,6 @@ protected function loadResourcesFromTheme($cacheKey, &$theme)
178180
$this->resources[$cacheKey][$block] = $blockData;
179181
}
180182
}
181-
} while (false !== $currentTheme = $currentTheme->getParent(array()));
183+
} while (false !== $currentTheme = $currentTheme->getParent($context));
182184
}
183185
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ protected function setUp()
6464
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
6565
$environment->addExtension(new TranslationExtension(new StubTranslator()));
6666
$environment->addGlobal('global', '');
67+
// the value can be any template that exists
68+
$environment->addGlobal('dynamic_template_name', 'child_label');
6769
$environment->addExtension($this->extension);
6870

6971
$this->extension->initRuntime($environment);
@@ -106,6 +108,18 @@ public function testThemeBlockInheritanceUsingExtend()
106108
);
107109
}
108110

111+
public function testThemeBlockInheritanceUsingDynamicExtend()
112+
{
113+
$view = $this->factory
114+
->createNamed('name', 'email')
115+
->createView()
116+
;
117+
118+
$renderer = $this->extension->renderer;
119+
$renderer->setTheme($view, array('page_dynamic_extends.html.twig'));
120+
$renderer->searchAndRenderBlock($view, 'row');
121+
}
122+
109123
public function isSelectedChoiceProvider()
110124
{
111125
// The commented cases should not be necessary anymore, because the
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends dynamic_template_name ~ '.html.twig' %}

0 commit comments

Comments
 (0)
0