dev-master
9999999-dev
MIT
The Requires
- stof/doctrine-extensions-bundle ~1.2
- symfony/form ~3.2|~4.0
- symfony/framework-bundle ~2.7|~3.2|~4.0
- doctrine/orm ^2.5
The Development Requires
by Juan Miguel Besada
This bundle add a new FormType to simplify the creation of translatable forms using Gedmo Doctrine Extensions and StofDoctrineExtensionsBundle., (*1)
Open a command console, enter your project directory and execute:, (*2)
$ composer require juanmiguelbesada/doctrine-translatable-form-bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*3)
$ composer require juanmiguelbesada/doctrine-translatable-form-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*4)
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:, (*5)
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new JuanMiguelBesada\DoctrineTranslatableFormBundle\JuanMiguelBesadaDoctrineTranslatableFormBundle(), ); // ... } // ... }
Lastly, configure the default languages used by the TranslatableType, (*6)
juan_miguel_besada_doctrine_translatable_form: locales: ['es', 'en', 'fr'] #you can add as much as you need
<?php namespace AppBundle\Form; use Symfony\Component\Form\AbstractType; use JuanMiguelBesada\DoctrineTranslatableFormBundle\Form\TranslatableType; class CategoryType extends AbstractType { /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { // you can add the translatable fields $builder ->add("name", TranslatableType::class, array( 'label' => 'Name', 'type' => TextType::class, 'type_options' => array( 'required' => false, ... ) )) ->add("description", TranslatableType::class, array( 'type' => TextareaType::class, 'locales' => array('es', 'fr', 'de', 'gl'), //Define custom languages 'type_options' => array( 'attr' => array( 'class' => 'my_class' ), ... ) )) ->add('enabled') // you can add the rest of the fields using the standard way ; } /** * @param OptionsResolver $resolver */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\Category' )); } }
MIT