瀏覽代碼

Fix labels due to Form Component changes...

Thomas Rabaix 13 年之前
父節點
當前提交
47fdb86770

+ 5 - 5
DependencyInjection/SonataAdminExtension.php

@@ -108,11 +108,11 @@ class SonataAdminExtension extends Extension
          * This is a work in progress, so for now it is hardcoded
          */
         $classes = array(
-            'email'    => 'sonata-medium',
-            'textarea' => 'sonata-medium',
-            'text'     => 'sonata-medium',
-            'choice'   => 'sonata-medium',
-            'integer'  => 'sonata-medium',
+            'email'    => 'span5',
+            'textarea' => 'span5',
+            'text'     => 'span5',
+            'choice'   => 'span5',
+            'integer'  => 'span5',
             'datetime' => 'sonata-medium-date',
             'date'     => 'sonata-medium-date'
         );

+ 0 - 1
Form/Extension/Field/Type/FormTypeFieldExtension.php

@@ -119,7 +119,6 @@ class FormTypeFieldExtension extends AbstractTypeExtension
             }
 
             $view->vars['attr'] = $attr;
-
         } else {
             $view->vars['sonata_admin_enabled'] = false;
         }

+ 29 - 9
Resources/views/Form/form_admin_fields.html.twig

@@ -12,35 +12,42 @@ file that was distributed with this source code.
 {# Labels #}
 {% block form_label %}
 {% spaceless %}
+    {% set label_attr = label_attr|merge({'class': label_attr.class|default('') ~ " control-label" }) %}
+
     {% if not compound %}
-        {% set attr = attr|merge({'for': id}) %}
+        {% set label_attr = label_attr|merge({'for': id}) %}
     {% endif %}
     {% if required %}
-        {% set attr = attr|merge({'class': attr.class|default('') ~ ' required'}) %}
+        {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
+    {% endif %}
+
+    {% if label is empty %}
+        {% set label = name|humanize %}
     {% endif %}
+
     {% if in_list_checkbox is defined and in_list_checkbox and widget is defined %}
         <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
             {{ widget|raw }}
             <span>
                 {% if not sonata_admin.admin%}
-                    {{- label -}}
+                    {{- label|trans({}, translation_domain) -}}
                 {% else %}
                     {{- label|trans({}, sonata_admin.admin.translationDomain) -}}
                 {% endif%}
             </span>
         </label>
     {% else %}
-        <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
+        <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
             {% if not sonata_admin.admin%}
-                {{ label }}
+                {{- label|trans({}, translation_domain) -}}
             {% else %}
-                {{ label|trans({}, sonata_admin.admin.translationDomain) }}
+                {{- label|trans({}, sonata_admin.admin.translationDomain) -}}
             {% endif%}
             {{ required ? '*' : '' }}
         </label>
     {% endif %}
 {% endspaceless %}
-{% endblock %}
+{% endblock form_label %}
 
 {% block widget_container_attributes_choice_widget %}
     {% spaceless %}
@@ -50,13 +57,26 @@ file that was distributed with this source code.
     {% endspaceless %}
 {% endblock %}
 
+{% block choice_widget_expanded %}
+{% spaceless %}
+    <ul {{ block('widget_container_attributes') }}>
+        {% for child in form %}
+            <li>
+                {{ form_widget(child) }}
+                {{ form_label(child) }}
+            </li>
+        {% endfor %}
+    </ul>
+{% endspaceless %}
+{% endblock choice_widget_expanded %}
+
 {% block choice_widget %}
 {% spaceless %}
     {% if expanded %}
         <ul {{ block('widget_container_attributes_choice_widget') }}>
         {% for child in form %}
             <li>
-                {{ form_label(child, null, { 'in_list_checkbox' : true, 'widget' : form_widget(child) } ) }}
+                {{ form_label(child, child.vars.label|default(null), { 'in_list_checkbox' : true, 'widget' : form_widget(child) } ) }}
             </li>
         {% endfor %}
         </ul>
@@ -88,7 +108,7 @@ file that was distributed with this source code.
                 {% if sonata_admin.field_description.options.name is defined %}
                     {{ form_label(form, sonata_admin.field_description.options.name, { 'attr' : {'class' : 'control-label'} }) }}
                 {% else %}
-                    {{ form_label(form, null, { 'attr' : {'class' : 'control-label'} }) }}
+                    {{ form_label(form, label|default(null), { 'attr' : {'class' : 'control-label'} }) }}
                 {% endif %}
             {% endblock %}