Skip to content

Commit

Permalink
Merge pull request #1168 from EmmanuelVella/label-render
Browse files Browse the repository at this point in the history
Add form label_render option
  • Loading branch information
rande committed Feb 13, 2013
2 parents e2d5df6 + 8bde174 commit 54e161e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
13 changes: 13 additions & 0 deletions Resources/doc/reference/form_types.rst
Expand Up @@ -147,3 +147,16 @@ The type has one extra parameter :
'choices' => Delivery::getStatusList(),
'catalogue' => 'SonataOrderBundle'
))
Types options
-------------

General
^^^^^^^

- ``label``: You can set the ``label`` option to ``false`` if you don't want to show it.

.. code-block:: php
<?php
$form->add('status', null, array('label' => false);
58 changes: 30 additions & 28 deletions Resources/views/Form/form_admin_fields.html.twig
Expand Up @@ -12,39 +12,41 @@ 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 label is not sameas(false) %}
{% set label_attr = label_attr|merge({'class': label_attr.class|default('') ~ " control-label" }) %}

{% if not compound %}
{% set label_attr = label_attr|merge({'for': id}) %}
{% endif %}
{% if required %}
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
{% endif %}
{% if not compound %}
{% set label_attr = label_attr|merge({'for': id}) %}
{% endif %}
{% if 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 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 %}
{% 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|trans({}, translation_domain) -}}
{% else %}
{{- label|trans({}, sonata_admin.admin.translationDomain) -}}
{% endif%}
</span>
</label>
{% else %}
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
{% if not sonata_admin.admin%}
{{- label|trans({}, translation_domain) -}}
{% else %}
{{- label|trans({}, sonata_admin.admin.translationDomain) -}}
{% endif%}
</span>
</label>
{% else %}
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
{% if not sonata_admin.admin%}
{{- label|trans({}, translation_domain) -}}
{% else %}
{{ sonata_admin.admin.trans(label) }}
{% endif %}
{{ required ? '*' : '' }}
</label>
{{ sonata_admin.admin.trans(label) }}
{% endif %}
{{ required ? '*' : '' }}
</label>
{% endif %}
{% endif %}
{% endspaceless %}
{% endblock form_label %}
Expand Down

0 comments on commit 54e161e

Please sign in to comment.