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
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.
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'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With