mirror of
https://github.com/yiisoft/yii2.git
synced 2025-12-01 23:51:12 +08:00
Merge pull request #10292 from Faryshta/patch-5
use ArrayHelper::remove() for the html helper methods
This commit is contained in:
@@ -884,9 +884,12 @@ class BaseHtml
|
|||||||
$name .= '[]';
|
$name .= '[]';
|
||||||
}
|
}
|
||||||
|
|
||||||
$formatter = isset($options['item']) ? $options['item'] : null;
|
$formatter = ArrayHelper::remove($options, 'item');
|
||||||
$itemOptions = isset($options['itemOptions']) ? $options['itemOptions'] : [];
|
$itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
|
||||||
$encode = !isset($options['encode']) || $options['encode'];
|
$encode = ArrayHelper::remove($options, 'encode', true);
|
||||||
|
$separator = ArrayHelper::remove($options, 'separator', "\n");
|
||||||
|
$tag = ArrayHelper::remove($options, 'tag', 'div');
|
||||||
|
|
||||||
$lines = [];
|
$lines = [];
|
||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($items as $value => $label) {
|
foreach ($items as $value => $label) {
|
||||||
@@ -908,13 +911,10 @@ class BaseHtml
|
|||||||
// add a hidden field so that if the list box has no option being selected, it still submits a value
|
// add a hidden field so that if the list box has no option being selected, it still submits a value
|
||||||
$name2 = substr($name, -2) === '[]' ? substr($name, 0, -2) : $name;
|
$name2 = substr($name, -2) === '[]' ? substr($name, 0, -2) : $name;
|
||||||
$hidden = static::hiddenInput($name2, $options['unselect']);
|
$hidden = static::hiddenInput($name2, $options['unselect']);
|
||||||
|
unset($options['unselect']);
|
||||||
} else {
|
} else {
|
||||||
$hidden = '';
|
$hidden = '';
|
||||||
}
|
}
|
||||||
$separator = isset($options['separator']) ? $options['separator'] : "\n";
|
|
||||||
|
|
||||||
$tag = isset($options['tag']) ? $options['tag'] : 'div';
|
|
||||||
unset($options['tag'], $options['unselect'], $options['encode'], $options['separator'], $options['item'], $options['itemOptions']);
|
|
||||||
|
|
||||||
return $hidden . static::tag($tag, implode($separator, $lines), $options);
|
return $hidden . static::tag($tag, implode($separator, $lines), $options);
|
||||||
}
|
}
|
||||||
@@ -953,9 +953,12 @@ class BaseHtml
|
|||||||
*/
|
*/
|
||||||
public static function radioList($name, $selection = null, $items = [], $options = [])
|
public static function radioList($name, $selection = null, $items = [], $options = [])
|
||||||
{
|
{
|
||||||
$encode = !isset($options['encode']) || $options['encode'];
|
$formatter = ArrayHelper::remove($options, 'item');
|
||||||
$formatter = isset($options['item']) ? $options['item'] : null;
|
$itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
|
||||||
$itemOptions = isset($options['itemOptions']) ? $options['itemOptions'] : [];
|
$encode = ArrayHelper::remove($options, 'encode', true);
|
||||||
|
$separator = ArrayHelper::remove($options, 'separator', "\n");
|
||||||
|
$tag = ArrayHelper::remove($options, 'tag', 'div');
|
||||||
|
|
||||||
$lines = [];
|
$lines = [];
|
||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($items as $value => $label) {
|
foreach ($items as $value => $label) {
|
||||||
@@ -973,17 +976,14 @@ class BaseHtml
|
|||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$separator = isset($options['separator']) ? $options['separator'] : "\n";
|
|
||||||
if (isset($options['unselect'])) {
|
if (isset($options['unselect'])) {
|
||||||
// add a hidden field so that if the list box has no option being selected, it still submits a value
|
// add a hidden field so that if the list box has no option being selected, it still submits a value
|
||||||
$hidden = static::hiddenInput($name, $options['unselect']);
|
$hidden = static::hiddenInput($name, $options['unselect']);
|
||||||
|
unset($options['unselect']);
|
||||||
} else {
|
} else {
|
||||||
$hidden = '';
|
$hidden = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$tag = isset($options['tag']) ? $options['tag'] : 'div';
|
|
||||||
unset($options['tag'], $options['unselect'], $options['encode'], $options['separator'], $options['item'], $options['itemOptions']);
|
|
||||||
|
|
||||||
return $hidden . static::tag($tag, implode($separator, $lines), $options);
|
return $hidden . static::tag($tag, implode($separator, $lines), $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -995,6 +995,7 @@ class BaseHtml
|
|||||||
*
|
*
|
||||||
* - encode: boolean, whether to HTML-encode the items. Defaults to true.
|
* - encode: boolean, whether to HTML-encode the items. Defaults to true.
|
||||||
* This option is ignored if the `item` option is specified.
|
* This option is ignored if the `item` option is specified.
|
||||||
|
* - separator: string, since 2.0.7 the HTML code that separates items.
|
||||||
* - itemOptions: array, the HTML attributes for the `li` tags. This option is ignored if the `item` option is specified.
|
* - itemOptions: array, the HTML attributes for the `li` tags. This option is ignored if the `item` option is specified.
|
||||||
* - item: callable, a callback that is used to generate each individual list item.
|
* - item: callable, a callback that is used to generate each individual list item.
|
||||||
* The signature of this callback must be:
|
* The signature of this callback must be:
|
||||||
@@ -1012,11 +1013,11 @@ class BaseHtml
|
|||||||
*/
|
*/
|
||||||
public static function ul($items, $options = [])
|
public static function ul($items, $options = [])
|
||||||
{
|
{
|
||||||
$tag = isset($options['tag']) ? $options['tag'] : 'ul';
|
$tag = ArrayHelper::remove($options, 'tag', 'ul');
|
||||||
$encode = !isset($options['encode']) || $options['encode'];
|
$encode = ArrayHelper::remove($options, 'encode', true);
|
||||||
$formatter = isset($options['item']) ? $options['item'] : null;
|
$formatter = ArrayHelper::remove($options, 'item');
|
||||||
$itemOptions = isset($options['itemOptions']) ? $options['itemOptions'] : [];
|
$separator = ArrayHelper::remove($options, 'separator', "\n");
|
||||||
unset($options['tag'], $options['encode'], $options['item'], $options['itemOptions']);
|
$itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
|
||||||
|
|
||||||
if (empty($items)) {
|
if (empty($items)) {
|
||||||
return static::tag($tag, '', $options);
|
return static::tag($tag, '', $options);
|
||||||
@@ -1030,7 +1031,12 @@ class BaseHtml
|
|||||||
$results[] = static::tag('li', $encode ? static::encode($item) : $item, $itemOptions);
|
$results[] = static::tag('li', $encode ? static::encode($item) : $item, $itemOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return static::tag($tag, "\n" . implode("\n", $results) . "\n", $options);
|
|
||||||
|
return static::tag(
|
||||||
|
$tag,
|
||||||
|
$separator . implode($separator, $results) . $separator,
|
||||||
|
$options
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1083,10 +1089,9 @@ class BaseHtml
|
|||||||
*/
|
*/
|
||||||
public static function activeLabel($model, $attribute, $options = [])
|
public static function activeLabel($model, $attribute, $options = [])
|
||||||
{
|
{
|
||||||
$for = array_key_exists('for', $options) ? $options['for'] : static::getInputId($model, $attribute);
|
$for = ArrayHelper::remove($options, 'for', static::getInputId($model, $attribute));
|
||||||
$attribute = static::getAttributeName($attribute);
|
$attribute = static::getAttributeName($attribute);
|
||||||
$label = isset($options['label']) ? $options['label'] : static::encode($model->getAttributeLabel($attribute));
|
$label = ArrayHelper::remove($options, 'label', static::encode($model->getAttributeLabel($attribute)));
|
||||||
unset($options['label'], $options['for']);
|
|
||||||
return static::label($label, $for, $options);
|
return static::label($label, $for, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1140,9 +1145,9 @@ class BaseHtml
|
|||||||
public static function errorSummary($models, $options = [])
|
public static function errorSummary($models, $options = [])
|
||||||
{
|
{
|
||||||
$header = isset($options['header']) ? $options['header'] : '<p>' . Yii::t('yii', 'Please fix the following errors:') . '</p>';
|
$header = isset($options['header']) ? $options['header'] : '<p>' . Yii::t('yii', 'Please fix the following errors:') . '</p>';
|
||||||
$footer = isset($options['footer']) ? $options['footer'] : '';
|
$footer = ArrayHelper::remove($options, 'footer', '');
|
||||||
$encode = !isset($options['encode']) || $options['encode'] !== false;
|
$encode = ArrayHelper::remove($options, 'encode', true);
|
||||||
unset($options['header'], $options['footer'], $options['encode']);
|
unset($options['header']);
|
||||||
|
|
||||||
$lines = [];
|
$lines = [];
|
||||||
if (!is_array($models)) {
|
if (!is_array($models)) {
|
||||||
@@ -1187,9 +1192,8 @@ class BaseHtml
|
|||||||
{
|
{
|
||||||
$attribute = static::getAttributeName($attribute);
|
$attribute = static::getAttributeName($attribute);
|
||||||
$error = $model->getFirstError($attribute);
|
$error = $model->getFirstError($attribute);
|
||||||
$tag = isset($options['tag']) ? $options['tag'] : 'div';
|
$tag = ArrayHelper::remove($options, 'tag', 'div');
|
||||||
$encode = !isset($options['encode']) || $options['encode'] !== false;
|
$encode = ArrayHelper::remove($options, 'encode', true);
|
||||||
unset($options['tag'], $options['encode']);
|
|
||||||
return Html::tag($tag, $encode ? Html::encode($error) : $error, $options);
|
return Html::tag($tag, $encode ? Html::encode($error) : $error, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user