Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 public function __construct($key, array $options = array())
 {
     // Override parent option
     // \DateTime objects are never edited by reference, because
     // we treat them like value objects
     $this->addOption('by_reference', false);
     parent::__construct($key, $options);
 }
Beispiel #2
0
 /**
  * Transforms a checkbox/radio button array to a single choice or an array
  * of choices.
  *
  * The input value is an array with the choices as keys and true/false as
  * values, depending on whether a given choice is selected. The output
  * is an array with the selected choices or a single selected choice.
  *
  * @param  mixed $value  An array if "expanded" or "multiple" is set to true,
  *                       a scalar value otherwise.
  * @return mixed $value  An array if "multiple" is set to true, a scalar
  *                       value otherwise.
  */
 protected function reverseTransform($value)
 {
     if ($this->getOption('expanded')) {
         $choices = array();
         foreach ($value as $choice => $selected) {
             if ($selected) {
                 $choices[] = $choice;
             }
         }
         if ($this->getOption('multiple')) {
             $value = $choices;
         } else {
             $value = count($choices) > 0 ? current($choices) : null;
         }
     }
     return parent::reverseTransform($value);
 }
 /**
  * Sets the locale of this field.
  *
  * @see Localizable
  */
 public function setLocale($locale)
 {
     parent::setLocale($locale);
     $this->initFormatter();
     if ($this->getOption('widget') === self::CHOICE) {
         $this->addChoiceFields();
     }
 }