Skip to content

Commit ff0d772

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

40 files changed

+158
-139
lines changed

β€Žexamples/custom-control.phpβ€Ž

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

3636

37-
public function setValue($value)
37+
public function setCurrentValue($value)
3838
{
3939
if ($value === null) {
4040
$this->day = $this->month = $this->year = '';

β€Žsrc/Forms/Container.phpβ€Ž

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
*
1818
* @property Nette\Utils\ArrayHash $values
1919
* @property-read \Iterator $controls
20-
* @property-read Form|null $form
20+
* @property-read Form|NULL $form
2121
*/
2222
class Container extends Nette\ComponentModel\Container implements \ArrayAccess
2323
{
24+
2425
/** @var callable[] function (Container $sender); Occurs when the form is validated */
2526
public $onValidate;
2627

27-
/** @var ControlGroup|null */
28+
/** @var ControlGroup|NULL */
2829
protected $currentGroup;
29-
3030
/** @var callable[] extension methods */
3131
private static $extMethods = [];
3232

@@ -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: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements ICo
6262
/** @var array */
6363
private $errors = [];
6464

65-
/** @var bool|null */
65+
/** @var bool|NULL */
6666
private $omitted;
6767

6868
/** @var Rules */
@@ -92,7 +92,7 @@ public function __construct($caption = null)
9292
if (self::$autoOptional) {
9393
$this->setRequired(false);
9494
}
95-
$this->setValue(null);
95+
$this->setCurrentValue(null);
9696
}
9797

9898

@@ -142,7 +142,7 @@ public function getForm(bool $throw = true): ?Form
142142
*/
143143
public function loadHttpData(): void
144144
{
145-
$this->setValue($this->getHttpData(Form::DATA_TEXT));
145+
$this->setCurrentValue($this->getHttpData(Form::DATA_TEXT));
146146
}
147147

148148

@@ -173,10 +173,18 @@ public function getHtmlName(): string
173173
* @return static
174174
* @internal
175175
*/
176+
public function setCurrentValue($value)
177+
{
178+
return $this->setValue($value);
179+
}
180+
181+
182+
/**
183+
* @deprecated
184+
*/
176185
public function setValue($value)
177186
{
178187
$this->value = $value;
179-
return $this;
180188
}
181189

182190

@@ -208,7 +216,7 @@ public function setDefaultValue($value)
208216
{
209217
$form = $this->getForm(false);
210218
if ($this->isDisabled() || !$form || !$form->isAnchored() || !$form->isSubmitted()) {
211-
$this->setValue($value);
219+
$this->setCurrentValue($value);
212220
}
213221
return $this;
214222
}
@@ -221,7 +229,7 @@ public function setDefaultValue($value)
221229
public function setDisabled($value = true)
222230
{
223231
if ($this->disabled = (bool) $value) {
224-
$this->setValue(null);
232+
$this->setCurrentValue(null);
225233
} elseif (($form = $this->getForm(false)) && $form->isAnchored() && $form->isSubmitted()) {
226234
$this->loadHttpData();
227235
}
@@ -327,7 +335,7 @@ public function getLabelPrototype(): Html
327335

328336
/**
329337
* Changes control's HTML id.
330-
* @param mixed new ID, or false or null
338+
* @param mixed new ID, or FALSE or NULL
331339
* @return static
332340
*/
333341
public function setHtmlId($id)

β€Ž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
@@ -61,7 +61,7 @@ public function loadHttpData(): void
6161
* @return static
6262
* @internal
6363
*/
64-
public function setValue($value)
64+
public function setCurrentValue($value)
6565
{
6666
if ($this->checkAllowedValues && $value !== null && !array_key_exists((string) $value, $this->items)) {
6767
$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
@@ -56,7 +56,7 @@ public function loadHttpData(): void
5656
* @return static
5757
* @internal
5858
*/
59-
public function setValue($values)
59+
public function setCurrentValue($values)
6060
{
6161
if (is_scalar($values) || $values === null) {
6262
$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)