Beispiel #1
0
 /**
  * Transforms a single choice or an array of choices to a format appropriate
  * for the nested checkboxes/radio buttons.
  *
  * The result is an array with the options as keys and true/false as values,
  * depending on whether a given option is selected. If this field is rendered
  * as select tag, the value is not modified.
  *
  * @param  mixed $value  An array if "multiple" is set to true, a scalar
  *                       value otherwise.
  * @return mixed         An array if "expanded" or "multiple" is set to true,
  *                       a scalar value otherwise.
  */
 protected function transform($value)
 {
     if ($this->getOption('expanded')) {
         $value = parent::transform($value);
         $choices = $this->getOption('choices');
         foreach ($choices as $choice => $_) {
             $choices[$choice] = $this->getOption('multiple') ? in_array($choice, (array) $value, true) : $choice === $value;
         }
         return $choices;
     }
     return parent::transform($value);
 }
Beispiel #2
0
 /**
  * Transforms a single choice or an array of choices to a format appropriate
  * for the nested checkboxes/radio buttons.
  *
  * The result is an array with the options as keys and true/false as values,
  * depending on whether a given option is selected. If this field is rendered
  * as select tag, the value is not modified.
  *
  * @param  mixed $value  An array if "multiple" is set to true, a scalar
  *                       value otherwise.
  * @return mixed         An array if "expanded" or "multiple" is set to true,
  *                       a scalar value otherwise.
  */
 protected function transform($value)
 {
     if ($this->isExpanded()) {
         $value = parent::transform($value);
         $choices = $this->getChoices();
         foreach ($choices as $choice => $_) {
             $choices[$choice] = $this->isMultipleChoice() ? in_array($choice, (array) $value, true) : $choice === $value;
         }
         return $choices;
     }
     return parent::transform($value);
 }