Translations are not saved correctly using A2lix Translation + KnpLabs DoctrineBehaviors

271 Views Asked by At

In my Symfony project I use SonataAdminBundle and A2lixTranslationForm + KnpLabsDoctrineBehaviors bundles for multi-language support.

I have Serial and Episode entities which use standard OneToMany and ManyToOne relationship. I display episodes using sonata_type_collection:

->add('episodes', 'sonata_type_collection', [
        'by_reference' => false,
    ], 
    [
        'edit' => 'inline',
        'inline' => 'table',
    ]
)

By default A2lixTranslation bundle displays translatable fields under each other. However, I need to display each translation field of the episode in its own column. In order to achieve this, I created three virtual fields with the same property_path:

           ->add('episode_title', 'a2lix_translations', [
                'property_path' => 'translations',
                'fields' => [
                    'title' => [
                        'attr' => [
                            'pattern' => false,
                        ],
                        'label' => false,
                    ],
                ],
                'exclude_fields' => ['subTitle', 'description'],
                'label' => 'Title',
            ])
            ->add('episode_subtitle', 'a2lix_translations', [
                'property_path' => 'translations',
                'fields' => [
                    'subTitle' => [
                        'label' => false,
                    ],
                ],
                'exclude_fields' => ['title', 'description'],
                'label' => 'Subtitle',
                'required' => false,
            ])
            ->add('episode_description', 'a2lix_translations', [
                'property_path' => 'translations',
                'fields' => [
                    'description' => [
                        'field_type' => 'textarea',
                        'label' => false,
                    ],
                ],
                'exclude_fields' => ['title', 'subTitle'],
                'label' => 'Description',
                'required' => false,
            ])

As you can see, I display only one field in each a2lix_translations form.

But I faced the following problem: only the last field value (description in this case) is saved when I add new episode using Add new button of the collection form and then clicking Update button of the parent (Serial) form. Wherein already existing episodes are saved correctly if edited.

Could you please point me why is this happening and how to fix the issue. I suppose each translations form values rewrite the previous ones, but why do this work normally when saving existing records? Or maybe there is another way to display each field in the own column in sonata collection form, this also will be helpful.

Thank you.

0

There are 0 best solutions below