Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

symfony - EasyAdmin 3 Translation Error, The Doctrine type of the "translations" field is "4", which is not supported by EasyAdmin yet

I am using symfony 5.2 and Easyadmin 3. I try to implement translation with A2Lix bundle in easyadmin at that time i got error like:

The Doctrine type of the "translations" field is "4", which is not supported by EasyAdmin yet.

I have checked with Symfony EasyAdmin 3.x ManyToMany error when adding : The Doctrine type of the .... field is "4", which is not supported by EasyAdmin yet

But this case is different becuase i am implementing translation in easyadmin.

Can anyone Help me? How to solve it.

question from:https://stackoverflow.com/questions/65913957/easyadmin-3-translation-error-the-doctrine-type-of-the-translations-field-is

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Finally i got a way to solve this issue.

I found solution from below link:

https://github.com/EasyCorp/EasyAdminBundle/issues/1621

Created a translation field:

namespace AppAdminField;

use A2lixTranslationFormBundleFormTypeTranslationsType;
use EasyCorpBundleEasyAdminBundleContractsFieldFieldInterface;
use EasyCorpBundleEasyAdminBundleFieldFieldTrait;

final class TranslationField implements FieldInterface
{
    use FieldTrait;

    public static function new(string $propertyName, ?string $label = null, $fieldsConfig = []): self
    {
        return (new self())
            ->setProperty($propertyName)
            ->setLabel($label)
            ->setFormType(TranslationsType::class)
            ->setFormTypeOptions(
                [
                    'default_locale' => '%locale%',
                    'fields' => $fieldsConfig,
                ]
            );
    }
}

After creating field implement in crud controller:

public function configureFields(string $pageName): iterable
    {
        $fieldsConfig = [
            'subject' => [
                'field_type' => TextareaType::class,
                'required' => true,
                'label' => 'Тема',
            ],
            'text' => [
                'field_type' => CKEditorType::class,
                'required' => true,
                'label' => 'Текст',
            ],
        ];

        return [
            TranslationField::new('translations', 'Переводы', $fieldsConfig)
                ->setRequired(true)
                ->hideOnIndex(),
            TextField::new('subject')->hideOnForm()->setLabel('Тема'),
            BooleanField::new('isActive')->setLabel('Активность'),
        ];
    }

This code will save time of anybody who face this kind of issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...