Bläddra i källkod

added script[type="text/html"] collection prototype to form themes

Kris Wallsmith 14 år sedan
förälder
incheckning
0df338fdb1

+ 9 - 0
src/Symfony/Bridge/Twig/Resources/views/Form/div_layout.html.twig

@@ -276,3 +276,12 @@
     {{ block('field_widget') }}
 {% endspaceless %}
 {% endblock email_widget %}
+
+{% block collection_widget %}
+{% spaceless %}
+    {{ block('form_widget') }}
+    {% if prototype %}
+    <script type="text/html" id="{{ id }}_prototype">{{ form_row(prototype) }}</script>
+    {% endif %}
+{% endspaceless %}
+{% endblock collection_widget %}

+ 5 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/collection_widget.html.php

@@ -0,0 +1,5 @@
+<?php $view->render('FrameworkBundle:Form:form_widget.html.php', array('form' => $form)) ?>
+
+<?php if (isset($prototype)): ?>
+<script type="text/html" id="<?php echo $view->escape($id) ?>_prototype"><?php echo $view['form']->row($prototype) ?></script>
+<?php endif; ?>

+ 17 - 0
tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

@@ -1119,6 +1119,23 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
     [@type="url"]
     [@name="na&me"]
     [@value="http://www.google.com?foo1=bar1&foo2=bar2"]
+'
+        );
+    }
+
+    public function testCollectionPrototype()
+    {
+        $form = $this->factory->createNamedBuilder('form', 'na&me', array('items' => array('one', 'two', 'three')))
+            ->add('items', 'collection', array('allow_add' => true))
+            ->getForm()
+            ->createView();
+
+        $html = $this->renderWidget($form);
+
+        $this->assertMatchesXpath($html,
+'//script
+    [@id="na&me_items_prototype"]
+    [@type="text/html"]
 '
         );
     }