Skip to content

Commit

Permalink
[Form] Fix twig theme inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Jun 8, 2011
1 parent 882a8e3 commit bee505a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Symfony/Bridge/Twig/Extension/FormExtension.php
Expand Up @@ -248,16 +248,18 @@ protected function getTemplates(FormView $view)
{
if (!$this->templates->contains($view)) {
// defaults
$all = $this->resources;
$all = array();

// themes
$parent = $view;
do {
if (isset($this->themes[$parent])) {
$all = array_merge($all, $this->themes[$parent]);
$all = array_merge($this->themes[$parent], $all);
}
} while ($parent = $parent->getParent());

$all = array_merge($this->resources, $all);

$templates = array();
foreach ($all as $resource) {
if (!$resource instanceof \Twig_Template) {
Expand Down
Expand Up @@ -48,6 +48,48 @@ protected function setUp()
$this->extension->initRuntime($environment);
}

public function testThemeInheritance()
{
$child = $this->factory->createNamedBuilder('form', 'child')
->add('field', 'text')
->getForm();

$view = $this->factory->createNamedBuilder('form', 'parent')
->add('field', 'text')
->getForm()
->add($child)
->createView()
;

$this->extension->setTheme($view, array('parent_label.html.twig'));
$this->extension->setTheme($view['child'], array('child_label.html.twig'));

$this->assertWidgetMatchesXpath($view, array(),
'/div
[
./input[@type="hidden"]
/following-sibling::div
[
./label[.="parent"]
/following-sibling::input[@type="text"]
]
/following-sibling::div
[
./label
/following-sibling::div
[
./div
[
./label[.="child"]
/following-sibling::input[@type="text"]
]
]
]
]
'
);
}

protected function renderEnctype(FormView $view)
{
return (string)$this->extension->renderEnctype($view);
Expand Down
@@ -0,0 +1,3 @@
{% block field_label %}
<label>child</label>
{% endblock field_label %}
@@ -0,0 +1,3 @@
{% block field_label %}
<label>parent</label>
{% endblock field_label %}

0 comments on commit bee505a

Please sign in to comment.