Browse Source

Fixes #14294: Added `InputWidget::renderInputHtml()` to move behavior described in `InputWidget` class docs to the class itself

This reverts commit b0162d3a48.

Closes #14294
tags/2.0.13
SilverFire - Dmitry Naumenko 7 years ago
parent
commit
34cc2dee8f
No known key found for this signature in database
GPG Key ID: 39DD917A92B270A
  1. 1
      framework/CHANGELOG.md
  2. 6
      framework/captcha/Captcha.php
  3. 27
      framework/widgets/InputWidget.php
  4. 6
      framework/widgets/MaskedInput.php

1
framework/CHANGELOG.md

@ -71,6 +71,7 @@ Yii Framework 2 Change Log
- Bug #11825: User can login by cookie only once when `autoRenewCookie` is set to false (shirase, silverfire)
- Bug #13969: Fixed a bug in a `yii\console\controllers\CacheController` when caches defined via a closure were not detected (Kolyunya)
- Enh #14061: Added request scope assignments cache to `yii\rbac\DbManager::checkAccess()` to avoid duplicate queries for user assignments (leandrogehlen, cebe, nineinchnick, ryusoft)
- Enh #14294: Added `InputWidget::renderInput()` to move behavior described in `InputWidget` class docs to the class itself (cebe)
2.0.12 June 05, 2017

6
framework/captcha/Captcha.php

@ -104,11 +104,7 @@ class Captcha extends InputWidget
public function run()
{
$this->registerClientScript();
if ($this->hasModel()) {
$input = Html::activeTextInput($this->model, $this->attribute, $this->options);
} else {
$input = Html::textInput($this->name, $this->value, $this->options);
}
$input = $this->renderInputHtml('text');
$route = $this->captchaAction;
if (is_array($route)) {
$route['v'] = uniqid();

27
framework/widgets/InputWidget.php

@ -16,9 +16,9 @@ use yii\helpers\Html;
/**
* InputWidget is the base class for widgets that collect user inputs.
*
* An input widget can be associated with a data model and an attribute,
* or a name and a value. If the former, the name and the value will
* be generated automatically.
* An input widget can be associated with a data [[model]] and an [[attribute]],
* or a [[name]] and a [[value]]. If the former, the name and the value will
* be generated automatically (subclasses may call [[renderInputHtml()]] to follow this behavior).
*
* Classes extending from this widget can be used in an [[\yii\widgets\ActiveForm|ActiveForm]]
* using the [[\yii\widgets\ActiveField::widget()|widget()]] method, for example like this:
@ -87,4 +87,25 @@ class InputWidget extends Widget
{
return $this->model instanceof Model && $this->attribute !== null;
}
/**
* Render a HTML input tag
*
* This will call [[Html::activeInput()]] if the input widget is [[hasModel()|tied to a model]],
* or [[Html::input()]] if not.
*
* @param string $type the type of the input to create.
* @return string the HTML of the input field.
* @since 2.0.13
* @see Html::activeInput()
* @see Html::input()
*/
protected function renderInputHtml($type)
{
if ($this->hasModel()) {
return Html::activeInput($type, $this->model, $this->attribute, $this->options);
} else {
return Html::input($type, $this->name, $this->value, $this->options);
}
}
}

6
framework/widgets/MaskedInput.php

@ -124,11 +124,7 @@ class MaskedInput extends InputWidget
public function run()
{
$this->registerClientScript();
if ($this->hasModel()) {
echo Html::activeInput($this->type, $this->model, $this->attribute, $this->options);
} else {
echo Html::input($this->type, $this->name, $this->value, $this->options);
}
echo $this->renderInputHtml($this->type);
}
/**

Loading…
Cancel
Save