I'm starting developing with Symfony2 and I have some problems with Forms. I used console to generate form fields based on my Entity. Everything looks great but I have to change labels of fields. When it comes to idCapacityUnit its based on another Entity and Symfony made that this field looks like "select". Now I want to change label of this field. So I used this code:
...
->add('idCapacityUnit', 'choice', array('label' => 'My label'))
but Symfony throws an error that I want to put wrong data type to it. Do I need to create another Data Transformer for this?
$builder
->add('nameShort', 'text', array('label' => 'Nazwa krótka'))
->add('capacityValue', 'text', array('label' => 'Pojemność'))
->add('idCapacityUnit', 'choice', array('label' => 'Jednostka'))
->add('idCapacityUnit')
->add('priceDetail')
->add($builder->create('isPackage', 'checkbox')->addModelTransformer($transformer))
->add('lifeTime')
->add('components')
->add('isActive');
Maybe there is a way to put there something like that:
->add('idCapacityUnit', 'customEntityType:choice', array('label' => 'Jednostka'))
Also I don't know how to put label values in language file. I tried to:
- Create language file in path src\Vendor\NameOfBundle\Resources\translations\VendorNameOfBundle.en.yml
- Then in *Type class I wrote array('label' => 'form.labels.name_short')
in language file I have:
form:
labels:
name_short: "Nazwa krótka"
then in browser I see form.labels.name_short...