I'm searching for a simple way to edit translated fields within a symfony2 form. I'm using the doctrine knp translatable extentions for translation of the entity. The form mixes not translated with translated properties in a special order. The form should be displayed (end edit) only in the active language. For example:
$builder
->add('key')
->add('translate1','text',array(
'property_path' => 'translations[de].translate1',
))
->add('mynumber')
->add('translate2','text',array(
'property_path' => 'translations[de].translate2',
))
If the language translations[de] does not exists i get an error: "Cannot read property "translate1" from an array... "
A2LiX Translation Form is not the solution, because it displays all translatabe fields in a single list.
Any ideas?
If you need to display the form fields in a specific order (using A2lix) you can do it like in this example:
Then in the view:
Actually i solved my problem with a custom from type with two event listeners for setting and getting translations values:
The fields are not mapped. translation property name and language can be provided directly.
And type inherit form basic text.
After define it as a twig extension service (translation_text) you can use it quite easy: