如何在EasyAdmin中配置可翻译的实体? 我在Symfony 5项目中使用可翻译和EasyAdmin,我配置了2种语言。 问题是我需要能够在EasyAdmin中编辑唱片的不同语言,我有Checke ...

问题描述 投票:0回答:1
因此,我在代码方面有点陷入困境,我尝试在实体CRUD控制器内配置

setTranslationParameters(),并在DashboardController

中更改某些配置,但是,我认为这不是正确的方法。

有关如何解决此问题的任何建议? 谢谢您的努力和时间。

写作,此功能在EasyAdmin中不存在,请参阅GitHub上的答案的链接。
https://github.com/easycorp/easyadminbundle/issues/4982

,但是,有一个不同的包裹可以解决:

symfony translation easyadmin
1个回答
5
投票
取消

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

安装
    a2lix/translation-form-bundle
  1. 创建翻译字段:
    
    
  2. TranslationField
  3. 使用管理员内部的crud控制器内部:
  4. 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() ]; }

    我建议通过添加“ Formtheme”来维护A2LIX选项卡来增强Kierra的答案。
  1. //... ->setFormType(TranslationsType::class) ->addFormTheme('@A2lixTranslationForm/bootstrap_5_layout.html.twig') //...
        
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.