From bf5476f253633925a5dfb51dda1f286081d578ce Mon Sep 17 00:00:00 2001 From: Alexey Date: Sat, 28 Jul 2018 19:07:09 +0300 Subject: [PATCH] Fixes #15889: Fixed override `yii\helpers\Html::setActivePlaceholder` --- framework/CHANGELOG.md | 1 + framework/helpers/BaseHtml.php | 4 ++-- tests/framework/helpers/HtmlTest.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 81193184b1..f2ef76f41c 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -40,6 +40,7 @@ Yii Framework 2 Change Log - Chg #16192: `yii\db\Command::logQuery()` is now protected, extracted `getCacheKey()` from `queryInternal()` (drlibra) - Bug #16377: Fixed `yii\base\Event:off()` undefined index error when event handler does not match (razvanphp) - Bug #16514: Fixed `yii\di\Container::resolveCallableDependencies` to support callable object (wi1dcard) +- Bug #15889: Fixed override `yii\helpers\Html::setActivePlaceholder` (lesha724) 2.0.15.1 March 21, 2018 ----------------------- diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index fdf5b1b432..eb0226a8b5 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -1325,7 +1325,7 @@ class BaseHtml $options['id'] = static::getInputId($model, $attribute); } - self::setActivePlaceholder($model, $attribute, $options); + static::setActivePlaceholder($model, $attribute, $options); return static::input($type, $name, $value, $options); } @@ -1502,7 +1502,7 @@ class BaseHtml $options['id'] = static::getInputId($model, $attribute); } self::normalizeMaxLength($model, $attribute, $options); - self::setActivePlaceholder($model, $attribute, $options); + static::setActivePlaceholder($model, $attribute, $options); return static::textarea($name, $value, $options); } diff --git a/tests/framework/helpers/HtmlTest.php b/tests/framework/helpers/HtmlTest.php index e00b1f15c5..8e4923e5b6 100644 --- a/tests/framework/helpers/HtmlTest.php +++ b/tests/framework/helpers/HtmlTest.php @@ -1729,6 +1729,34 @@ HTML; $this->assertContains('placeholder="Name"', $html); } + public function testOverrideSetActivePlaceholder() + { + $model = new HtmlTestModel(); + + $html = MyHtml::activeTextInput($model, 'name', ['placeholder' => true]); + + $this->assertContains('placeholder="My placeholder: Name"', $html); + } +} + +/** + * Class MyHtml + * @package yiiunit\framework\helpers + */ +class MyHtml extends Html{ + + /** + * @param \yii\base\Model $model + * @param string $attribute + * @param array $options + */ + protected static function setActivePlaceholder($model, $attribute, &$options = []) + { + if (isset($options['placeholder']) && $options['placeholder'] === true) { + $attribute = static::getAttributeName($attribute); + $options['placeholder'] = 'My placeholder: '. $model->getAttributeLabel($attribute); + } + } } /**