mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
translation of countries in form refs #317
This commit is contained in:
parent
bf52c347ee
commit
234a3c9a5f
@ -21,7 +21,10 @@
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
use Chill\MainBundle\Entity\Country;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* Extends choice to allow adding select2 library on widget
|
||||
@ -30,6 +33,17 @@ use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
*/
|
||||
class Select2CountryType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var RequestStack
|
||||
*/
|
||||
private $requestStack;
|
||||
|
||||
public function __construct(RequestStack $requestStack)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'select2_chill_country';
|
||||
@ -42,8 +56,11 @@ class Select2CountryType extends AbstractType
|
||||
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$locale = $this->requestStack->getCurrentRequest()->getLocale();
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
'class' => 'Chill\MainBundle\Entity\Country'
|
||||
'class' => 'Chill\MainBundle\Entity\Country',
|
||||
'property' => 'name['.$locale.']'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,10 @@ services:
|
||||
- "%locale%"
|
||||
tags:
|
||||
- { name: form.type, alias: translatable_string }
|
||||
chill.main.helper.translatable_string:
|
||||
class: Chill\MainBundle\Templating\TranslatableStringHelper
|
||||
arguments:
|
||||
- "@request_stack"
|
||||
|
||||
chill.main.form.type.select2choice:
|
||||
class: Chill\MainBundle\Form\Type\Select2ChoiceType
|
||||
@ -38,5 +42,7 @@ services:
|
||||
|
||||
chill.main.form.type.select2country:
|
||||
class: Chill\MainBundle\Form\Type\Select2CountryType
|
||||
arguments:
|
||||
- "@request_stack"
|
||||
tags:
|
||||
- { name: form.type, alias: select2_chill_country }
|
||||
|
Loading…
x
Reference in New Issue
Block a user