Skip to content

Commit 71841c7

Browse files
committed
Revert "[Form] refactor RadioListMapper::mapDataToForm()"
closes #18173. This reverts commit 8f918e5.
1 parent 064aedf commit 71841c7

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/Symfony/Component/Form/Extension/Core/DataMapper/RadioListMapper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ public function __construct(ChoiceListInterface $choiceList)
3838
/**
3939
* {@inheritdoc}
4040
*/
41-
public function mapDataToForms($data, $radios)
41+
public function mapDataToForms($choice, $radios)
4242
{
43+
$valueMap = array_flip($this->choiceList->getValuesForChoices(array($choice)));
44+
4345
foreach ($radios as $radio) {
4446
$value = $radio->getConfig()->getOption('value');
45-
$radio->setData($value === $data ? true : false);
47+
$radio->setData(isset($valueMap[$value]) ? true : false);
4648
}
4749
}
4850

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
143143
$event->setData(null);
144144
}
145145
});
146-
// For radio lists, pre selection of the choice needs to pre set data
147-
// with the string value so it can be matched in
148-
// {@link \Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper::mapDataToForms()}
149-
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
150-
$choiceList = $event->getForm()->getConfig()->getOption('choice_list');
151-
$value = current($choiceList->getValuesForChoices(array($event->getData())));
152-
$event->setData((string) $value);
153-
});
154146
}
155147
} elseif ($options['multiple']) {
156148
// <select> tag with "multiple" option

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy