4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Extension\Core\EventListener
;
14 use Symfony\Component\Form\FormEvents
;
15 use Symfony\Component\Form\FormEvent
;
16 use Symfony\Component\EventDispatcher\EventSubscriberInterface
;
17 use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
;
20 * Takes care of converting the input from a single radio button
23 * @author Bernhard Schussek <bschussek@gmail.com>
25 class FixRadioInputListener
implements EventSubscriberInterface
29 private $placeholderPresent;
34 * @param ChoiceListInterface $choiceList
35 * @param Boolean $placeholderPresent
37 public function __construct(ChoiceListInterface
$choiceList, $placeholderPresent)
39 $this->choiceList
= $choiceList;
40 $this->placeholderPresent
= $placeholderPresent;
43 public function preSubmit(FormEvent
$event)
45 $value = $event->getData();
46 $index = current($this->choiceList
->getIndicesForValues(array($value)));
48 $event->setData(false !== $index ? array($index => $value) : ($this->placeholderPresent
? array('placeholder' => '') : array())) ;
52 * Alias of {@link preSubmit()}.
54 * @deprecated Deprecated since version 2.3, to be removed in 3.0. Use
55 * {@link preSubmit()} instead.
57 public function preBind(FormEvent
$event)
59 $this->preSubmit($event);
62 public static function getSubscribedEvents()
64 return array(FormEvents
::PRE_SUBMIT
=> 'preSubmit');