Development

Changeset 13043

You must first sign up to be able to contribute.

Changeset 13043

Show
Ignore:
Timestamp:
11/16/08 22:56:26 (5 years ago)
Author:
fabien
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelPlugin/trunk/lib/form/sfFormPropel.class.php

    r13041 r13043  
    184184   * Updates the values of the object with the cleaned up values. 
    185185   * 
     186   * @param  array $values An array of values 
     187   * 
    186188   * @return BaseObject The current updated object 
    187189   */ 
     
    198200 
    199201    // embedded forms 
    200     foreach ($this->embeddedForms as $name => $form) 
    201     { 
    202       if ($form instanceof sfFormPropel && is_array($values[$name])) 
     202    $this->updateObjectEmbeddedForms($values); 
     203 
     204    return $this->object; 
     205  } 
     206 
     207  /** 
     208   * Updates the values of the objects in embedded forms. 
     209   * 
     210   * @param array $values An array of values 
     211   * @param array $forms  An array of forms 
     212   */ 
     213  public function updateObjectEmbeddedForms($values, $forms = null) 
     214  { 
     215    if (is_null($forms)) 
     216    { 
     217      $forms = $this->embeddedForms; 
     218    } 
     219 
     220    foreach ($forms as $name => $form) 
     221    { 
     222      if (!is_array($values[$name])) 
     223      { 
     224        continue; 
     225      } 
     226 
     227      if ($form instanceof sfFormPropel) 
    203228      { 
    204229        $form->updateObject($values[$name]); 
    205230      } 
    206     } 
    207  
    208     return $this->object; 
     231      else 
     232      { 
     233        $this->updateObjectEmbeddedForms($values[$name], $form->getEmbeddedForms()); 
     234      } 
     235    } 
    209236  } 
    210237 
     
    344371   * Saves embedded form objects. 
    345372   * 
    346    * @param PropelPDO $con An optional PropelPDO object 
    347    */ 
    348   public function saveEmbeddedForms($con = null) 
     373   * @param PropelPDO $con   An optional PropelPDO object 
     374   * @param array     $forms An array of forms 
     375   */ 
     376  public function saveEmbeddedForms($con = null, $forms = null) 
    349377  { 
    350378    if (is_null($con)) 
     
    353381    } 
    354382 
    355     foreach ($this->embeddedForms as $form) 
     383    if (is_null($forms)) 
     384    { 
     385      $forms = $this->embeddedForms; 
     386    } 
     387 
     388    foreach ($forms as $form) 
    356389    { 
    357390      if ($form instanceof sfFormPropel) 
     
    360393        $form->getObject()->save($con); 
    361394      } 
     395      else 
     396      { 
     397        $this->saveEmbeddedForms($con, $form->getEmbeddedForms()); 
     398      } 
    362399    } 
    363400  }