public function setValue($value)
 {
     if (is_object($value) && $value !== $this->value) {
         if ($value->id) {
             $doctrine = $this->getLoops()->getService("doctrine");
             $doctrine->merge($value);
             $this->setForm(new UpdateEntityForm($value, $this->__filter, $this->__fields, $context, $loops));
         } else {
             $this->setForm(new PersistEntityForm($value, $this->__filter, $this->__fields, $context, $loops));
         }
     }
     return parent::setValue($value);
 }
Exemple #2
0
 public function setValue($value)
 {
     if (is_array($value)) {
         $value = new ArrayObject($value);
     }
     $current = $this->subform->getFormElements();
     foreach (array_keys($current) as $key) {
         $this->subform->offsetUnset($key);
     }
     if ($value instanceof ArrayObject) {
         $values = $value->toArray();
     } elseif ($value instanceof Traversable) {
         $values = iterator_to_array($value);
     } else {
         $values = (array) $value;
     }
     static $meh = 0;
     if ($meh++ > 40) {
         throw new \Exception("Meh");
     }
     foreach ($values as $k => $v) {
         $element = array_key_exists($k, $current) ? $current[$k] : Misc::deepClone($this->newelement);
         $element->setValue($v);
         $value->offsetSet($k, $element->getValue(FALSE));
         $this->subform->offsetSet($k, $element);
     }
     return parent::setValue($value);
 }