Browse Source

Merge remote branch 'vicb/form-collection-rendering'

* vicb/form-collection-rendering:
  [Form] Fix collection rendering
Fabien Potencier 14 years ago
parent
commit
c3bf2037df

+ 1 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/collection_label.html.php

@@ -0,0 +1 @@
+<label <?php echo $view['form']->attributes() ?>><?php echo $view->escape($view['translator']->trans($label)) ?></label>

+ 0 - 1
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/collection_row.html.php

@@ -1 +0,0 @@
-<?php echo $view['form']->render('form', 'widget', $renderer->all()); ?>

+ 6 - 0
src/Symfony/Bundle/TwigBundle/Resources/views/Form/div_layout.html.twig

@@ -10,6 +10,12 @@
 {% endspaceless %}
 {% endblock field_label %}
 
+{% block collection_label %}
+{% spaceless %}
+    <label {% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label>
+{% endspaceless %}
+{% endblock collection_label %}
+
 {% block field_errors %}
 {% spaceless %}
     {% if errors|length > 0 %}

+ 40 - 0
tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php

@@ -282,6 +282,46 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
         );
     }
 
+    public function testCollectionRow()
+    {
+        $collection = $this->factory->createNamedBuilder(
+            'collection',
+            'collection',
+            array('a', 'b'),
+            array('type' => 'text')
+        );
+
+        $form = $this->factory->createNamedBuilder('form', 'form')
+          ->add($collection)
+          ->getForm();
+
+        $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/div
+    [
+        ./input[@type="hidden"][@id="form__token"]
+        /following-sibling::div
+            [
+                ./label[not(@for)]
+                /following-sibling::div
+                    [
+                        ./div
+                            [
+                                ./label[@for="form_collection_0"]
+                                /following-sibling::input[@type="text"][@value="a"]
+                            ]
+                        /following-sibling::div
+                            [
+                                ./label[@for="form_collection_1"]
+                                /following-sibling::input[@type="text"][@value="b"]
+                            ]
+                    ]
+            ]
+    ]
+    [count(.//input)=3]
+'
+        );
+    }
+
     public function testForm()
     {
         $form = $this->factory->createNamedBuilder('form', 'name')