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 list of checkboxes to a correctly
23 * @author Bernhard Schussek <bschussek@gmail.com>
25 class FixCheckboxInputListener
implements EventSubscriberInterface
32 * @param ChoiceListInterface $choiceList
34 public function __construct(ChoiceListInterface
$choiceList)
36 $this->choiceList
= $choiceList;
39 public function preSubmit(FormEvent
$event)
41 $values = (array) $event->getData();
42 $indices = $this->choiceList
->getIndicesForValues($values);
44 $event->setData(count($indices) > 0 ? array_combine($indices, $values) : array());
48 * Alias of {@link preSubmit()}.
50 * @deprecated Deprecated since version 2.3, to be removed in 3.0. Use
51 * {@link preSubmit()} instead.
53 public function preBind(FormEvent
$event)
55 $this->preSubmit($event);
58 public static function getSubscribedEvents()
60 return array(FormEvents
::PRE_SUBMIT
=> 'preSubmit');