2017 © Pedro Peláez
 

symfony-bundle doctrine-translatable-form-bundle

image

juanmiguelbesada/doctrine-translatable-form-bundle

  • Friday, July 27, 2018
  • by juanmiguelbesada
  • Repository
  • 1 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

DoctrineTranslatableFormBundle

This bundle add a new FormType to simplify the creation of translatable forms using Gedmo Doctrine Extensions and StofDoctrineExtensionsBundle., (*1)

Installation

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:, (*2)

$ 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:, (*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)

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:, (*5)

<?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, (*6)

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'
        ));
    }
}

The Versions