首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >翻译错误,“EasyAdmin”字段的原则类型为"4",EasyAdmin还不支持该类型

翻译错误,“EasyAdmin”字段的原则类型为"4",EasyAdmin还不支持该类型
EN

Stack Overflow用户
提问于 2021-01-27 06:31:03
回答 1查看 1.6K关注 0票数 0

我正在使用symfony 5.2和Easyadmin 3。我试图在easyadmin中用A2Lix包实现翻译,当时我遇到了以下错误:

“翻译”字段的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中实现了翻译。

有谁可以帮我?如何解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-27 14:09:32

最后,我找到了解决这个问题的方法。

我从下面的链接中找到了解决方案:

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

创建了一个翻译字段:

代码语言:javascript
复制
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控制器中创建字段实现之后:

代码语言:javascript
复制
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('Активность'),
        ];
    }

这段代码将为任何面临此类问题的人节省时间。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65913957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档