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
This commit is contained in:
Fabien Potencier 2013-09-12 18:11:03 +02:00
commit 8e5a9b056c
3 changed files with 18 additions and 1 deletions

View File

@ -167,6 +167,8 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
// theme is a reference and we don't want to change it.
$currentTheme = $theme;
$context = $this->environment->mergeGlobals(array());
// The do loop takes care of template inheritance.
// Add blocks from all templates in the inheritance tree, but avoid
// overriding blocks already set.
@ -178,6 +180,6 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
$this->resources[$cacheKey][$block] = $blockData;
}
}
} while (false !== $currentTheme = $currentTheme->getParent(array()));
} while (false !== $currentTheme = $currentTheme->getParent($context));
}
}

View File

@ -64,6 +64,8 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addGlobal('global', '');
// the value can be any template that exists
$environment->addGlobal('dynamic_template_name', 'child_label');
$environment->addExtension($this->extension);
$this->extension->initRuntime($environment);
@ -106,6 +108,18 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
);
}
public function testThemeBlockInheritanceUsingDynamicExtend()
{
$view = $this->factory
->createNamed('name', 'email')
->createView()
;
$renderer = $this->extension->renderer;
$renderer->setTheme($view, array('page_dynamic_extends.html.twig'));
$renderer->searchAndRenderBlock($view, 'row');
}
public function isSelectedChoiceProvider()
{
// The commented cases should not be necessary anymore, because the

View File

@ -0,0 +1 @@
{% extends dynamic_template_name ~ '.html.twig' %}