setTranslationParameters()
,并在DashboardController
有关如何解决此问题的任何建议? 谢谢您的努力和时间。
写作,此功能在EasyAdmin中不存在,请参阅GitHub上的答案的链接。
https://github.com/easycorp/easyadminbundle/issues/4982
,但是,有一个不同的包裹可以解决:
doctrine-extensions/DoctrineExtensions
<?php
declare(strict_types=1);
namespace App\Controller\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, array $fieldsConfig = []): self
{
return (new self())
->setProperty($propertyName)
->setLabel($label)
->setFormType(TranslationsType::class)
->setFormTypeOptions([
'default_locale' => 'cz',
'fields' => $fieldsConfig,
]);
}
}
,然后安装knplabs/doctrineBehaviors
安装
TranslationField
public function configureFields(string $pageName): iterable
{
return [
TextField::new('title', 'title')->hideOnForm(),
TranslationField::new('translations', 'translations', [
'title' => [
'field_type' => TextType::class,
'required' => true,
]
// add more translatable properties into the array
])->setRequired(true)
->hideOnIndex()
];
}
//...
->setFormType(TranslationsType::class)
->addFormTheme('@A2lixTranslationForm/bootstrap_5_layout.html.twig')
//...