Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2679c87

Browse files
committed
changes execution order
1 parent 5963f57 commit 2679c87

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

lib/form/mmReadOnlyBaseForm.class.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function __construct($defaults = array(), $options = array(), $CSRFSecret
3737

3838
$this->addCSRFProtection($this->localCSRFSecret);
3939
$this->resetFormFields();
40+
41+
$this->_handleReadOnlyFields();
4042
}
4143

4244
/**
@@ -66,22 +68,25 @@ private function _handleNotVisibleField($fieldName)
6668
* Mark the widgets as readonly &&
6769
* creates a validator if appropriate
6870
*/
69-
private function _handleReadOnlyField($fieldName)
71+
private function _handleReadOnlyFields()
7072
{
71-
if($this->getWidgetSchema()->offsetExists($fieldName))
73+
foreach($this->_readOnlyFields as $fieldName)
7274
{
73-
$this->_setWidgetReadOnly($fieldName);
74-
if($this instanceof sfFormDoctrine && !$this->getObject()->isNew())
75-
{
76-
$value = $this->getObject()->$fieldName;
77-
}
78-
else
75+
if($this->getWidgetSchema()->offsetExists($fieldName))
7976
{
80-
$value = $this->getValue($fieldName);
77+
$this->_setWidgetReadOnly($fieldName);
78+
if($this instanceof sfFormDoctrine)
79+
{
80+
$value = $this->widgetSchema[$fieldName]->getDefault() ? $this->widgetSchema[$fieldName]->getDefault() : $this->getObject()->$fieldName;
81+
}
82+
else
83+
{
84+
$value = $this->widgetSchema[$fieldName]->getDefault();
85+
}
86+
$this->validatorSchema[$fieldName] = new mmValidatorReadOnly(array(
87+
'value' => $value,
88+
));
8189
}
82-
$this->validatorSchema[$fieldName] = new mmValidatorReadOnly(array(
83-
'widget' => $this->validatorSchema[$fieldName]
84-
));
8590
}
8691
}
8792

@@ -126,7 +131,7 @@ public function addReadOnlyField($fieldName)
126131
{
127132
throw new InvalidArgumentException(__FUNCTION__ . ': Invalid Argument type. Expected String, got ' . gettype($fieldName));
128133
}
129-
$this->_handleReadOnlyField($fieldName);
134+
$this->_readOnlyFields[] = $fieldName;
130135
}
131136

132137
/**
@@ -139,7 +144,7 @@ public function addReadOnlyFields(array $fields)
139144
{
140145
foreach($fields as $fieldName)
141146
{
142-
$this->_handleReadOnlyField($fieldName);
147+
$this->_readOnlyFields[] = $fieldName;
143148
}
144149
}
145150

@@ -201,7 +206,7 @@ public function setReadOnly(array $fields = array())
201206
{
202207
foreach($this->widgetSchema->getFields() as $fieldName => $w)
203208
{
204-
$this->_handleReadOnlyField($fieldName);
209+
$this->_readOnlyFields[] = $fieldName;
205210
}
206211
}
207212

lib/validator/mmValidatorReadOnly.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class mmValidatorReadOnly extends sfValidatorBase
1818
*/
1919
protected function configure($options = array(), $messages = array())
2020
{
21-
$this->addRequiredOption('widget');
21+
$this->addRequiredOption('value');
2222
$this->setOption('required', false);
2323
}
2424

@@ -27,6 +27,6 @@ protected function configure($options = array(), $messages = array())
2727
*/
2828
protected function doClean($value)
2929
{
30-
return $this->getOption('widget')->getDefault();
30+
return $this->getOption('value');
3131
}
3232
}

0 commit comments

Comments
 (0)