Wallogit.com
2017 © Pedro PelĆ”ez
This bundle of symfony2
Este bundle tem o objetivo de alterar o comportamento do A2lixFormBundle que Ć© utilizado para renderizar o formulario de multi idiomas, (*1)
Adicionar no composer a instalação do A2lixFormBundle, (*2)
composer require a2lix/translation-form-bundle
Adicionar as seguintes linhas no arquivo app/AppKernel.php, (*3)
# app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new A2lix\TranslationFormBundle\A2lixTranslationFormBundle(),
new A2C\Bundle\TranslationFormBundle\A2CTranslationFormBundle(),
new Knp\DoctrineBehaviors\Bundle\DoctrineBehaviorsBundle(),
// ...
);
}
Configuração do app/config/config.yml, (*4)
# Translate Form a2lix a2lix_translation_form: locale_provider: locale_doctrine_provider locales: [en_US] default_locale: en_US manager_registry: doctrine templating: "BaconTranslationFormBundle::default.html.twig" #Bacon TranslationForm bacon_translation_form: class_language_provider: Bacon\Bundle\LanguageBundle\Entity\Language
Para utilizar vocĆŖ deve implementar as 2 interface disponĆveis, (*5)
Deve ficar algo mais ou menos assim:, (*6)
# src/AppBundle/Entity/Language.php
<?php
namespace AppBundle\Entity;
use A2C\Bundle\CoreBundle\Entity\BaseEntity;
use A2C\Bundle\TranslationFormBundle\Locale\EntityInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Language
* @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\LanguageRepository")
* @ORM\Table(name="language")
*/
class Language extends BaseEntity implements EntityInterface
{
// --------
/**
* @ORM\Column(name="acron",type="string",length=2,nullable=false)
*/
private $acron;
/**
* @ORM\Column(name="locale",type="string",length=5,nullable=false)
*/
private $locale;
public function getAcron()
{
return $this->acron;
}
public function getLocale()
{
return $this->locale;
}
// --------
}
# src/AppBundle/Entity/Repository/LanguageRepository.php
<?php
namespace AppBundle\Entity\Repository;
use Bacon\Bundle\TranslationFormBundle\Locale\RepositoryInterface;
use Doctrine\ORM\EntityRepository;
class LanguageRepository extends EntityRepository implements RepositoryInterface
{
// --------
/**
* @return array
*/
public function getAllLocale()
{
$queryBuilder = $this->createQueryBuilder('l');
$queryBuilder->orderBy('l.orderBy','DESC');
$query = $queryBuilder->getQuery();
$query->useResultCache(true,60,md5('bacon_cache_locale_provider'));
return $query->getResult();
}
// --------
}