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:
$builder
->add('key')
->add('mynumber')
->add('translations', 'a2lix_translations', [
'required_locales' => ['de'], <-- your current locale
'fields' => [
'translate1' => [
# your field options
],
'translate2' => [
# your field options
],
))
Then in the view:
{% import "A2lixTranslationFormBundle::macros.html.twig" as a2lixTranslations %}
{{ form_errors(form_edit) }}
{{ form_start(form_edit) }}
{{ form_row(form_edit.key) }}
{{ a2lixTranslations.partialTranslations(form_edit.translations, ['translate1']) }}
{{ form_row(form_edit.mynumber) }}
{{ a2lixTranslations.partialTranslations(form_edit.translations, ['translate2']) }}
{{ form_end(form_edit) }}