Skip to content

Commit 632c05a

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

40 files changed

Lines changed: 147 additions & 129 deletions

β€Ž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
@@ -45,7 +45,7 @@ public function setDefaults(iterable $values, bool $erase = FALSE)
4545
{
4646
$form = $this->getForm(FALSE);
4747
if (!$form || !$form->isAnchored() || !$form->isSubmitted()) {
48-
$this->setValues($values, $erase);
48+
$this->setCurrentValues($values, $erase);
4949
}
5050
return $this;
5151
}
@@ -56,7 +56,7 @@ public function setDefaults(iterable $values, bool $erase = FALSE)
5656
* @return static
5757
* @internal
5858
*/
59-
public function setValues(iterable $values, bool $erase = FALSE)
59+
public function setCurrentValues(iterable $values, bool $erase = FALSE)
6060
{
6161
if ($values instanceof \Traversable) {
6262
$values = iterator_to_array($values);
@@ -68,25 +68,35 @@ public function setValues(iterable $values, bool $erase = FALSE)
6868
foreach ($this->getComponents() as $name => $control) {
6969
if ($control instanceof IControl) {
7070
if (array_key_exists($name, $values)) {
71-
$control->setValue($values[$name]);
71+
$control->setCurrentValue($values[$name]);
7272

7373
} elseif ($erase) {
74-
$control->setValue(NULL);
74+
$control->setCurrentValue(NULL);
7575
}
7676

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

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

8989

90+
/**
91+
* @deprecated
92+
*/
93+
public function setValues($values, $erase = FALSE)
94+
{
95+
trigger_error(__METHOD__ . '() is deprecated; use setCurrentValues() instead.', E_USER_DEPRECATED);
96+
return $this->setCurrentValues($values, $erase);
97+
}
98+
99+
90100
/**
91101
* Returns the values submitted by the form.
92102
* @return Nette\Utils\ArrayHash|array

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

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

9797

@@ -120,7 +120,7 @@ public function getForm(bool $throw = TRUE): ?Form
120120
*/
121121
public function loadHttpData(): void
122122
{
123-
$this->setValue($this->getHttpData(Form::DATA_TEXT));
123+
$this->setCurrentValue($this->getHttpData(Form::DATA_TEXT));
124124
}
125125

126126

@@ -151,10 +151,18 @@ public function getHtmlName(): string
151151
* @return static
152152
* @internal
153153
*/
154+
public function setCurrentValue($value)
155+
{
156+
return $this->setValue($value);
157+
}
158+
159+
160+
/**
161+
* @deprecated
162+
*/
154163
public function setValue($value)
155164
{
156165
$this->value = $value;
157-
return $this;
158166
}
159167

160168

@@ -186,7 +194,7 @@ public function setDefaultValue($value)
186194
{
187195
$form = $this->getForm(FALSE);
188196
if ($this->isDisabled() || !$form || !$form->isAnchored() || !$form->isSubmitted()) {
189-
$this->setValue($value);
197+
$this->setCurrentValue($value);
190198
}
191199
return $this;
192200
}
@@ -199,7 +207,7 @@ public function setDefaultValue($value)
199207
public function setDisabled($value = TRUE)
200208
{
201209
if ($this->disabled = (bool) $value) {
202-
$this->setValue(NULL);
210+
$this->setCurrentValue(NULL);
203211
} elseif (($form = $this->getForm(FALSE)) && $form->isAnchored() && $form->isSubmitted()) {
204212
$this->loadHttpData();
205213
}

β€Ž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
@@ -58,7 +58,7 @@ public function loadHttpData(): void
5858
* @return static
5959
* @internal
6060
*/
61-
public function setValue($value)
61+
public function setCurrentValue($value)
6262
{
6363
if ($this->checkAllowedValues && $value !== NULL && !array_key_exists((string) $value, $this->items)) {
6464
$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
@@ -49,7 +49,7 @@ protected function attached(Nette\ComponentModel\IComponent $parent): void
4949
* @return static
5050
* @internal
5151
*/
52-
public function setValue($value)
52+
public function setCurrentValue($value)
5353
{
5454
return $this;
5555
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct($persistentValue = 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 && !method_exists($value, '__toString')) {
4545
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
@@ -53,7 +53,7 @@ public function loadHttpData(): void
5353
* @return static
5454
* @internal
5555
*/
56-
public function setValue($values)
56+
public function setCurrentValue($values)
5757
{
5858
if (is_scalar($values) || $values === NULL) {
5959
$values = (array) $values;

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct($label = NULL, int $maxLength = NULL)
3535
*/
3636
public function loadHttpData(): void
3737
{
38-
$this->setValue($this->getHttpData(Form::DATA_LINE));
38+
$this->setCurrentValue($this->getHttpData(Form::DATA_LINE));
3939
}
4040

4141

0 commit comments

Comments
Β (0)