Skip to content

Commit ee056e0

Browse files
committed
IControl::setValue() β‡’ setCurrentValues() and Container::setValues() β‡’ setCurrentValues() [Closes #114]
1 parent 3517086 commit ee056e0

40 files changed

+147
-129
lines changed

β€Žexamples/custom-control.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct($label = NULL)
3333
}
3434

3535

36-
public function setValue($value)
36+
public function setCurrentValue($value)
3737
{
3838
if ($value === NULL) {
3939
$this->day = $this->month = $this->year = '';

β€Žsrc/Forms/Container.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function setDefaults($values, $erase = FALSE)
4444
{
4545
$form = $this->getForm(FALSE);
4646
if (!$form || !$form->isAnchored() || !$form->isSubmitted()) {
47-
$this->setValues($values, $erase);
47+
$this->setCurrentValues($values, $erase);
4848
}
4949
return $this;
5050
}
@@ -57,7 +57,7 @@ public function setDefaults($values, $erase = FALSE)
5757
* @return static
5858
* @internal
5959
*/
60-
public function setValues($values, $erase = FALSE)
60+
public function setCurrentValues($values, $erase = FALSE)
6161
{
6262
if ($values instanceof \Traversable) {
6363
$values = iterator_to_array($values);
@@ -69,25 +69,35 @@ public function setValues($values, $erase = FALSE)
6969
foreach ($this->getComponents() as $name => $control) {
7070
if ($control instanceof IControl) {
7171
if (array_key_exists($name, $values)) {
72-
$control->setValue($values[$name]);
72+
$control->setCurrentValue($values[$name]);
7373

7474
} elseif ($erase) {
75-
$control->setValue(NULL);
75+
$control->setCurrentValue(NULL);
7676
}
7777

7878
} elseif ($control instanceof self) {
7979
if (array_key_exists($name, $values)) {
80-
$control->setValues($values[$name], $erase);
80+
$control->setCurrentValues($values[$name], $erase);
8181

8282
} elseif ($erase) {
83-
$control->setValues([], $erase);
83+
$control->setCurrentValues([], $erase);
8484
}
8585
}
8686
}
8787
return $this;
8888
}
8989

9090

91+
/**
92+
* @deprecated
93+
*/
94+
public function setValues($values, $erase = FALSE)
95+
{
96+
trigger_error(__METHOD__ . '() is deprecated; use setCurrentValues() instead.', E_USER_DEPRECATED);
97+
return $this->setCurrentValues($values, $erase);
98+
}
99+
100+
91101
/**
92102
* Returns the values submitted by the form.
93103
* @param bool return values as an array?

β€Žsrc/Forms/Controls/BaseControl.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function __construct($caption = NULL)
8888
if (self::$autoOptional) {
8989
$this->setRequired(FALSE);
9090
}
91-
$this->setValue(NULL);
91+
$this->setCurrentValue(NULL);
9292
}
9393

9494

@@ -122,7 +122,7 @@ public function getForm($need = TRUE)
122122
*/
123123
public function loadHttpData()
124124
{
125-
$this->setValue($this->getHttpData(Form::DATA_TEXT));
125+
$this->setCurrentValue($this->getHttpData(Form::DATA_TEXT));
126126
}
127127

128128

@@ -154,10 +154,18 @@ public function getHtmlName()
154154
* @return static
155155
* @internal
156156
*/
157+
public function setCurrentValue($value)
158+
{
159+
return $this->setValue($value);
160+
}
161+
162+
163+
/**
164+
* @deprecated
165+
*/
157166
public function setValue($value)
158167
{
159168
$this->value = $value;
160-
return $this;
161169
}
162170

163171

@@ -190,7 +198,7 @@ public function setDefaultValue($value)
190198
{
191199
$form = $this->getForm(FALSE);
192200
if ($this->isDisabled() || !$form || !$form->isAnchored() || !$form->isSubmitted()) {
193-
$this->setValue($value);
201+
$this->setCurrentValue($value);
194202
}
195203
return $this;
196204
}
@@ -204,7 +212,7 @@ public function setDefaultValue($value)
204212
public function setDisabled($value = TRUE)
205213
{
206214
if ($this->disabled = (bool) $value) {
207-
$this->setValue(NULL);
215+
$this->setCurrentValue(NULL);
208216
} elseif (($form = $this->getForm(FALSE)) && $form->isAnchored() && $form->isSubmitted()) {
209217
$this->loadHttpData();
210218
}

β€Žsrc/Forms/Controls/Checkbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct($label = NULL)
3939
* @return static
4040
* @internal
4141
*/
42-
public function setValue($value)
42+
public function setCurrentValue($value)
4343
{
4444
if (!is_scalar($value) && $value !== NULL) {
4545
throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or NULL, %s given in field '%s'.", gettype($value), $this->name));

β€Žsrc/Forms/Controls/ChoiceControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function loadHttpData()
5959
* @return static
6060
* @internal
6161
*/
62-
public function setValue($value)
62+
public function setCurrentValue($value)
6363
{
6464
if ($this->checkAllowedValues && $value !== NULL && !array_key_exists((string) $value, $this->items)) {
6565
$set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');

β€Žsrc/Forms/Controls/CsrfProtection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function attached($parent)
5050
* @return static
5151
* @internal
5252
*/
53-
public function setValue($value)
53+
public function setCurrentValue($value)
5454
{
5555
return $this;
5656
}

β€Žsrc/Forms/Controls/HiddenField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct($persistentValue = NULL)
4040
* @return static
4141
* @internal
4242
*/
43-
public function setValue($value)
43+
public function setCurrentValue($value)
4444
{
4545
if (!is_scalar($value) && $value !== NULL && !method_exists($value, '__toString')) {
4646
throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or NULL, %s given in field '%s'.", gettype($value), $this->name));

β€Žsrc/Forms/Controls/MultiChoiceControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function loadHttpData()
5555
* @return static
5656
* @internal
5757
*/
58-
public function setValue($values)
58+
public function setCurrentValue($values)
5959
{
6060
if (is_scalar($values) || $values === NULL) {
6161
$values = (array) $values;

β€Žsrc/Forms/Controls/TextBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract class TextBase extends BaseControl
3535
* @return static
3636
* @internal
3737
*/
38-
public function setValue($value)
38+
public function setCurrentValue($value)
3939
{
4040
if ($value === NULL) {
4141
$value = '';

β€Žsrc/Forms/Controls/TextInput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct($label = NULL, $maxLength = NULL)
3737
*/
3838
public function loadHttpData()
3939
{
40-
$this->setValue($this->getHttpData(Form::DATA_LINE));
40+
$this->setCurrentValue($this->getHttpData(Form::DATA_LINE));
4141
}
4242

4343

0 commit comments

Comments
Β (0)