【问题标题】:EasyAdmin 3 Translation Error, The Doctrine type of the "translations" field is "4", which is not supported by EasyAdmin yetEasyAdmin 3翻译错误,“翻译”字段的Doctrine类型为“4”,EasyAdmin尚不支持
【发布时间】:2021-04-30 23:33:09
【问题描述】:

我正在使用 symfony 5.2 和 Easyadmin 3。当时我尝试在 easyadmin 中使用 A2Lix 包实现翻译,但出现如下错误:

“translations”字段的Doctrine类型是“4”,不是 EasyAdmin 还支持。

我已经和Symfony EasyAdmin 3.x ManyToMany error when adding : The Doctrine type of the .... field is "4", which is not supported by EasyAdmin yet核实过

但这种情况不同,因为我在 easyadmin 中实现翻译。

谁能帮帮我?如何解决。

【问题讨论】:

    标签: symfony translation a2lix-translation easyadmin3


    【解决方案1】:

    终于有办法解决这个问题了。

    我从以下链接找到了解决方案:

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

    创建了翻译字段:

    namespace App\Admin\Field;
    
    use A2lix\TranslationFormBundle\Form\Type\TranslationsType;
    use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
    use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
    
    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,
                    ]
                );
        }
    }
    

    在 crud 控制器中创建字段实现后:

    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('Активность'),
            ];
        }
    

    此代码将为遇到此类问题的任何人节省时间。

    【讨论】:

      猜你喜欢
      • 2020-10-27
      • 1970-01-01
      • 2022-06-25
      • 1970-01-01
      • 2021-02-10
      • 2015-06-03
      • 2021-12-21
      • 1970-01-01
      • 2018-11-03
      相关资源
      最近更新 更多