juanmiguelbesada / doctrine-translatable-form-bundle
Installs: 368
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 3
Open Issues: 0
Type:symfony-bundle
Requires
- doctrine/orm: ^2.5
- stof/doctrine-extensions-bundle: ~1.2
- symfony/form: ~3.0|~4.0
- symfony/framework-bundle: ~3.0|~4.0
- symfony/property-access: ~3.0|~4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.12
This package is auto-updated.
Last update: 2024-10-29 05:22:39 UTC
README
This bundle add a new FormType to simplify the creation of translatable forms using Gedmo Doctrine Extensions and StofDoctrineExtensionsBundle.
Installation
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
$ composer require juanmiguelbesada/doctrine-translatable-form-bundle
Applications that don't use Symfony Flex
Step 1: Download the 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.
Step 2: Enable the Bundle
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(), ); // ... } // ... }
Step 3: Configure the Bundle
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
Usage
<?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' )); } }