Skip to content

Commit

Permalink
Merge 50b8421 into 6517352
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Dec 7, 2019
2 parents 6517352 + 50b8421 commit 77dcc40
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 471 deletions.
8 changes: 4 additions & 4 deletions composer.json
Expand Up @@ -25,11 +25,11 @@
"psr/log": "^1.1",
"yiisoft/aliases": "^3.0@dev",
"yiisoft/arrays": "^3.0@dev",
"yiisoft/files": "^3.0@dev",
"yiisoft/html": "^3.0@dev",
"yiisoft/i18n": "^3.0@dev",
"yiisoft/json": "^3.0@dev",
"yiisoft/var-dumper": "^3.0@dev",
"yiisoft/files": "^3.0@dev",
"yiisoft/i18n": "^3.0@dev"
"yiisoft/var-dumper": "^3.0@dev"
},
"require-dev": {
"hiqdev/composer-config-plugin": "^1.0@dev",
Expand Down Expand Up @@ -66,4 +66,4 @@
"config": {
"sort-packages": true
}
}
}
57 changes: 24 additions & 33 deletions src/Widget/ActiveField.php
Expand Up @@ -2,10 +2,9 @@

namespace Yiisoft\Widget;

use yii\base\ErrorHandler;
use yii\base\Model;
use yii\helpers\Html;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Html\Html;

/**
* ActiveField represents a form input field within an [[ActiveForm]].
Expand Down Expand Up @@ -33,11 +32,11 @@ class ActiveField
* The following special options are recognized:
*
* - `tag`: the tag name of the container element. Defaults to `div`. Setting it to `false` will not render a container tag.
* See also [[\yii\helpers\Html::tag()]].
* See also [[Html::tag()]].
*
* If you set a custom `id` for the container element, you may need to adjust the [[$selectors]] accordingly.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @see Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = ['class' => 'form-group'];
/**
Expand All @@ -51,7 +50,7 @@ class ActiveField
*
* If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @see Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $inputOptions = ['class' => 'form-control'];
/**
Expand All @@ -60,19 +59,19 @@ class ActiveField
* The following special options are recognized:
*
* - `tag`: the tag name of the container element. Defaults to `div`. Setting it to `false` will not render a container tag.
* See also [[\yii\helpers\Html::tag()]].
* See also [[Html::tag()]].
* - `encode`: whether to encode the error output. Defaults to `true`.
*
* If you set a custom `id` for the error element, you may need to adjust the [[$selectors]] accordingly.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @see Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $errorOptions = ['class' => 'help-block'];
/**
* @var array the default options for the label tags. The parameter passed to [[label()]] will be
* merged with this property when rendering the label tag.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @see Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $labelOptions = ['class' => 'control-label'];
/**
Expand All @@ -81,9 +80,9 @@ class ActiveField
* The following special options are recognized:
*
* - `tag`: the tag name of the container element. Defaults to `div`. Setting it to `false` will not render a container tag.
* See also [[\yii\helpers\Html::tag()]].
* See also [[Html::tag()]].
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @see Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $hintOptions = ['class' => 'hint-block'];
/**
Expand Down Expand Up @@ -147,11 +146,11 @@ class ActiveField
* @var string this property holds a custom input id if it was set using [[inputOptions]] or in one of the
* `$options` parameters of the `input*` methods.
*/
private $_inputId;
private $inputId;
/**
* @var bool if "for" field label attribute should be skipped.
*/
private $_skipLabelFor = false;
private $skipLabelFor = false;

/**
* PHP magic method that returns the string representation of this object.
Expand All @@ -160,15 +159,7 @@ class ActiveField
*/
public function __toString()
{
// __toString cannot throw exception
// use trigger_error to bypass this limitation
try {
return $this->render();
} catch (\Exception $e) {
ErrorHandler::convertExceptionToError($e);

return '';
}
return $this->render();
}

/**
Expand Down Expand Up @@ -276,7 +267,7 @@ public function label($label = null, $options = [])
$options['label'] = $label;
}

if ($this->_skipLabelFor) {
if ($this->skipLabelFor) {
$options['for'] = null;
}

Expand All @@ -296,7 +287,7 @@ public function label($label = null, $options = [])
* The following options are specially handled:
*
* - `tag`: this specifies the tag name. If not set, `div` will be used.
* See also [[\yii\helpers\Html::tag()]].
* See also [[Html::tag()]].
*
* If you set a custom `id` for the error element, you may need to adjust the [[$selectors]] accordingly.
*
Expand Down Expand Up @@ -330,7 +321,7 @@ public function error($options = [])
* The following options are specially handled:
*
* - `tag`: this specifies the tag name. If not set, `div` will be used.
* See also [[\yii\helpers\Html::tag()]].
* See also [[Html::tag()]].
*
* @return $this the field object itself.
*/
Expand Down Expand Up @@ -414,7 +405,7 @@ public function textInput($options = [])
*
* Note that this method is provided for completeness. In most cases because you do not need
* to validate a hidden input, you should not need to use this method. Instead, you should
* use [[\yii\helpers\Html::activeHiddenInput()]].
* use [[Html::activeHiddenInput()]].
*
* This method will generate the `name` and `value` tag attributes automatically for the model attribute
* unless they are explicitly specified in `$options`.
Expand Down Expand Up @@ -643,7 +634,7 @@ public function checkbox($options = [], $enclosedByLabel = true)
* the labels will also be HTML-encoded.
* @param array $options the tag options in terms of name-value pairs.
*
* For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeDropDownList()]].
* For the list of available options please refer to the `$options` parameter of [[Html::activeDropDownList()]].
*
* If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly.
*
Expand Down Expand Up @@ -678,7 +669,7 @@ public function dropDownList($items, $options = [])
* the labels will also be HTML-encoded.
* @param array $options the tag options in terms of name-value pairs.
*
* For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeListBox()]].
* For the list of available options please refer to the `$options` parameter of [[Html::activeListBox()]].
*
* If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly.
*
Expand Down Expand Up @@ -708,7 +699,7 @@ public function listBox($items, $options = [])
* @param array $items the data item used to generate the checkboxes.
* The array values are the labels, while the array keys are the corresponding checkbox values.
* @param array $options options (name => config) for the checkbox list.
* For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeCheckboxList()]].
* For the list of available options please refer to the `$options` parameter of [[Html::activeCheckboxList()]].
*
* @return $this the field object itself.
*/
Expand All @@ -720,7 +711,7 @@ public function checkboxList($items, $options = [])

