8000 [Form] Fix twig theme inheritance · 77web/symfony@bee505a · GitHub
[go: up one dir, main page]

Skip to content

Commit bee505a

Browse files
committed
[Form] Fix twig theme inheritance
1 parent 882a8e3 commit bee505a

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,18 @@ protected function getTemplates(FormView $view)
248248
{
249249
if (!$this->templates->contains($view)) {
250250
// defaults
251-
$all = $this->resources;
251+
$all = array();
252252

253253
// themes
254254
$parent = $view;
255255
do {
256256
if (isset($this->themes[$parent])) {
257-
$all = array_merge($all, $this->themes[$parent]);
257+
$all = array_merge($this->themes[$parent], $all);
258258
}
259259
} while ($parent = $parent->getParent());
260260

261+
$all = array_merge($this->resources, $all);
262+
261263
$templates = array();
262264
foreach ($all as $resource) {
263265
if (!$resource instanceof \Twig_Template) {

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,48 @@ protected function setUp()
4848
$this->extension->initRuntime($environment);
4949
}
5050

51+
public function testThemeInheritance()
52+
{
53+
$child = $this->factory->createNamedBuilder('form', 'child')
54+
->add('field', 'text')
55+
->getForm();
56+
57+
$view = $this->factory->createNamedBuilder('form', 'parent')
58+
->add('field', 'text')
59+
->getForm()
60+
->add($child)
61+
->createView()
62+
;
63+
64+
$this->extension->setTheme($view, array('parent_label.html.twig'));
65+
$this->extension->setTheme($view['child'], array('child_label.html.twig'));
66+
67+
$this->assertWidgetMatchesXpath($view, array(),
68+
'/div
69+
[
70+
./input[@type="hidden"]
71+
/following-sibling::div
72+
[
73+
./label[.="parent"]
74+
/following-sibling::input[@type="text"]
75+
]
76+
/following-sibling::div
77+
[
78+
./label
79+
/following-sibling::div
80+
[
81+
./div
82+
[
83+
./label[.="child"]
84+
/following-sibling::input[@type="text"]
85+
]
86+
]
87+
]
88+
]
89+
'
90+
);
91+
}
92+
5193
protected function renderEnctype(FormView $view)
5294
{
5395
return (string)$this->extension->renderEnctype($view);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% block field_label %}
2+
<label>child</label>
3+
{% endblock field_label %}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% block field_label %}
2+
<label>parent</label>
3+
{% endblock field_label %}

0 commit comments

Comments
 (0)
0