mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-23 10:44:24 +00:00
Form type for Languages (select2)
This commit is contained in:
parent
22df3cb17d
commit
79ccfb184a
64
Form/Type/Select2LanguageType.php
Normal file
64
Form/Type/Select2LanguageType.php
Normal 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.']'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
@ -54,7 +54,13 @@ services:
|
|||||||
- "@request_stack"
|
- "@request_stack"
|
||||||
tags:
|
tags:
|
||||||
- { name: form.type, alias: select2_chill_country }
|
- { 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:
|
chill.main.search_provider:
|
||||||
class: Chill\MainBundle\Search\SearchProvider
|
class: Chill\MainBundle\Search\SearchProvider
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user