$this->addAriaAttributes($options);
$this->adjustLabelFor($options);
$this->_skipLabelFor = true;
$this->skipLabelFor = true;
$this->parts['{input}'] = Html::activeCheckboxList($this->model, $this->attribute, $items, $options);

return $this;
Expand All @@ -734,7 +725,7 @@ public function checkboxList($items, $options = [])
* @param array $items the data item used to generate the radio buttons.
* The array values are the labels, while the array keys are the corresponding radio values.
* @param array $options options (name => config) for the radio button list.
* For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeRadioList()]].
* For the list of available options please refer to the `$options` parameter of [[Html::activeRadioList()]].
*
* @return $this the field object itself.
*/
Expand All @@ -746,7 +737,7 @@ public function radioList($items, $options = [])

$this->addAriaAttributes($options);
$this->adjustLabelFor($options);
$this->_skipLabelFor = true;
$this->skipLabelFor = true;
$this->parts['{input}'] = Html::activeRadioList($this->model, $this->attribute, $items, $options);

return $this;
Expand Down Expand Up @@ -812,7 +803,7 @@ protected function adjustLabelFor($options)
if (!isset($options['id'])) {
return;
}
$this->_inputId = $options['id'];
$this->inputId = $options['id'];
if (!isset($this->labelOptions['for'])) {
$this->labelOptions['for'] = $options['id'];
}
Expand Down Expand Up @@ -845,7 +836,7 @@ public function isAjaxValidationEnabled()
*/
public function getInputId()
{
return $this->_inputId ?: Html::getInputId($this->model, $this->attribute);
return $this->inputId ?: Html::getInputId($this->model, $this->attribute);
}

/**
Expand Down
24 changes: 10 additions & 14 deletions src/Widget/ActiveForm.php
Expand Up @@ -2,13 +2,9 @@

namespace Yiisoft\Widget;

use yii\base\Model;
use yii\di\Initiable;
use yii\exceptions\InvalidCallException;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\Url;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Html\Html;
use Yiisoft\View\InvalidCallException;
use Yiisoft\Widget\Event\AfterActiveFieldRender;
use Yiisoft\Widget\Event\BeforeActiveFieldRender;

Expand All @@ -17,19 +13,19 @@
*
* For more details and usage information on ActiveForm, see the [guide article on forms](guide:input-forms).
*/
class ActiveForm extends Widget implements Initiable
class ActiveForm extends Widget
{
/**
* Add validation state class to container tag.
*/
const VALIDATION_STATE_ON_CONTAINER = 'container';
public const VALIDATION_STATE_ON_CONTAINER = 'container';
/**
* Add validation state class to input tag.
*/
const VALIDATION_STATE_ON_INPUT = 'input';
public const VALIDATION_STATE_ON_INPUT = 'input';

/**
* @var array|string the form action URL. This parameter will be processed by [[\yii\helpers\Url::to()]].
* @var array|string the form action URL. This parameter will be processed by [[Url::to()]].
*
* @see method for specifying the HTTP method for this form.
*/
Expand All @@ -53,7 +49,7 @@ class ActiveForm extends Widget implements Initiable
/**
* @var array the HTML attributes (name-value pairs) for the form tag.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @see Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = [];
/**
Expand Down Expand Up @@ -218,7 +214,7 @@ public function run(): string
* - `footer`: string, the footer HTML for the error summary.
*
* The rest of the options will be rendered as the attributes of the container tag. The values will
* be HTML-encoded using [[\yii\helpers\Html::encode()]]. If a value is `null`, the corresponding attribute will not be rendered.
* be HTML-encoded using [[Html::encode()]]. If a value is `null`, the corresponding attribute will not be rendered.
*
* @return string the generated error summary.
*
Expand Down Expand Up @@ -405,7 +401,7 @@ public static function validateMultiple($models, $attributes = null)
*/
public function beforeFieldRender(ActiveField $field)
{
$this->eventDispatcher->dispatch(new BeforeActiveFieldRender($field));
self::$eventDispatcher->dispatch(new BeforeActiveFieldRender($field));
}

/**
Expand All @@ -416,6 +412,6 @@ public function beforeFieldRender(ActiveField $field)
*/
public function afterFieldRender(ActiveField $field)
{
$this->eventDispatcher->dispatch(new AfterActiveFieldRender($field));
self::$eventDispatcher->dispatch(new AfterActiveFieldRender($field));
}
}
4 changes: 2 additions & 2 deletions src/Widget/Event/AfterRun.php
Expand Up @@ -6,12 +6,12 @@ class AfterRun
{
private $result;

public function __construct($result)
public function __construct(string $result)
{
$this->result = $result;
}

public function getResult()
public function getResult(): string
{
return $this->result;
}
Expand Down

0 comments on commit 77dcc40

Please sign in to comment.