/** * {@inheritdoc} */ public function mapFormsToData($radios, &$choice) { $choice = null; foreach ($radios as $radio) { if ($radio->getData()) { if ('placeholder' === $radio->getName()) { return; } $value = $radio->getConfig()->getOption('value'); $choice = current($this->choiceList->getChoicesForValues(array($value))); return; } } }
/** * {@inheritdoc} */ public function mapFormsToData($checkboxes, &$choices) { $values = array(); foreach ($checkboxes as $checkbox) { if ($checkbox->getData()) { // construct an array of choice values $values[] = $checkbox->getConfig()->getOption('value'); } } try { $choices = $this->choiceList->getChoicesForValues($values); } catch (\Exception $e) { throw new TransformationFailedException('Can not read the values from the choice list.', $e->getCode(), $e); } }
/** * {@inheritdoc} */ public function getChoicesForValues(array $values) { if (!$this->loadedList) { return $this->loader->loadChoicesForValues($values, $this->value); } return $this->loadedList->getChoicesForValues($values); }
/** * {@inheritdoc} */ public function loadChoicesForValues(array $values, $value = null) { if (empty(array_filter($values))) { return []; } if (!$this->choiceList) { $this->loadChoiceList($value); } return $this->choiceList->getChoicesForValues($values); }
/** * {@inheritdoc} */ public function getChoicesForValues(array $values) { if ($this->loaded) { // Check whether the loader has the same cache if ($this->loadedList !== $this->loader->loadChoiceList($this->value)) { @trigger_error(sprintf('Caching the choice list in %s is deprecated since 3.1 and will not happen in 4.0. Cache the list in the %s instead.', __CLASS__, ChoiceLoaderInterface::class), E_USER_DEPRECATED); } return $this->loadedList->getChoicesForValues($values); } return $this->loader->loadChoicesForValues($values, $this->value); }
public function testGetChoicesForValuesEmpty() { $this->assertSame(array(), $this->list->getChoicesForValues(array())); }
public function testGetChoicesForValuesWithNull() { $values = $this->list->getValuesForChoices(array(null)); $this->assertNotEmpty($this->list->getChoicesForValues($values)); }