Form type for Languages (select2)

This commit is contained in:
Marc Ducobu 2014-11-26 12:58:01 +01:00
parent 22df3cb17d
commit 79ccfb184a
2 changed files with 72 additions and 2 deletions

View File

@ -0,0 +1,64 @@
<?php
/*
* Chill is a software for social workers
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\MainBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Chill\MainBundle\Entity\Language;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Extends choice to allow adding select2 library on widget for languages (multiple)
*/
class Select2LanguageType extends AbstractType
{
/**
*
* @var RequestStack
*/
private $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function getName()
{
return 'select2_chill_language';
}
public function getParent()
{
return 'select2_entity';
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$locale = $this->requestStack->getCurrentRequest()->getLocale();
$resolver->setDefaults(array(
'class' => 'Chill\MainBundle\Entity\Language',
'property' => 'name['.$locale.']'
));
}
}

View File

@ -54,7 +54,13 @@ services:
- "@request_stack"
tags:
- { name: form.type, alias: select2_chill_country }
chill.main.form.type.select2language:
class: Chill\MainBundle\Form\Type\Select2LanguageType
arguments:
- "@request_stack"
tags:
- { name: form.type, alias: select2_chill_language }
chill.main.search_provider:
class: Chill\MainBundle\Search\SearchProvider