Skip to content

Commit bbe8c59

Browse files
committed
TextBase::addFilter() un-deprecated; is processed during validation (BC break)
1 parent 8423c9d commit bbe8c59

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/Forms/Controls/TextBase.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ abstract class TextBase extends BaseControl
2424
/** @var string */
2525
protected $emptyValue = '';
2626

27-
/** @var array */
28-
protected $filters = array();
29-
3027
/** @var mixed unfiltered submitted value */
3128
protected $rawValue = '';
3229

@@ -54,11 +51,7 @@ public function setValue($value)
5451
*/
5552
public function getValue()
5653
{
57-
$value = $this->value;
58-
foreach ($this->filters as $filter) {
59-
$value = (string) call_user_func($filter, $value);
60-
}
61-
return $value === Strings::trim($this->translate($this->emptyValue)) ? '' : $value;
54+
return $this->value === Strings::trim($this->translate($this->emptyValue)) ? '' : $this->value;
6255
}
6356

6457

@@ -100,13 +93,14 @@ public function setMaxLength($length)
10093
* Appends input string filter callback.
10194
* @param callable
10295
* @return self
103-
* @deprecated
10496
*/
10597
public function addFilter($filter)
10698
{
107-
trigger_error(__METHOD__ . '() is deprecated; use validation rules instead.', E_USER_DEPRECATED);
108-
$this->filters[] = Nette\Utils\Callback::check($filter);
109-
return $this;
99+
Nette\Utils\Callback::check($filter);
100+
return parent::addRule(function($control) use ($filter) {
101+
$control->setValue( call_user_func($filter, $control->getValue()) );
102+
return TRUE;
103+
});
110104
}
111105

112106

tests/Forms/Controls.TextBase.loadData.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,16 @@ test(function() { // object
160160

161161
Assert::same( $date, $input->getValue() );
162162
});
163+
164+
165+
test(function() { // filter
166+
$_POST = array('text' => 'hello');
167+
168+
$form = new Form;
169+
$input = $form->addText('text')
170+
->addFilter('strrev');
171+
172+
Assert::same( 'hello', $input->getValue() );
173+
$input->validate();
174+
Assert::same( 'olleh', $input->getValue() );
175+
});

0 commit comments

Comments
 (0)