Parcourir la source

[Form] Revert the ability to override anything else than the text of the label while rendering a row

Victor Berchet il y a 14 ans
Parent
commit
2c1108ce6b

+ 0 - 9
src/Symfony/Bridge/Twig/Extension/FormExtension.php

@@ -122,15 +122,6 @@ class FormExtension extends \Twig_Extension
      */
     public function renderRow(FormView $view, array $variables = array())
     {
-        $variables = array_replace_recursive(
-            array(
-                'label'     => array(),
-                'widget'    => array(),
-                'attr'      => array(),
-            ),
-            $variables
-        );
-
         return $this->render($view, 'row', $variables);
     }
 

+ 3 - 3
src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

@@ -196,10 +196,10 @@
 
 {% block field_row %}
 {% spaceless %}
-    <div {% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}>
-        {{ form_label(form, null, label) }}
+    <div>
+        {{ form_label(form, label|default(null)) }}
         {{ form_errors(form) }}
-        {{ form_widget(form, widget) }}
+        {{ form_widget(form) }}
     </div>
 {% endspaceless %}
 {% endblock field_row %}

+ 3 - 3
src/Symfony/Bridge/Twig/Resources/views/Form/form_table_layout.html.twig

@@ -2,13 +2,13 @@
 
 {% block field_row %}
 {% spaceless %}
-    <tr {% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}>
+    <tr>
         <td>
-            {{ form_label(form, null, label) }}
+            {{ form_label(form, label|default(null)) }}
         </td>
         <td>
             {{ form_errors(form) }}
-            {{ form_widget(form, widget) }}
+            {{ form_widget(form) }}
         </td>
     </tr>
 {% endspaceless %}

+ 3 - 3
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/field_row.html.php

@@ -1,5 +1,5 @@
-<div <?php foreach($attr as $k => $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?>>
-    <?php echo $view['form']->label($form, null, $label) ?>
+<div>
+    <?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
     <?php echo $view['form']->errors($form) ?>
-    <?php echo $view['form']->widget($form, $widget) ?>
+    <?php echo $view['form']->widget($form) ?>
 </div>

+ 0 - 9
src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php

@@ -99,15 +99,6 @@ class FormHelper extends Helper
      */
     public function row(FormView $view, array $variables = array())
     {
-        $variables = array_replace_recursive(
-            array(
-                'label'     => array(),
-                'widget'    => array(),
-                'attr'      => array()
-            ),
-            $variables
-        );
-
         return $this->renderSection($view, 'row', $variables);
     }
 

+ 4 - 9
tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php

@@ -38,18 +38,13 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
     public function testRowOverrideVariables()
     {
         $view = $this->factory->createNamed('text', 'name')->createView();
-        $html = $this->renderRow($view, array(
-            'label'  => array('label' => 'foo&bar', 'attr' => array('class ' => 'label&class')),
-            'widget' => array('attr' => array('class' => 'widget&class')),
-            'attr'   => array('class' => 'row&class')
-
-        ));
+        $html = $this->renderRow($view, array('label' => 'foo&bar'));
 
         $this->assertMatchesXpath($html,
-'/div[@class="row&class"]
+'/div
     [
-        ./label[@for="name"][.="[trans]foo&bar[/trans]"][@class="label&class"]
-        /following-sibling::input[@id="name"][@class="widget&class"]
+        ./label[@for="name"][.="[trans]foo&bar[/trans]"]
+        /following-sibling::input[@id="name"]
     ]
 '
         );