Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove or customize the embeded form label

When I set up my formtype file like this:

$builder->add( 'producer', new ProducerType() );

it always return me a general title(label) for the embeded form, like "producer", how can I remove or customize this label?

UPDATE: the latest Fosuserbundle has been removed this annoyed lable

like image 553
luxury Avatar asked Dec 15 '22 22:12

luxury


2 Answers

The correct(?) way of removing the label is to set it to false.

$builder->add( 'producer', new ProducerType(), array( 'label' => false ));

Then the tag won't be rendered at all. Altough it's somehow missing in the documentation at the moment, you can refactor this behaviour by looking at the default twig form styles (3rd line):

{% block form_label %}
{% spaceless %}
    {% if label is not sameas(false) %}
        {% 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 %}
        <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
    {% endif %}
{% endspaceless %}
{% endblock form_label %}

Those twig styles are also a great start for form customization. More on this topic can be found in this cookbook entry.

like image 56
althaus Avatar answered Jan 13 '23 13:01

althaus


you can try adding a label as an option, depending on what options ProductType is inheriting this may be enough.

$builder->add('producer', new ProducerType(), array('label' => 'Some Label'));
like image 26
MDrollette Avatar answered Jan 13 '23 14:01

MDrollette