Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function mapDataToForms($choice, $radios)
 {
     $valueMap = array_flip($this->choiceList->getValuesForChoices(array($choice)));
     foreach ($radios as $radio) {
         $value = $radio->getConfig()->getOption('value');
         $radio->setData(isset($valueMap[$value]) ? true : false);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getValuesForChoices(array $choices)
 {
     if (!$this->loadedList) {
         return $this->loader->loadValuesForChoices($choices, $this->value);
     }
     return $this->loadedList->getValuesForChoices($choices);
 }
 /**
  * {@inheritdoc}
  */
 public function mapDataToForms($choices, $checkboxes)
 {
     if (null === $choices) {
         $choices = array();
     }
     if (!is_array($choices)) {
         throw new TransformationFailedException('Expected an array.');
     }
     try {
         $valueMap = array_flip($this->choiceList->getValuesForChoices($choices));
     } catch (\Exception $e) {
         throw new TransformationFailedException('Can not read the choices from the choice list.', $e->getCode(), $e);
     }
     foreach ($checkboxes as $checkbox) {
         $value = $checkbox->getConfig()->getOption('value');
         $checkbox->setData(isset($valueMap[$value]) ? true : false);
     }
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function getValuesForChoices(array $choices)
 {
     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->getValuesForChoices($choices);
     }
     return $this->loader->loadValuesForChoices($choices, $this->value);
 }
 public function testGetValuesForChoicesEmpty()
 {
     $this->assertSame(array(), $this->list->getValuesForChoices(array()));
 }
 public function testGetChoicesForValuesWithNull()
 {
     $values = $this->list->getValuesForChoices(array(null));
     $this->assertNotEmpty($this->list->getChoicesForValues($values));
 }