2
votes

Is it possible to add a translatable association in Sonata Admin, using DoctrineBehaviors Translatable feature?

I mean, something like that:

// InfoPageAdmin.php

->add('translations', 'a2lix_translations', [
    'fields' => [
        'title' => [
            'field_type' => 'text'
        ],
        'content' => [
            'field_type' => 'ckeditor',
            'config_name' => 'default'
        ],
        'slideshow' => [
            'field_type' => 'sonata_type_model_list'
        ]
    ]
])

Where 'slideshow' is translatable field, associated with other entity:

// InfoPageTranslation.php

/**
 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\PictureCollection", cascade={"persist"}, fetch="EAGER")
 * @ORM\JoinColumn(name="slideshow_id", referencedColumnName="id")
 */
protected $slideshow;

I got the following error:

ContextErrorException: Catchable Fatal Error: Argument 1 passed to Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer::__construct() must implement interface Sonata\AdminBundle\Model\ModelManagerInterface, null given, called in D:\XAMPP\htdocs\mega\app\cache\dev\classes.php on line 13492 and defined in D:\XAMPP\htdocs\mega\app\cache\dev\classes.php line 12628

I hope that my question is clear.

Thank you!

1

1 Answers

1
votes

Well, I have found the simple way to solve the problem. For example, I would like to have a different Gallery for every different language of InfoPage. So, I can achieve that in this way:

# InfoPageAdmin.php
->add('translations', 'a2lix_translations', [
    'fields' => [
        'gallery' => [
            'field_type' => 'entity',
            'class' => 'AppBundle:Gallery',
        ],
    ],
])

Here, Gallery is the field of InfoPage entity:

# AppBundle/Entity/InfoPage.php
/**
 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Gallery", cascade={"persist"}, fetch="EAGER")
 * @ORM\JoinColumn(name="gallery_id", referencedColumnName="id")
 */
protected $gallery;

I hope that my answer help someone. :)

Edit: If you want to use 'sonata_type_model_list' in translations, working workaround is described here: https://github.com/a2lix/TranslationFormBundle/issues/155.