Author: francois
Date: 2010-05-14 22:11:28 +0200 (Fri, 14 May 2010)
New Revision: 29477

Modified:
   plugins/sfPropel15Plugin/trunk/lib/form/sfFormPropel.class.php
Log:
[sfPropel15Plugin] Fixed addition of related objects in related collection form 
on a new object

Modified: plugins/sfPropel15Plugin/trunk/lib/form/sfFormPropel.class.php
===================================================================
--- plugins/sfPropel15Plugin/trunk/lib/form/sfFormPropel.class.php      
2010-05-14 18:19:07 UTC (rev 29476)
+++ plugins/sfPropel15Plugin/trunk/lib/form/sfFormPropel.class.php      
2010-05-14 20:11:28 UTC (rev 29477)
@@ -20,11 +20,6 @@
  */
 abstract class sfFormPropel extends sfFormObject
 {
-  /**
-   * List of fields that cannot be changed by the user, but still take a 
default value
-   * @var array
-   */
-  protected $fixedValues = array();
   
   /**
    * List of forms that can be added by the user
@@ -228,7 +223,6 @@
         return;
       }
     }
-    $values = array_merge($values, $this->getFixedValues());
     $this->getObject()->fromArray($values, BasePeer::TYPE_FIELDNAME);
   }
 
@@ -655,18 +649,30 @@
     }
     
     $relatedClass = $relationMap->getRightTable()->getClassname();
+    $relatedObject = new $relatedClass();
+    
+    // the relatedObject must be related to this form's object
+    // but without actually adding the relatedObject to the collection
+    // that's what the next lines do
+    $realRelatedObjects = call_user_func(array($this->getObject(), 
sprintf('get%ss', $relationName)))->getArrayCopy();
+    call_user_func(array($this->getObject(), sprintf('add%s', $relationName)), 
$relatedObject);
+    call_user_func(array($this->getObject(), sprintf('init%ss', 
$relationName)));
+    foreach ($realRelatedObjects as $realRelatedObject)
+    {
+      call_user_func(array($this->getObject(), sprintf('add%s', 
$relationName)), $realRelatedObject);
+    }
+    
     if (!$formClass = $options['embedded_form_class'])
     {
       $formClass = $relatedClass . 'Form';
     }
-    $emptyForm = new $formClass(new $relatedClass());
+    $emptyForm = new $formClass($relatedObject);
     if ($label = $options['empty_label']) {
       $emptyForm->getWidgetSchema()->setLabel($label);
     }
     foreach ($this->getRelationFields($relationMap) as $leftCol => $field)
     {
       unset($emptyForm[$field]);
-      $emptyForm->setFixedValue($field, 
$this->getObject()->getByName($leftCol, BasePeer::TYPE_COLNAME));
     }
     
     return $emptyForm;
@@ -689,21 +695,6 @@
     return $relationFields;
   }
   
-  public function setFixedValues($values)
-  {
-    $this->fixedValues = $values;
-  }
-
-  public function setFixedValue($name, $value)
-  {
-    $this->fixedValues[$name] = $value;
-  }
-
-  public function getFixedValues()
-  {
-    return $this->fixedValues;
-  }
-  
   public function setDeleteField($fieldName)
   {
     $this->deleteField = $fieldName;

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to