This bundle add a new FormType to simplify the creation of translatable forms using Gedmo Doctrine Extensions and StofDoctrineExtensionsBundle.
Open a command console, enter your project directory and execute:
$ 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:
$ 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.
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?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
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'
));
}
}