Development

Changeset 27749

You must first sign up to be able to contribute.

Changeset 27749

Show
Ignore:
Timestamp:
02/08/10 19:48:39 (1 month ago)
Author:
Kris.Wallsmith
Message:

[1.3, 1.4] updated doctrine and propel forms to allow setting of defaults on numeric fields from within configure (closes #8238)

Files:

Legend:

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

    r24971 r27749  
    228228  protected function updateDefaultsFromObject() 
    229229  { 
     230    $defaults = $this->getDefaults(); 
     231 
    230232    // update defaults for the main object 
    231233    if ($this->isNew()) 
    232234    { 
    233       $this->setDefaults(array_merge($this->getObject()->toArray(false), $this->getDefaults())); 
    234     } 
    235     else 
    236     { 
    237       $this->setDefaults(array_merge($this->getDefaults(), $this->getObject()->toArray(false))); 
    238     } 
    239  
    240     $defaults = $this->getDefaults(); 
     235      $defaults = $this->getObject()->toArray(false) + $defaults; 
     236    } 
     237    else 
     238    { 
     239      $defaults = $this->getDefaults() + $this->getObject()->toArray(false); 
     240    } 
     241 
    241242    foreach ($this->embeddedForms as $name => $form) 
    242243    { 
     
    247248      } 
    248249    } 
     250 
    249251    $this->setDefaults($defaults); 
    250252  } 
  • branches/1.3/lib/plugins/sfDoctrinePlugin/test/unit/form/sfFormDoctrineTest.php

    r24537 r27749  
    44include dirname(__FILE__).'/../../bootstrap/functional.php'; 
    55 
    6 $t = new lime_test(10); 
     6$t = new lime_test(11); 
     7 
     8// ->__construct() 
     9$t->diag('->__construct()'); 
     10 
     11class DefaultValuesForm extends ArticleForm 
     12
     13  public function configure() 
     14  { 
     15    $this->widgetSchema[1] = new sfWidgetFormInputText(); 
     16    $this->validatorSchema[1] = new sfValidatorPass(); 
     17    $this->setDefault(1, '==DEFAULT_VALUE=='); 
     18  } 
     19
     20 
     21$form = new DefaultValuesForm(); 
     22$defaults = $form->getDefaults(); 
     23$t->is($defaults[1], '==DEFAULT_VALUE==', '->__construct() allows ->configure() to set defaults on numeric fields'); 
    724 
    825// ->embedRelation() 
  • branches/1.3/lib/plugins/sfPropelPlugin/lib/form/sfFormPropel.class.php

    r24068 r27749  
    192192    if ($this->isNew()) 
    193193    { 
    194       $this->setDefaults(array_merge($this->getObject()->toArray(BasePeer::TYPE_FIELDNAME), $this->getDefaults())); 
     194      $this->setDefaults($this->getObject()->toArray(BasePeer::TYPE_FIELDNAME) + $this->getDefaults()); 
    195195    } 
    196196    else 
    197197    { 
    198       $this->setDefaults(array_merge($this->getDefaults(), $this->getObject()->toArray(BasePeer::TYPE_FIELDNAME))); 
     198      $this->setDefaults($this->getDefaults() + $this->getObject()->toArray(BasePeer::TYPE_FIELDNAME)); 
    199199    } 
    200200  } 
  • branches/1.4/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php

    r24971 r27749  
    228228  protected function updateDefaultsFromObject() 
    229229  { 
     230    $defaults = $this->getDefaults(); 
     231 
    230232    // update defaults for the main object 
    231233    if ($this->isNew()) 
    232234    { 
    233       $this->setDefaults(array_merge($this->getObject()->toArray(false), $this->getDefaults())); 
    234     } 
    235     else 
    236     { 
    237       $this->setDefaults(array_merge($this->getDefaults(), $this->getObject()->toArray(false))); 
    238     } 
    239  
    240     $defaults = $this->getDefaults(); 
     235      $defaults = $this->getObject()->toArray(false) + $defaults; 
     236    } 
     237    else 
     238    { 
     239      $defaults = $this->getDefaults() + $this->getObject()->toArray(false); 
     240    } 
     241 
    241242    foreach ($this->embeddedForms as $name => $form) 
    242243    { 
     
    247248      } 
    248249    } 
     250 
    249251    $this->setDefaults($defaults); 
    250252  } 
  • branches/1.4/lib/plugins/sfDoctrinePlugin/test/unit/form/sfFormDoctrineTest.php

    r24537 r27749  
    44include dirname(__FILE__).'/../../bootstrap/functional.php'; 
    55 
    6 $t = new lime_test(10); 
     6$t = new lime_test(11); 
     7 
     8// ->__construct() 
     9$t->diag('->__construct()'); 
     10 
     11class DefaultValuesForm extends ArticleForm 
     12
     13  public function configure() 
     14  { 
     15    $this->widgetSchema[1] = new sfWidgetFormInputText(); 
     16    $this->validatorSchema[1] = new sfValidatorPass(); 
     17    $this->setDefault(1, '==DEFAULT_VALUE=='); 
     18  } 
     19
     20 
     21$form = new DefaultValuesForm(); 
     22$defaults = $form->getDefaults(); 
     23$t->is($defaults[1], '==DEFAULT_VALUE==', '->__construct() allows ->configure() to set defaults on numeric fields'); 
    724 
    825// ->embedRelation() 
  • branches/1.4/lib/plugins/sfPropelPlugin/lib/form/sfFormPropel.class.php

    r24068 r27749  
    192192    if ($this->isNew()) 
    193193    { 
    194       $this->setDefaults(array_merge($this->getObject()->toArray(BasePeer::TYPE_FIELDNAME), $this->getDefaults())); 
     194      $this->setDefaults($this->getObject()->toArray(BasePeer::TYPE_FIELDNAME) + $this->getDefaults()); 
    195195    } 
    196196    else 
    197197    { 
    198       $this->setDefaults(array_merge($this->getDefaults(), $this->getObject()->toArray(BasePeer::TYPE_FIELDNAME))); 
     198      $this->setDefaults($this->getDefaults() + $this->getObject()->toArray(BasePeer::TYPE_FIELDNAME)); 
    199199    } 
    200200  } 

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.