Commit 234a3c9a authored by Julien Fastré's avatar Julien Fastré
Browse files

translation of countries in form refs #317

parent bf52c347
......@@ -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 }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment