我正在使用symfony 5.2和Easyadmin 3。我试图在easyadmin中用A2Lix包实现翻译,当时我遇到了以下错误:
“翻译”字段的Doctrine类型是"4",EasyAdmin还不支持这一类型。
但是这种情况是不同的,因为我在easyadmin中实现了翻译。
有谁可以帮我?如何解决这个问题。
发布于 2021-01-27 14:09:32
最后,我找到了解决这个问题的方法。
我从下面的链接中找到了解决方案:
创建了一个翻译字段:
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('Активность'),
];
}这段代码将为任何面临此类问题的人节省时间。
https://stackoverflow.com/questions/65913957
复制相似问题