8000 [TwigBridge] fixed form rendering when used in a template with dynamic inheritance by fabpot · Pull Request #9010 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge] fixed form rendering when used in a template with dynamic inheritance #9010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

[TwigBridge] fixed form rendering when used in a template with dynami…
…c inheritance
  • Loading branch information
fabpot committed Sep 12, 2013
commit 4c1dbc75d5256dad2de5e25174c4ddbfe544197f
4 changes: 3 additions & 1 deletion src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ protected function loadResourcesFromTheme($cacheKey, &$theme)
// 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.
Expand All @@ -178,6 +180,6 @@ protected function loadResourcesFromTheme($cacheKey, &$theme)
$this->resources[$cacheKey][$block] = $blockData;
}
}
} while (false !== $currentTheme = $currentTheme->getParent(array()));
} while (false !== $currentTheme = $currentTheme->getParent($context));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ protected function setUp()
$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);
Expand Down Expand Up @@ -106,6 +108,18 @@ public function testThemeBlockInheritanceUsingExtend()
);
}

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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends dynamic_template_name ~ '.html.twig' %}
0