Development

Changeset 13044

You must first sign up to be able to contribute.

Changeset 13044

Show
Ignore:
Timestamp:
11/16/08 22:56:45 (1 year ago)
Author:
fabien
Message:

[1.2] fixed embedded form saving when there is a non Doctrine form in the chain

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfDoctrinePlugin/trunk/lib/form/sfFormDoctrine.class.php

    r13042 r13044  
    194194   * Updates the values of the object with the cleaned up values. 
    195195   * 
     196   * @param  array $values An array of values 
     197   * 
    196198   * @return BaseObject The current updated object 
    197199   */ 
     
    208210 
    209211    // embedded forms 
    210     foreach ($this->embeddedForms as $name => $form) 
    211     { 
    212       if ($form instanceof sfFormDoctrine && is_array($values[$name])) 
     212    $this->updateObjectEmbeddedForms($values); 
     213 
     214    return $this->object; 
     215  } 
     216 
     217  /** 
     218   * Updates the values of the objects in embedded forms. 
     219   * 
     220   * @param array $values An array of values 
     221   * @param array $forms  An array of forms 
     222   */ 
     223  public function updateObjectEmbeddedForms($values, $forms = null) 
     224  { 
     225    if (is_null($forms)) 
     226    { 
     227      $forms = $this->embeddedForms; 
     228    } 
     229 
     230    foreach ($forms as $name => $form) 
     231    { 
     232      if (!is_array($values[$name])) 
     233      { 
     234        continue; 
     235      } 
     236 
     237      if ($form instanceof sfFormDoctrine) 
    213238      { 
    214239        $form->updateObject($values[$name]); 
    215240      } 
    216     } 
    217  
    218     return $this->object; 
    219   } 
    220    
     241      else 
     242      { 
     243        $this->updateObjectEmbeddedForms($values[$name], $form->getEmbeddedForms()); 
     244      } 
     245    } 
     246  } 
     247 
    221248  /** 
    222249   * Processes cleaned up values with user defined methods. 
     
    338365  } 
    339366 
    340   public function saveEmbeddedForms($con = null) 
     367  /** 
     368   * Saves embedded form objects. 
     369   * 
     370   * @param Connection $con   An optional Connection object 
     371   * @param array      $forms An array of forms 
     372   */ 
     373  public function saveEmbeddedForms($con = null, $forms = null) 
    341374  { 
    342375    if (is_null($con)) 
     
    345378    } 
    346379 
    347     foreach ($this->embeddedForms as $form) 
     380    if (is_null($forms)) 
     381    { 
     382      $forms = $this->embeddedForms; 
     383    } 
     384 
     385    foreach ($forms as $form) 
    348386    { 
    349387      if ($form instanceof sfFormDoctrine) 
     
    352390        $form->getObject()->save($con); 
    353391      } 
     392      else 
     393      { 
     394        $this->saveEmbeddedForms($con, $form->getEmbeddedForms()); 
     395      } 
    354396    } 
    355397  } 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.