uerka / translation-form-bundle
提供用于管理实体翻译的小部件
0.4.3
2018-03-31 13:38 UTC
Requires
- php: ^7.1.3
- knplabs/doctrine-behaviors: ~1.5
- symfony/config: ~3.4|~4.0
- symfony/dependency-injection: ^3.0|^4.0
- symfony/form: ^3.0|^4.0
This package is not auto-updated.
Last update: 2024-09-29 05:01:09 UTC
README
这是https://github.com/a2lix/TranslationFormBundle的简化版本。仅支持https://github.com/KnpLabs/DoctrineBehaviors。支持symfony4
##安装
composer require uerka/translation-form-bundle
添加到包
Symfony4 - bundles.php
return [ ... Uerka\TranslationFormBundle\UerkaTranslationFormBundle::class => ['all' => true],
Symfony3 - AppKernel.php
public function registerBundles() { $bundles = [ ... new Uerka\TranslationFormBundle\UerkaTranslationFormBundle(), }
配置
uerka_translation_form: locales: ["ru", "en"]
将主题添加到twig设置
twig: ... form_themes: ... - '@UerkaTranslationForm/form/fields.html.twig'
使用表单
... use Uerka\TranslationFormBundle\Form\Type\TranslationsType; class ExampleFormType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('translations', TranslationsType::class, [ 'locales' => ['ru', 'en', 'fr'], // optional, defaults to bundle's config 'required_locales' => ['en'], // optional, defaults to bundle's config (equals to locale option) 'fields' => [ 'name' => [ 'widget_class' => TextType::class, // optional, default TextType::class 'options' => [ // will be passed to field's options 'label' => 'form.label.name', ], ], 'shortDescription' => [ 'widget_class' => TextareaType::class, 'options' => [ 'label' => 'form.label.short_description', 'required' => false, ] ], ], ]); ... } ... }