diff --git a/docs/guide/input-validation.md b/docs/guide/input-validation.md index 7cdbdd9927..2c209d1796 100644 --- a/docs/guide/input-validation.md +++ b/docs/guide/input-validation.md @@ -895,13 +895,13 @@ the former will take precedence. > - if you want to implement your own custom client-side validation but leave the synchronization with server-side > validator options; > - to extend or customize to fit your specific needs: -> +> > ```php -> protected function getClientOptions($model, $attribute) +> public function getClientOptions($model, $attribute) > { > $options = parent::getClientOptions($model, $attribute); > // Modify $options here -> +> > return $options; > } > ``` diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index b9e7d97b45..1fcf8dc7ef 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -37,7 +37,7 @@ Yii Framework 2 Change Log - Enh #9162: Added support of closures in `value` for attributes in `yii\widgets\DetailView` (arogachev) - Enh #10896: Select only primary key when counting records in UniqueValidator (developeruz) - Enh #11037: `yii.js` and `yii.validation.js` use `Regexp.test()` instead of `String.match()` (arogachev, nkovacs) -- Enh #11163: Added separate method for client-side validation options in `yii\validators\Validator` (arogachev) +- Enh #11163: Added separate method for client-side validation options `yii\validators\Validator::getClientOptions()` (arogachev) - Enh #11756: Added type mapping for `varbinary` data type in MySQL DBMS (silverfire) - Enh #11929: Changed `type` column type from `int` to `smallInt` in RBAC migrations (silverfire) - Enh #12015: Changed visibility `yii\db\ActiveQueryTrait::createModels()` from private to protected (ArekX, dynasource) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index 7c67fd70a2..ecccdb5ed7 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -29,14 +29,14 @@ The simple way to upgrade Yii, for example to version 2.0.10 (replace this with composer require "yiisoft/yii2:~2.0.10" This however may fail due to changes in the dependencies of yiisoft/yii2, which may change due to security updates -in other libraries or by adding support for newer versions. `composer require` will not update any other packages +in other libraries or by adding support for newer versions. `composer require` will not update any other packages as a safety feature. The better way to upgrade is to change the `composer.json` file to require the new Yii version and then run `composer update` by specifying all packages that are allowed to be updated. composer update yiisoft/yii2 yiisoft/yii2-composer bower-asset/jquery.inputmask - + The above command will only update the specified packages and leave the versions of all other dependencies intact. This helps to update packages step by step without causing a lot of package version changes that might break in some way. If you feel lucky you can of course update everything to the latest version by running `composer update` without @@ -57,6 +57,9 @@ Upgrade from Yii 2.0.10 This method is implemented in the `yii\db\QueryTrait`, so this only affects your code if you implement QueryInterface in a class that does not use the trait. +* `yii\validators\FileValidator::getClientOptions()` and `yii\validators\ImageValidator::getClientOptions()` are now public. + If you extend from these classes and override these methods, you must make them public as well. + Upgrade from Yii 2.0.9 ---------------------- diff --git a/framework/captcha/CaptchaValidator.php b/framework/captcha/CaptchaValidator.php index a319740f57..357a81bc70 100644 --- a/framework/captcha/CaptchaValidator.php +++ b/framework/captcha/CaptchaValidator.php @@ -95,7 +95,7 @@ class CaptchaValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $captcha = $this->createCaptchaAction(); $code = $captcha->getVerifyCode(false); diff --git a/framework/validators/BooleanValidator.php b/framework/validators/BooleanValidator.php index 96beafe802..cff9fc9fef 100644 --- a/framework/validators/BooleanValidator.php +++ b/framework/validators/BooleanValidator.php @@ -79,7 +79,7 @@ class BooleanValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $options = [ 'trueValue' => $this->trueValue, diff --git a/framework/validators/CompareValidator.php b/framework/validators/CompareValidator.php index b243722ee1..c9284f0f72 100644 --- a/framework/validators/CompareValidator.php +++ b/framework/validators/CompareValidator.php @@ -234,7 +234,7 @@ class CompareValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $options = [ 'operator' => $this->operator, diff --git a/framework/validators/EmailValidator.php b/framework/validators/EmailValidator.php index 1989f2cd76..9262b56908 100644 --- a/framework/validators/EmailValidator.php +++ b/framework/validators/EmailValidator.php @@ -121,7 +121,7 @@ class EmailValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $options = [ 'pattern' => new JsExpression($this->pattern), diff --git a/framework/validators/FileValidator.php b/framework/validators/FileValidator.php index c0ebf847bd..64774b362a 100644 --- a/framework/validators/FileValidator.php +++ b/framework/validators/FileValidator.php @@ -386,7 +386,7 @@ class FileValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $label = $model->getAttributeLabel($attribute); diff --git a/framework/validators/FilterValidator.php b/framework/validators/FilterValidator.php index 5f214d712c..cedf241fd1 100644 --- a/framework/validators/FilterValidator.php +++ b/framework/validators/FilterValidator.php @@ -97,7 +97,7 @@ class FilterValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $options = []; if ($this->skipOnEmpty) { diff --git a/framework/validators/ImageValidator.php b/framework/validators/ImageValidator.php index 769cad9398..6d72812acf 100644 --- a/framework/validators/ImageValidator.php +++ b/framework/validators/ImageValidator.php @@ -172,7 +172,7 @@ class ImageValidator extends FileValidator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $options = parent::getClientOptions($model, $attribute); diff --git a/framework/validators/IpValidator.php b/framework/validators/IpValidator.php index 54018a1ce3..9b72adfad0 100644 --- a/framework/validators/IpValidator.php +++ b/framework/validators/IpValidator.php @@ -597,7 +597,7 @@ class IpValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $messages = [ 'ipv6NotAllowed' => $this->ipv6NotAllowed, diff --git a/framework/validators/NumberValidator.php b/framework/validators/NumberValidator.php index edf9dfc0ff..cf5b7c0cb8 100644 --- a/framework/validators/NumberValidator.php +++ b/framework/validators/NumberValidator.php @@ -130,7 +130,7 @@ class NumberValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $label = $model->getAttributeLabel($attribute); diff --git a/framework/validators/RangeValidator.php b/framework/validators/RangeValidator.php index 66296a765c..63be6eacc6 100644 --- a/framework/validators/RangeValidator.php +++ b/framework/validators/RangeValidator.php @@ -117,7 +117,7 @@ class RangeValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $range = []; foreach ($this->range as $value) { diff --git a/framework/validators/RegularExpressionValidator.php b/framework/validators/RegularExpressionValidator.php index b5a98e467b..60130e2685 100644 --- a/framework/validators/RegularExpressionValidator.php +++ b/framework/validators/RegularExpressionValidator.php @@ -74,7 +74,7 @@ class RegularExpressionValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $pattern = Html::escapeJsRegularExpression($this->pattern); diff --git a/framework/validators/RequiredValidator.php b/framework/validators/RequiredValidator.php index 54e5ad8a2e..21966c5725 100644 --- a/framework/validators/RequiredValidator.php +++ b/framework/validators/RequiredValidator.php @@ -97,7 +97,7 @@ class RequiredValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $options = []; if ($this->requiredValue !== null) { diff --git a/framework/validators/StringValidator.php b/framework/validators/StringValidator.php index 2465dcf83f..b41ae55f87 100644 --- a/framework/validators/StringValidator.php +++ b/framework/validators/StringValidator.php @@ -159,7 +159,7 @@ class StringValidator extends Validator return 'yii.validation.string(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; } - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { $label = $model->getAttributeLabel($attribute); diff --git a/framework/validators/UrlValidator.php b/framework/validators/UrlValidator.php index b6501ad5f5..8f6ef5bb19 100644 --- a/framework/validators/UrlValidator.php +++ b/framework/validators/UrlValidator.php @@ -125,7 +125,7 @@ class UrlValidator extends Validator /** * @inheritdoc */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { if (strpos($this->pattern, '{schemes}') !== false) { $pattern = str_replace('{schemes}', '(' . implode('|', $this->validSchemes) . ')', $this->pattern); diff --git a/framework/validators/Validator.php b/framework/validators/Validator.php index 1eb6084dec..e04d6f4994 100644 --- a/framework/validators/Validator.php +++ b/framework/validators/Validator.php @@ -372,7 +372,7 @@ class Validator extends Component * @return array the client-side validation options * @since 2.0.11 */ - protected function getClientOptions($model, $attribute) + public function getClientOptions($model, $attribute) { return []; }