Author: Kris.Wallsmith
Date: 2010-02-08 19:48:39 +0100 (Mon, 08 Feb 2010)
New Revision: 27749
Modified:
branches/1.3/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
branches/1.3/lib/plugins/sfDoctrinePlugin/test/unit/form/sfFormDoctrineTest.php
branches/1.3/lib/plugins/sfPropelPlugin/lib/form/sfFormPropel.class.php
branches/1.4/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
branches/1.4/lib/plugins/sfDoctrinePlugin/test/unit/form/sfFormDoctrineTest.php
branches/1.4/lib/plugins/sfPropelPlugin/lib/form/sfFormPropel.class.php
Log:
[1.3, 1.4] updated doctrine and propel forms to allow setting of defaults on
numeric fields from within configure (closes #8238)
Modified:
branches/1.3/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
===================================================================
--- branches/1.3/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
2010-02-08 18:18:44 UTC (rev 27748)
+++ branches/1.3/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
2010-02-08 18:48:39 UTC (rev 27749)
@@ -227,17 +227,18 @@
*/
protected function updateDefaultsFromObject()
{
+ $defaults = $this->getDefaults();
+
// update defaults for the main object
if ($this->isNew())
{
- $this->setDefaults(array_merge($this->getObject()->toArray(false),
$this->getDefaults()));
+ $defaults = $this->getObject()->toArray(false) + $defaults;
}
else
{
- $this->setDefaults(array_merge($this->getDefaults(),
$this->getObject()->toArray(false)));
+ $defaults = $this->getDefaults() + $this->getObject()->toArray(false);
}
- $defaults = $this->getDefaults();
foreach ($this->embeddedForms as $name => $form)
{
if ($form instanceof sfFormDoctrine)
@@ -246,6 +247,7 @@
$defaults[$name] = $form->getDefaults();
}
}
+
$this->setDefaults($defaults);
}
Modified:
branches/1.3/lib/plugins/sfDoctrinePlugin/test/unit/form/sfFormDoctrineTest.php
===================================================================
---
branches/1.3/lib/plugins/sfDoctrinePlugin/test/unit/form/sfFormDoctrineTest.php
2010-02-08 18:18:44 UTC (rev 27748)
+++
branches/1.3/lib/plugins/sfDoctrinePlugin/test/unit/form/sfFormDoctrineTest.php
2010-02-08 18:48:39 UTC (rev 27749)
@@ -3,8 +3,25 @@
$app = 'frontend';
include dirname(__FILE__).'/../../bootstrap/functional.php';
-$t = new lime_test(10);
+$t = new lime_test(11);
+// ->__construct()
+$t->diag('->__construct()');
+
+class DefaultValuesForm extends ArticleForm
+{
+ public function configure()
+ {
+ $this->widgetSchema[1] = new sfWidgetFormInputText();
+ $this->validatorSchema[1] = new sfValidatorPass();
+ $this->setDefault(1, '==DEFAULT_VALUE==');
+ }
+}
+
+$form = new DefaultValuesForm();
+$defaults = $form->getDefaults();
+$t->is($defaults[1], '==DEFAULT_VALUE==', '->__construct() allows
->configure() to set defaults on numeric fields');
+
// ->embedRelation()
$t->diag('->embedRelation()');
Modified:
branches/1.3/lib/plugins/sfPropelPlugin/lib/form/sfFormPropel.class.php
===================================================================
--- branches/1.3/lib/plugins/sfPropelPlugin/lib/form/sfFormPropel.class.php
2010-02-08 18:18:44 UTC (rev 27748)
+++ branches/1.3/lib/plugins/sfPropelPlugin/lib/form/sfFormPropel.class.php
2010-02-08 18:48:39 UTC (rev 27749)
@@ -191,11 +191,11 @@
// update defaults for the main object
if ($this->isNew())
{
-
$this->setDefaults(array_merge($this->getObject()->toArray(BasePeer::TYPE_FIELDNAME),
$this->getDefaults()));
+ $this->setDefaults($this->getObject()->toArray(BasePeer::TYPE_FIELDNAME)
+ $this->getDefaults());
}
else
{
- $this->setDefaults(array_merge($this->getDefaults(),
$this->getObject()->toArray(BasePeer::TYPE_FIELDNAME)));
+ $this->setDefaults($this->getDefaults() +
$this->getObject()->toArray(BasePeer::TYPE_FIELDNAME));
}
}
Modified:
branches/1.4/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
===================================================================
--- branches/1.4/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
2010-02-08 18:18:44 UTC (rev 27748)
+++ branches/1.4/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
2010-02-08 18:48:39 UTC (rev 27749)
@@ -227,17 +227,18 @@
*/
protected function updateDefaultsFromObject()
{
+ $defaults = $this->getDefaults();
+
// update defaults for the main object
if ($this->isNew())
{
- $this->setDefaults(array_merge($this->getObject()->toArray(false),
$this->getDefaults()));
+ $defaults = $this->getObject()->toArray(false) + $defaults;
}
else
{
- $this->setDefaults(array_merge($this->getDefaults(),
$this->getObject()->toArray(false)));
+ $defaults = $this->getDefaults() + $this->getObject()->toArray(false);
}
- $defaults = $this->getDefaults();
foreach ($this->embeddedForms as $name => $form)
{
if ($form instanceof sfFormDoctrine)
@@ -246,6 +247,7 @@
$defaults[$name] = $form->getDefaults();
}
}
+
$this->setDefaults($defaults);
}
Modified:
branches/1.4/lib/plugins/sfDoctrinePlugin/test/unit/form/sfFormDoctrineTest.php
===================================================================
---
branches/1.4/lib/plugins/sfDoctrinePlugin/test/unit/form/sfFormDoctrineTest.php
2010-02-08 18:18:44 UTC (rev 27748)
+++
branches/1.4/lib/plugins/sfDoctrinePlugin/test/unit/form/sfFormDoctrineTest.php
2010-02-08 18:48:39 UTC (rev 27749)
@@ -3,8 +3,25 @@
$app = 'frontend';
include dirname(__FILE__).'/../../bootstrap/functional.php';
-$t = new lime_test(10);
+$t = new lime_test(11);
+// ->__construct()
+$t->diag('->__construct()');
+
+class DefaultValuesForm extends ArticleForm
+{
+ public function configure()
+ {
+ $this->widgetSchema[1] = new sfWidgetFormInputText();
+ $this->validatorSchema[1] = new sfValidatorPass();
+ $this->setDefault(1, '==DEFAULT_VALUE==');
+ }
+}
+
+$form = new DefaultValuesForm();
+$defaults = $form->getDefaults();
+$t->is($defaults[1], '==DEFAULT_VALUE==', '->__construct() allows
->configure() to set defaults on numeric fields');
+
// ->embedRelation()
$t->diag('->embedRelation()');
Modified:
branches/1.4/lib/plugins/sfPropelPlugin/lib/form/sfFormPropel.class.php
===================================================================
--- branches/1.4/lib/plugins/sfPropelPlugin/lib/form/sfFormPropel.class.php
2010-02-08 18:18:44 UTC (rev 27748)
+++ branches/1.4/lib/plugins/sfPropelPlugin/lib/form/sfFormPropel.class.php
2010-02-08 18:48:39 UTC (rev 27749)
@@ -191,11 +191,11 @@
// update defaults for the main object
if ($this->isNew())
{
-
$this->setDefaults(array_merge($this->getObject()->toArray(BasePeer::TYPE_FIELDNAME),
$this->getDefaults()));
+ $this->setDefaults($this->getObject()->toArray(BasePeer::TYPE_FIELDNAME)
+ $this->getDefaults());
}
else
{
- $this->setDefaults(array_merge($this->getDefaults(),
$this->getObject()->toArray(BasePeer::TYPE_FIELDNAME)));
+ $this->setDefaults($this->getDefaults() +
$this->getObject()->toArray(BasePeer::TYPE_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.