go back to 7.0 language level

code style updates
This commit is contained in:
Simon Karlen 2021-08-04 08:03:41 +02:00
parent c3c1bb2eba
commit 4610054aea
No known key found for this signature in database
GPG Key ID: 0630C27D666EBCC3
25 changed files with 297 additions and 240 deletions

View File

@ -13,7 +13,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest] os: [ubuntu-latest]
php: ['7.4', '8.0'] php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
steps: steps:
- name: Checkout - name: Checkout

View File

@ -25,7 +25,7 @@
], ],
"minimum-stability": "stable", "minimum-stability": "stable",
"require": { "require": {
"php": ">=7.4.0", "php": ">=7.0",
"ext-json": "*", "ext-json": "*",
"yiisoft/yii2": "^2.0.42", "yiisoft/yii2": "^2.0.42",
"bower-asset/bootstrap": "^5.0.0" "bower-asset/bootstrap": "^5.0.0"

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use Exception;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -83,16 +84,16 @@ class Accordion extends Widget
* ]) * ])
* ``` * ```
*/ */
public array $items = []; public $items = [];
/** /**
* @var bool whether the labels for header items should be HTML-encoded. * @var bool whether the labels for header items should be HTML-encoded.
*/ */
public bool $encodeLabels = true; public $encodeLabels = true;
/** /**
* @var bool whether to close other items if an item is opened. Defaults to `true` which causes an * @var bool whether to close other items if an item is opened. Defaults to `true` which causes an
* accordion effect. Set this to `false` to allow keeping multiple items open at once. * accordion effect. Set this to `false` to allow keeping multiple items open at once.
*/ */
public bool $autoCloseItems = true; public $autoCloseItems = true;
/** /**
* @var array the HTML options for the item toggle tag. Key 'tag' might be used here for the tag name specification. * @var array the HTML options for the item toggle tag. Key 'tag' might be used here for the tag name specification.
* For example: * For example:
@ -105,7 +106,7 @@ class Accordion extends Widget
* ``` * ```
* *
*/ */
public array $itemToggleOptions = []; public $itemToggleOptions = [];
/** /**
@ -116,6 +117,7 @@ class Accordion extends Widget
{ {
$this->registerPlugin('collapse'); $this->registerPlugin('collapse');
Html::addCssClass($this->options, ['widget' => 'accordion']); Html::addCssClass($this->options, ['widget' => 'accordion']);
return implode("\n", [ return implode("\n", [
Html::beginTag('div', $this->options), Html::beginTag('div', $this->options),
$this->renderItems(), $this->renderItems(),
@ -164,7 +166,7 @@ class Accordion extends Widget
* @param int $index the item index as each item group content must have an id * @param int $index the item index as each item group content must have an id
* @return string the rendering result * @return string the rendering result
* @throws InvalidConfigException * @throws InvalidConfigException
* @throws \Exception * @throws Exception
*/ */
public function renderItem(string $header, array $item, int $index): string public function renderItem(string $header, array $item, int $index): string
{ {

View File

@ -93,15 +93,15 @@ class ActiveField extends \yii\widgets\ActiveField
/** /**
* @var bool whether to render [[checkboxList()]] and [[radioList()]] inline. * @var bool whether to render [[checkboxList()]] and [[radioList()]] inline.
*/ */
public bool $inline = false; public $inline = false;
/** /**
* @var string|null optional template to render the `{input}` placeholder content * @var string|null optional template to render the `{input}` placeholder content
*/ */
public ?string $inputTemplate = null; public $inputTemplate = null;
/** /**
* @var array options for the wrapper tag, used in the `{beginWrapper}` placeholder * @var array options for the wrapper tag, used in the `{beginWrapper}` placeholder
*/ */
public array $wrapperOptions = []; public $wrapperOptions = [];
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -119,7 +119,7 @@ class ActiveField extends \yii\widgets\ActiveField
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @since 2.0.7 * @since 2.0.7
*/ */
public array $checkOptions = [ public $checkOptions = [
'class' => ['widget' => 'form-check-input'], 'class' => ['widget' => 'form-check-input'],
'labelOptions' => [ 'labelOptions' => [
'class' => ['widget' => 'form-check-label'], 'class' => ['widget' => 'form-check-label'],
@ -134,7 +134,7 @@ class ActiveField extends \yii\widgets\ActiveField
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @since 2.0.7 * @since 2.0.7
*/ */
public array $radioOptions = [ public $radioOptions = [
'class' => ['widget' => 'form-check-input'], 'class' => ['widget' => 'form-check-input'],
'labelOptions' => [ 'labelOptions' => [
'class' => ['widget' => 'form-check-label'], 'class' => ['widget' => 'form-check-label'],
@ -160,37 +160,37 @@ class ActiveField extends \yii\widgets\ActiveField
* - 'error' the error grid class * - 'error' the error grid class
* - 'hint' the hint grid class * - 'hint' the hint grid class
*/ */
public ?array $horizontalCssClasses = []; public $horizontalCssClasses = [];
/** /**
* @var string the template for checkboxes in default layout * @var string the template for checkboxes in default layout
*/ */
public string $checkTemplate = "<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>"; public $checkTemplate = "<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>";
/** /**
* @var string the template for radios in default layout * @var string the template for radios in default layout
* @since 2.0.5 * @since 2.0.5
*/ */
public string $radioTemplate = "<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>"; public $radioTemplate = "<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>";
/** /**
* @var string the template for checkboxes and radios in horizontal layout * @var string the template for checkboxes and radios in horizontal layout
*/ */
public string $checkHorizontalTemplate = "{beginWrapper}\n<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>\n{endWrapper}"; public $checkHorizontalTemplate = "{beginWrapper}\n<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>\n{endWrapper}";
/** /**
* @var string the template for checkboxes and radios in horizontal layout * @var string the template for checkboxes and radios in horizontal layout
* @since 2.0.5 * @since 2.0.5
*/ */
public string $radioHorizontalTemplate = "{beginWrapper}\n<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>\n{endWrapper}"; public $radioHorizontalTemplate = "{beginWrapper}\n<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>\n{endWrapper}";
/** /**
* @var string the `enclosed by label` template for checkboxes and radios in default layout * @var string the `enclosed by label` template for checkboxes and radios in default layout
*/ */
public string $checkEnclosedTemplate = "<div class=\"form-check\">\n{beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n</div>"; public $checkEnclosedTemplate = "<div class=\"form-check\">\n{beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n</div>";
/** /**
* @var bool whether to render the error. Default is `true` except for layout `inline`. * @var bool whether to render the error. Default is `true` except for layout `inline`.
*/ */
public bool $enableError = true; public $enableError = true;
/** /**
* @var bool whether to render the label. Default is `true`. * @var bool whether to render the label. Default is `true`.
*/ */
public bool $enableLabel = true; public $enableLabel = true;
/** /**
@ -238,6 +238,7 @@ class ActiveField extends \yii\widgets\ActiveField
$this->parts['{input}'] = strtr($this->inputTemplate, ['{input}' => $input]); $this->parts['{input}'] = strtr($this->inputTemplate, ['{input}' => $input]);
} }
} }
return parent::render($content); return parent::render($content);
} }
@ -351,6 +352,7 @@ class ActiveField extends \yii\widgets\ActiveField
} }
parent::checkboxList($items, $options); parent::checkboxList($items, $options);
return $this; return $this;
} }
@ -392,6 +394,7 @@ class ActiveField extends \yii\widgets\ActiveField
} }
parent::radioList($items, $options); parent::radioList($items, $options);
return $this; return $this;
} }
@ -429,10 +432,11 @@ class ActiveField extends \yii\widgets\ActiveField
* @return $this the field object itself * @return $this the field object itself
* @see https://getbootstrap.com/docs/5.0/components/forms/#readonly-plain-text * @see https://getbootstrap.com/docs/5.0/components/forms/#readonly-plain-text
*/ */
public function staticControl($options = []): self public function staticControl(array $options = []): self
{ {
$this->adjustLabelFor($options); $this->adjustLabelFor($options);
$this->parts['{input}'] = Html::activeStaticControl($this->model, $this->attribute, $options); $this->parts['{input}'] = Html::activeStaticControl($this->model, $this->attribute, $options);
return $this; return $this;
} }
@ -451,6 +455,7 @@ class ActiveField extends \yii\widgets\ActiveField
$this->renderLabelParts($label, $options); $this->renderLabelParts($label, $options);
parent::label($label, $options); parent::label($label, $options);
} }
return $this; return $this;
} }
@ -462,9 +467,20 @@ class ActiveField extends \yii\widgets\ActiveField
public function inline($value = true): self public function inline($value = true): self
{ {
$this->inline = (bool)$value; $this->inline = (bool)$value;
return $this; return $this;
} }
/**
* {@inheritdoc}
*/
public function fileInput($options = [])
{
Html::addCssClass($options, ['widget' => 'form-control']);
return parent::fileInput($options);
}
/** /**
* @param array $instanceConfig the configuration passed to this instance's constructor * @param array $instanceConfig the configuration passed to this instance's constructor
* @return array the layout specific default configuration for this instance * @return array the layout specific default configuration for this instance
@ -527,20 +543,11 @@ class ActiveField extends \yii\widgets\ActiveField
return $config; return $config;
} }
/**
* {@inheritdoc}
*/
public function fileInput($options = [])
{
Html::addCssClass($options, ['widget' => 'form-control']);
return parent::fileInput($options);
}
/** /**
* @param string|null $label the label or null to use model label * @param string|null $label the label or null to use model label
* @param array $options the tag options * @param array $options the tag options
*/ */
protected function renderLabelParts($label = null, $options = []) protected function renderLabelParts(string $label = null, array $options = [])
{ {
$options = array_merge($this->labelOptions, $options); $options = array_merge($this->labelOptions, $options);
if ($label === null) { if ($label === null) {

View File

@ -93,7 +93,7 @@ class ActiveForm extends \yii\widgets\ActiveForm
* override these defaults through [[fieldConfig]]. * override these defaults through [[fieldConfig]].
* @see ActiveField for details on Bootstrap 5 field configuration * @see ActiveField for details on Bootstrap 5 field configuration
*/ */
public string $layout = self::LAYOUT_DEFAULT; public $layout = self::LAYOUT_DEFAULT;
/** /**
* @var string the CSS class that is added to a field container when the associated attribute has validation error. * @var string the CSS class that is added to a field container when the associated attribute has validation error.
*/ */

View File

@ -46,7 +46,7 @@ class Alert extends Widget
* the [[begin()]] and [[end()]] calls of the Alert widget will also be treated * the [[begin()]] and [[end()]] calls of the Alert widget will also be treated
* as the body content, and will be rendered before this. * as the body content, and will be rendered before this.
*/ */
public string $body; public $body;
/** /**
* @var array|false the options for rendering the close button tag. * @var array|false the options for rendering the close button tag.
* The close button is displayed in the header of the modal window. Clicking * The close button is displayed in the header of the modal window. Clicking
@ -99,7 +99,7 @@ class Alert extends Widget
* Renders the close button. * Renders the close button.
* @return string|null the rendering result * @return string|null the rendering result
*/ */
protected function renderCloseButton(): ?string protected function renderCloseButton()
{ {
if (($closeButton = $this->closeButton) !== false) { if (($closeButton = $this->closeButton) !== false) {
$tag = ArrayHelper::remove($closeButton, 'tag', 'button'); $tag = ArrayHelper::remove($closeButton, 'tag', 'button');

View File

@ -16,12 +16,12 @@ abstract class BaseHtml extends \yii\helpers\Html
* @var int a counter used to generate [[id]] for widgets. * @var int a counter used to generate [[id]] for widgets.
* @internal * @internal
*/ */
public static int $counter = 0; public static $counter = 0;
/** /**
* @var string the prefix to the automatically generated widget IDs. * @var string the prefix to the automatically generated widget IDs.
* @see getId() * @see getId()
*/ */
public static string $autoIdPrefix = 'i'; public static $autoIdPrefix = 'i';
/** /**
* @var array list of tag attributes that should be specially handled when their values are of array type. * @var array list of tag attributes that should be specially handled when their values are of array type.
* In particular, if the value of the `data` attribute is `['name' => 'xyz', 'age' => 13]`, two attributes * In particular, if the value of the `data` attribute is `['name' => 'xyz', 'age' => 13]`, two attributes
@ -46,12 +46,13 @@ abstract class BaseHtml extends \yii\helpers\Html
static::addCssClass($options, 'form-control-plaintext'); static::addCssClass($options, 'form-control-plaintext');
$value = (string)$value; $value = (string)$value;
$options['readonly'] = true; $options['readonly'] = true;
return static::input('text', null, $value, $options); return static::input('text', null, $value, $options);
} }
/** /**
* Generates a Bootstrap static form control for the given model attribute. * Generates a Bootstrap static form control for the given model attribute.
* @param \yii\base\Model $model the model object. * @param Model $model the model object.
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format * @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
* about attribute expression. * about attribute expression.
* @param array $options the tag options in terms of name-value pairs. See [[staticControl()]] for details. * @param array $options the tag options in terms of name-value pairs. See [[staticControl()]] for details.
@ -66,6 +67,7 @@ abstract class BaseHtml extends \yii\helpers\Html
} else { } else {
$value = static::getAttributeValue($model, $attribute); $value = static::getAttributeValue($model, $attribute);
} }
return static::staticControl($value, $options); return static::staticControl($value, $options);
} }
@ -86,6 +88,7 @@ abstract class BaseHtml extends \yii\helpers\Html
'labelOptions' => ['class' => 'form-check-label'], 'labelOptions' => ['class' => 'form-check-label'],
'value' => $value, 'value' => $value,
], $itemOptions); ], $itemOptions);
return '<div class="form-check">' . static::radio($name, $checked, $options) . '</div>'; return '<div class="form-check">' . static::radio($name, $checked, $options) . '</div>';
}; };
} }
@ -110,6 +113,7 @@ abstract class BaseHtml extends \yii\helpers\Html
'labelOptions' => ['class' => 'form-check-label'], 'labelOptions' => ['class' => 'form-check-label'],
'value' => $value, 'value' => $value,
], $itemOptions); ], $itemOptions);
return '<div class="form-check">' . Html::checkbox($name, $checked, $options) . '</div>'; return '<div class="form-check">' . Html::checkbox($name, $checked, $options) . '</div>';
}; };
} }
@ -117,6 +121,18 @@ abstract class BaseHtml extends \yii\helpers\Html
return parent::checkboxList($name, $selection, $items, $options); return parent::checkboxList($name, $selection, $items, $options);
} }
/**
* {@inheritdoc}
*/
public static function error($model, $attribute, $options = []): string
{
if (!array_key_exists('class', $options)) {
$options['class'] = ['invalid-feedback'];
}
return parent::error($model, $attribute, $options);
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
@ -152,23 +168,13 @@ abstract class BaseHtml extends \yii\helpers\Html
} else { } else {
$content = $input . "\n" . static::label($label, $options['id'], $labelOptions); $content = $input . "\n" . static::label($label, $options['id'], $labelOptions);
} }
return $hidden . $content; return $hidden . $content;
} }
return $hidden . static::input($type, $name, $value, $options); return $hidden . static::input($type, $name, $value, $options);
} }
/**
* {@inheritdoc}
*/
public static function error($model, $attribute, $options = []): string
{
if (!array_key_exists('class', $options)) {
$options['class'] = ['invalid-feedback'];
}
return parent::error($model, $attribute, $options);
}
/** /**
* Returns an autogenerated ID * Returns an autogenerated ID
* @return string Autogenerated ID * @return string Autogenerated ID

View File

@ -35,14 +35,14 @@ trait BootstrapWidgetTrait
* For example, [this page](http://getbootstrap.com/javascript/#modals) shows * For example, [this page](http://getbootstrap.com/javascript/#modals) shows
* how to use the "Modal" plugin and the supported options (e.g. "remote"). * how to use the "Modal" plugin and the supported options (e.g. "remote").
*/ */
public array $clientOptions = []; public $clientOptions = [];
/** /**
* @var array the event handlers for the underlying Bootstrap JS plugin. * @var array the event handlers for the underlying Bootstrap JS plugin.
* Please refer to the corresponding Bootstrap plugin Web page for possible events. * Please refer to the corresponding Bootstrap plugin Web page for possible events.
* For example, [this page](http://getbootstrap.com/javascript/#modals) shows * For example, [this page](http://getbootstrap.com/javascript/#modals) shows
* how to use the "Modal" plugin and the supported events (e.g. "shown"). * how to use the "Modal" plugin and the supported events (e.g. "shown").
*/ */
public array $clientEvents = []; public $clientEvents = [];
/** /**

View File

@ -7,7 +7,6 @@
namespace yii\bootstrap5; namespace yii\bootstrap5;
use JsonException;
use RuntimeException; use RuntimeException;
use Yii; use Yii;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -33,18 +32,18 @@ class Breadcrumbs extends Widget
/** /**
* @var string the name of the breadcrumb container tag. * @var string the name of the breadcrumb container tag.
*/ */
public string $tag = 'ol'; public $tag = 'ol';
/** /**
* @var bool whether to HTML-encode the link labels. * @var bool whether to HTML-encode the link labels.
*/ */
public bool $encodeLabels = true; public $encodeLabels = true;
/** /**
* @var array the first hyperlink in the breadcrumbs (called home link). * @var array the first hyperlink in the breadcrumbs (called home link).
* Please refer to [[links]] on the format of the link. * Please refer to [[links]] on the format of the link.
* If this property is not set, it will default to a link pointing to [[\yii\web\Application::homeUrl]] * If this property is not set, it will default to a link pointing to [[\yii\web\Application::homeUrl]]
* with the label 'Home'. If this property is false, the home link will not be rendered. * with the label 'Home'. If this property is false, the home link will not be rendered.
*/ */
public array $homeLink = []; public $homeLink = [];
/** /**
* @var array list of links to appear in the breadcrumbs. If this property is empty, * @var array list of links to appear in the breadcrumbs. If this property is empty,
* the widget will not render anything. Each array element represents a single link in the breadcrumbs * the widget will not render anything. Each array element represents a single link in the breadcrumbs
@ -60,22 +59,22 @@ class Breadcrumbs extends Widget
* *
* *
*/ */
public array $links = []; public $links = [];
/** /**
* @var string the template used to render each inactive item in the breadcrumbs. The token `{link}` * @var string the template used to render each inactive item in the breadcrumbs. The token `{link}`
* will be replaced with the actual HTML link for each inactive item. * will be replaced with the actual HTML link for each inactive item.
*/ */
public string $itemTemplate = "<li class=\"breadcrumb-item\">{link}</li>\n"; public $itemTemplate = "<li class=\"breadcrumb-item\">{link}</li>\n";
/** /**
* @var string the template used to render each active item in the breadcrumbs. The token `{link}` * @var string the template used to render each active item in the breadcrumbs. The token `{link}`
* will be replaced with the actual HTML link for each active item. * will be replaced with the actual HTML link for each active item.
*/ */
public string $activeItemTemplate = "<li class=\"breadcrumb-item active\" aria-current=\"page\">{link}</li>\n"; public $activeItemTemplate = "<li class=\"breadcrumb-item active\" aria-current=\"page\">{link}</li>\n";
/** /**
* @var array the HTML attributes for the widgets nav container tag. * @var array the HTML attributes for the widgets nav container tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $navOptions = ['aria-label' => 'breadcrumb']; public $navOptions = ['aria-label' => 'breadcrumb'];
/** /**
@ -127,42 +126,6 @@ class Breadcrumbs extends Widget
return Html::tag('nav', Html::tag($this->tag, implode('', $links), $this->options), $this->navOptions); return Html::tag('nav', Html::tag($this->tag, implode('', $links), $this->options), $this->navOptions);
} }
/**
* Renders a single breadcrumb item.
*
* @param array $link the link to be rendered. It must contain the "label" element. The "url" element is optional.
* @param string $template the template to be used to rendered the link. The token "{link}" will be replaced by the
* link.
*
* @throws RuntimeException if `$link` does not have "label" element.
*
* @return string the rendering result
*/
protected function renderItem(array $link, string $template): string
{
$encodeLabel = ArrayHelper::remove($link, 'encode', $this->encodeLabels);
if (array_key_exists('label', $link)) {
$label = $encodeLabel ? Html::encode($link['label']) : $link['label'];
} else {
throw new RuntimeException('The "label" element is required for each link.');
}
if (isset($link['template'])) {
$template = $link['template'];
}
if (isset($link['url'])) {
$options = $link;
unset($options['template'], $options['label'], $options['url']);
$linkHtml = Html::a($label, $link['url'], $options);
} else {
$linkHtml = $label;
}
return strtr($template, ['{link}' => $linkHtml]);
}
/** /**
* The template used to render each active item in the breadcrumbs. The token `{link}` will be replaced with the * The template used to render each active item in the breadcrumbs. The token `{link}` will be replaced with the
* actual HTML link for each active item. * actual HTML link for each active item.
@ -295,4 +258,40 @@ class Breadcrumbs extends Widget
return $this; return $this;
} }
/**
* Renders a single breadcrumb item.
*
* @param array $link the link to be rendered. It must contain the "label" element. The "url" element is optional.
* @param string $template the template to be used to rendered the link. The token "{link}" will be replaced by the
* link.
*
* @return string the rendering result
* @throws RuntimeException if `$link` does not have "label" element.
*
*/
protected function renderItem(array $link, string $template): string
{
$encodeLabel = ArrayHelper::remove($link, 'encode', $this->encodeLabels);
if (array_key_exists('label', $link)) {
$label = $encodeLabel ? Html::encode($link['label']) : $link['label'];
} else {
throw new RuntimeException('The "label" element is required for each link.');
}
if (isset($link['template'])) {
$template = $link['template'];
}
if (isset($link['url'])) {
$options = $link;
unset($options['template'], $options['label'], $options['url']);
$linkHtml = Html::a($label, $link['url'], $options);
} else {
$linkHtml = $label;
}
return strtr($template, ['{link}' => $linkHtml]);
}
} }

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use yii\base\InvalidConfigException;
/** /**
* Button renders a bootstrap button. * Button renders a bootstrap button.
* *
@ -23,21 +25,21 @@ class Button extends Widget
/** /**
* @var string the tag to use to render the button * @var string the tag to use to render the button
*/ */
public string $tagName = 'button'; public $tagName = 'button';
/** /**
* @var string the button label * @var string the button label
*/ */
public string $label = 'Button'; public $label = 'Button';
/** /**
* @var bool whether the label should be HTML-encoded. * @var bool whether the label should be HTML-encoded.
*/ */
public bool $encodeLabel = true; public $encodeLabel = true;
/** /**
* Initializes the widget. * Initializes the widget.
* If you override this method, make sure you call the parent implementation first. * If you override this method, make sure you call the parent implementation first.
* @throws \yii\base\InvalidConfigException * @throws InvalidConfigException
*/ */
public function init() public function init()
{ {

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use Throwable;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\helpers\Url; use yii\helpers\Url;
@ -50,7 +51,7 @@ class ButtonDropdown extends Widget
/** /**
* @var string the button label * @var string the button label
*/ */
public string $label = 'Button'; public $label = 'Button';
/** /**
* @var array the HTML attributes for the container tag. The following special options are recognized: * @var array the HTML attributes for the container tag. The following special options are recognized:
* *
@ -58,43 +59,43 @@ class ButtonDropdown extends Widget
* *
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $options = []; public $options = [];
/** /**
* @var array the HTML attributes of the button. * @var array the HTML attributes of the button.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $buttonOptions = []; public $buttonOptions = [];
/** /**
* @var array the configuration array for [[Dropdown]]. * @var array the configuration array for [[Dropdown]].
*/ */
public array $dropdown = []; public $dropdown = [];
/** /**
* @var string the drop-direction of the widget * @var string the drop-direction of the widget
* *
* Possible values are 'left', 'right', 'up', or 'down' (default) * Possible values are 'left', 'right', 'up', or 'down' (default)
*/ */
public string $direction = self::DIRECTION_DOWN; public $direction = self::DIRECTION_DOWN;
/** /**
* @var bool whether to display a group of split-styled button group. * @var bool whether to display a group of split-styled button group.
*/ */
public bool $split = false; public $split = false;
/** /**
* @var string the tag to use to render the button * @var string the tag to use to render the button
*/ */
public string $tagName = 'button'; public $tagName = 'button';
/** /**
* @var bool whether the label should be HTML-encoded. * @var bool whether the label should be HTML-encoded.
*/ */
public bool $encodeLabel = true; public $encodeLabel = true;
/** /**
* @var string name of a class to use for rendering dropdowns withing this widget. Defaults to [[Dropdown]]. * @var string name of a class to use for rendering dropdowns withing this widget. Defaults to [[Dropdown]].
*/ */
public string $dropdownClass = Dropdown::class; public $dropdownClass = Dropdown::class;
/** /**
* @var bool whether to render the container using the [[options]] as HTML attributes. If set to `false`, * @var bool whether to render the container using the [[options]] as HTML attributes. If set to `false`,
* the container element enclosing the button and dropdown will NOT be rendered. * the container element enclosing the button and dropdown will NOT be rendered.
*/ */
public bool $renderContainer = true; public $renderContainer = true;
/** /**
@ -112,7 +113,7 @@ class ButtonDropdown extends Widget
/** /**
* {@inheritdoc} * {@inheritdoc}
* @return string * @return string
* @throws \Throwable * @throws Throwable
*/ */
public function run(): string public function run(): string
{ {
@ -129,13 +130,14 @@ class ButtonDropdown extends Widget
$this->options['id'] = $this->buttonOptions['id']; $this->options['id'] = $this->buttonOptions['id'];
$this->registerPlugin('dropdown'); $this->registerPlugin('dropdown');
return $html; return $html;
} }
/** /**
* Generates the button dropdown. * Generates the button dropdown.
* @return string the rendering result. * @return string the rendering result.
* @throws \Throwable * @throws Throwable
*/ */
protected function renderButton(): string protected function renderButton(): string
{ {
@ -188,7 +190,7 @@ class ButtonDropdown extends Widget
/** /**
* Generates the dropdown menu. * Generates the dropdown menu.
* @return string the rendering result. * @return string the rendering result.
* @throws \Throwable * @throws Throwable
*/ */
protected function renderDropdown(): string protected function renderDropdown(): string
{ {
@ -197,6 +199,7 @@ class ButtonDropdown extends Widget
$config['view'] = $this->getView(); $config['view'] = $this->getView();
/** @var Widget $dropdownClass */ /** @var Widget $dropdownClass */
$dropdownClass = $this->dropdownClass; $dropdownClass = $this->dropdownClass;
return $dropdownClass::widget($config); return $dropdownClass::widget($config);
} }
} }

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use Throwable;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
/** /**
@ -48,11 +49,11 @@ class ButtonGroup extends Widget
* - options: array, optional, the HTML attributes of the button. * - options: array, optional, the HTML attributes of the button.
* - visible: bool, optional, whether this button is visible. Defaults to true. * - visible: bool, optional, whether this button is visible. Defaults to true.
*/ */
public array $buttons = []; public $buttons = [];
/** /**
* @var bool whether to HTML-encode the button labels. * @var bool whether to HTML-encode the button labels.
*/ */
public bool $encodeLabels = true; public $encodeLabels = true;
/** /**
@ -70,18 +71,19 @@ class ButtonGroup extends Widget
/** /**
* {@inheritdoc} * {@inheritdoc}
* @return string * @return string
* @throws \Throwable * @throws Throwable
*/ */
public function run(): string public function run(): string
{ {
BootstrapAsset::register($this->getView()); BootstrapAsset::register($this->getView());
return Html::tag('div', $this->renderButtons(), $this->options); return Html::tag('div', $this->renderButtons(), $this->options);
} }
/** /**
* Generates the buttons that compound the group as specified on [[buttons]]. * Generates the buttons that compound the group as specified on [[buttons]].
* @return string the rendering result. * @return string the rendering result.
* @throws \Throwable * @throws Throwable
*/ */
protected function renderButtons(): string protected function renderButtons(): string
{ {

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use Throwable;
/** /**
* ButtonToolbar Combines sets of button groups into button toolbars for more complex components. * ButtonToolbar Combines sets of button groups into button toolbars for more complex components.
* Use utility classes as needed to space out groups, buttons, and more. * Use utility classes as needed to space out groups, buttons, and more.
@ -57,7 +59,7 @@ class ButtonToolbar extends Widget
* - options: array optional, the HTML attributes of the button group. * - options: array optional, the HTML attributes of the button group.
* - encodeLabels: bool whether to HTML-encode the button labels. * - encodeLabels: bool whether to HTML-encode the button labels.
*/ */
public array $buttonGroups = []; public $buttonGroups = [];
/** /**
@ -75,18 +77,19 @@ class ButtonToolbar extends Widget
/** /**
* {@inheritdoc} * {@inheritdoc}
* @return string * @return string
* @throws \Throwable * @throws Throwable
*/ */
public function run(): string public function run(): string
{ {
BootstrapAsset::register($this->getView()); BootstrapAsset::register($this->getView());
return Html::tag('div', $this->renderButtonGroups(), $this->options); return Html::tag('div', $this->renderButtonGroups(), $this->options);
} }
/** /**
* Generates the button groups that compound the toolbar as specified on [[buttonGroups]]. * Generates the button groups that compound the toolbar as specified on [[buttonGroups]].
* @return string the rendering result. * @return string the rendering result.
* @throws \Throwable * @throws Throwable
*/ */
protected function renderButtonGroups(): string protected function renderButtonGroups(): string
{ {

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use Exception;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -40,7 +41,7 @@ class Carousel extends Widget
* @var array|null the labels for the previous and the next control buttons. * @var array|null the labels for the previous and the next control buttons.
* If null, it means the previous and the next control buttons should not be displayed. * If null, it means the previous and the next control buttons should not be displayed.
*/ */
public ?array $controls = [ public $controls = [
'<span class="carousel-control-prev-icon" aria-hidden="true"></span><span class="visually-hidden">Previous</span>', '<span class="carousel-control-prev-icon" aria-hidden="true"></span><span class="visually-hidden">Previous</span>',
'<span class="carousel-control-next-icon" aria-hidden="true"></span><span class="visually-hidden">Next</span>', '<span class="carousel-control-next-icon" aria-hidden="true"></span><span class="visually-hidden">Next</span>',
]; ];
@ -48,7 +49,7 @@ class Carousel extends Widget
/** /**
* @var bool whether carousel indicators (<ol> tag with anchors to items) should be displayed or not. * @var bool whether carousel indicators (<ol> tag with anchors to items) should be displayed or not.
*/ */
public bool $showIndicators = true; public $showIndicators = true;
/** /**
* @var array list of slides in the carousel. Each array element represents a single * @var array list of slides in the carousel. Each array element represents a single
* slide with the following structure: * slide with the following structure:
@ -64,15 +65,15 @@ class Carousel extends Widget
* ] * ]
* ``` * ```
*/ */
public array $items = []; public $items = [];
/** /**
* @var bool Animate slides with a fade transition instead of a slide. Defaults to `false` * @var bool Animate slides with a fade transition instead of a slide. Defaults to `false`
*/ */
public bool $crossfade = false; public $crossfade = false;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public array $options = ['data-bs-ride' => 'carousel']; public $options = ['data-bs-ride' => 'carousel'];
/** /**
@ -154,7 +155,7 @@ class Carousel extends Widget
* @param int $index the item index as the first item should be set to `active` * @param int $index the item index as the first item should be set to `active`
* @return string the rendering result * @return string the rendering result
* @throws InvalidConfigException if the item is invalid * @throws InvalidConfigException if the item is invalid
* @throws \Exception * @throws Exception
*/ */
public function renderItem($item, int $index): string public function renderItem($item, int $index): string
{ {
@ -186,9 +187,12 @@ class Carousel extends Widget
/** /**
* Renders previous and next control buttons. * Renders previous and next control buttons.
*
* @return string The rendered controls
*
* @throws InvalidConfigException if [[controls]] is invalid. * @throws InvalidConfigException if [[controls]] is invalid.
*/ */
public function renderControls() public function renderControls(): string
{ {
if (isset($this->controls[0], $this->controls[1])) { if (isset($this->controls[0], $this->controls[1])) {
return Html::button($this->controls[0], [ return Html::button($this->controls[0], [

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use Exception;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -51,19 +52,19 @@ class Dropdown extends Widget
* *
* To insert divider use `-`. * To insert divider use `-`.
*/ */
public array $items = []; public $items = [];
/** /**
* @var bool whether the labels for header items should be HTML-encoded. * @var bool whether the labels for header items should be HTML-encoded.
*/ */
public bool $encodeLabels = true; public $encodeLabels = true;
/** /**
* @var array|null the HTML attributes for sub-menu container tags. * @var array|null the HTML attributes for sub-menu container tags.
*/ */
public ?array $submenuOptions = []; public $submenuOptions = [];
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
public function init() public function init()
{ {
@ -80,6 +81,7 @@ class Dropdown extends Widget
{ {
BootstrapPluginAsset::register($this->getView()); BootstrapPluginAsset::register($this->getView());
$this->registerClientEvents(); $this->registerClientEvents();
return $this->renderItems($this->items, $this->options); return $this->renderItems($this->items, $this->options);
} }
@ -89,7 +91,7 @@ class Dropdown extends Widget
* @param array $options the container HTML attributes * @param array $options the container HTML attributes
* @return string the rendering result. * @return string the rendering result.
* @throws InvalidConfigException if the label option is not specified in one of the items. * @throws InvalidConfigException if the label option is not specified in one of the items.
* @throws \Exception * @throws Exception
*/ */
protected function renderItems(array $items, array $options = []): string protected function renderItems(array $items, array $options = []): string
{ {

View File

@ -37,54 +37,54 @@ class LinkPager extends Widget
* @var Pagination the pagination object that this pager is associated with. * @var Pagination the pagination object that this pager is associated with.
* You must set this property in order to make LinkPager work. * You must set this property in order to make LinkPager work.
*/ */
public Pagination $pagination; public $pagination;
/** /**
* @var array HTML attributes for the pager container tag. * @var array HTML attributes for the pager container tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $options = []; public $options = [];
/** /**
* @var array HTML attributes for the pager list tag. * @var array HTML attributes for the pager list tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $listOptions = ['class' => ['pagination']]; public $listOptions = ['class' => ['pagination']];
/** /**
* @var array HTML attributes which will be applied to all link containers * @var array HTML attributes which will be applied to all link containers
*/ */
public array $linkContainerOptions = ['class' => ['page-item']]; public $linkContainerOptions = ['class' => ['page-item']];
/** /**
* @var array HTML attributes for the link in a pager container tag. * @var array HTML attributes for the link in a pager container tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $linkOptions = ['class' => ['page-link']]; public $linkOptions = ['class' => ['page-link']];
/** /**
* @var string the CSS class for the each page button. * @var string the CSS class for the each page button.
*/ */
public string $pageCssClass = 'page-item'; public $pageCssClass = 'page-item';
/** /**
* @var string the CSS class for the "first" page button. * @var string the CSS class for the "first" page button.
*/ */
public string $firstPageCssClass = 'first'; public $firstPageCssClass = 'first';
/** /**
* @var string the CSS class for the "last" page button. * @var string the CSS class for the "last" page button.
*/ */
public string $lastPageCssClass = 'last'; public $lastPageCssClass = 'last';
/** /**
* @var string the CSS class for the "previous" page button. * @var string the CSS class for the "previous" page button.
*/ */
public string $prevPageCssClass = 'prev'; public $prevPageCssClass = 'prev';
/** /**
* @var string the CSS class for the "next" page button. * @var string the CSS class for the "next" page button.
*/ */
public string $nextPageCssClass = 'next'; public $nextPageCssClass = 'next';
/** /**
* @var string the CSS class for the active (currently selected) page button. * @var string the CSS class for the active (currently selected) page button.
*/ */
public string $activePageCssClass = 'active'; public $activePageCssClass = 'active';
/** /**
* @var string the CSS class for the disabled page buttons. * @var string the CSS class for the disabled page buttons.
*/ */
public string $disabledPageCssClass = 'disabled'; public $disabledPageCssClass = 'disabled';
/** /**
* @var array the options for the disabled tag to be generated inside the disabled list element. * @var array the options for the disabled tag to be generated inside the disabled list element.
* In order to customize the html tag, please use the tag key. * In order to customize the html tag, please use the tag key.
@ -93,11 +93,11 @@ class LinkPager extends Widget
* $disabledListItemSubTagOptions = ['class' => 'disabled-link']; * $disabledListItemSubTagOptions = ['class' => 'disabled-link'];
* ``` * ```
*/ */
public array $disabledListItemSubTagOptions = []; public $disabledListItemSubTagOptions = [];
/** /**
* @var int maximum number of page buttons that can be displayed. Defaults to 10. * @var int maximum number of page buttons that can be displayed. Defaults to 10.
*/ */
public int $maxButtonCount = 10; public $maxButtonCount = 10;
/** /**
* @var string|bool the label for the "next" page button. Note that this will NOT be HTML-encoded. * @var string|bool the label for the "next" page button. Note that this will NOT be HTML-encoded.
* If this property is false, the "next" page button will not be displayed. * If this property is false, the "next" page button will not be displayed.
@ -126,15 +126,15 @@ class LinkPager extends Widget
* @see http://www.w3.org/TR/html401/struct/links.html#h-12.1.2 * @see http://www.w3.org/TR/html401/struct/links.html#h-12.1.2
* @see registerLinkTags() * @see registerLinkTags()
*/ */
public bool $registerLinkTags = false; public $registerLinkTags = false;
/** /**
* @var bool Hide widget when only one page exist. * @var bool Hide widget when only one page exist.
*/ */
public bool $hideOnSinglePage = true; public $hideOnSinglePage = true;
/** /**
* @var bool whether to render current page button as disabled. * @var bool whether to render current page button as disabled.
*/ */
public bool $disableCurrentPageButton = false; public $disableCurrentPageButton = false;
/** /**
@ -223,7 +223,7 @@ class LinkPager extends Widget
} }
// internal pages // internal pages
[$beginPage, $endPage] = $this->getPageRange(); list($beginPage, $endPage) = $this->getPageRange();
for ($i = $beginPage; $i <= $endPage; ++$i) { for ($i = $beginPage; $i <= $endPage; ++$i) {
$buttons[] = $this->renderPageButton( $buttons[] = $this->renderPageButton(
(string)($i + 1), (string)($i + 1),
@ -262,6 +262,7 @@ class LinkPager extends Widget
$options = $this->listOptions; $options = $this->listOptions;
$tag = ArrayHelper::remove($options, 'tag', 'ul'); $tag = ArrayHelper::remove($options, 'tag', 'ul');
return Html::tag($tag, implode("\n", $buttons), $options); return Html::tag($tag, implode("\n", $buttons), $options);
} }

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
/** /**
@ -51,35 +52,35 @@ class Modal extends Widget
/** /**
* @var string the tile content in the modal window. * @var string the tile content in the modal window.
*/ */
public string $title; public $title;
/** /**
* @var array additional title options * @var array additional title options
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $titleOptions = []; public $titleOptions = [];
/** /**
* @var array additional header options * @var array additional header options
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $headerOptions = []; public $headerOptions = [];
/** /**
* @var array body options * @var array body options
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $bodyOptions = []; public $bodyOptions = [];
/** /**
* @var string|null the footer content in the modal window. * @var string|null the footer content in the modal window.
*/ */
public ?string $footer; public $footer;
/** /**
* @var array additional footer options * @var array additional footer options
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $footerOptions = []; public $footerOptions = [];
/** /**
* @var string|null the modal size. Can be [[SIZE_LARGE]] or [[SIZE_SMALL]], or empty for default. * @var string|null the modal size. Can be [[SIZE_LARGE]] or [[SIZE_SMALL]], or empty for default.
*/ */
public ?string $size; public $size;
/** /**
* @var array|false the options for rendering the close button tag. * @var array|false the options for rendering the close button tag.
* The close button is displayed in the header of the modal window. Clicking * The close button is displayed in the header of the modal window. Clicking
@ -116,25 +117,25 @@ class Modal extends Widget
* When true the modal-dialog-centered class will be added to the modal-dialog * When true the modal-dialog-centered class will be added to the modal-dialog
* @since 2.0.9 * @since 2.0.9
*/ */
public bool $centerVertical = false; public $centerVertical = false;
/** /**
* @var boolean whether to make the modal body scrollable * @var boolean whether to make the modal body scrollable
* *
* When true the modal-dialog-scrollable class will be added to the modal-dialog * When true the modal-dialog-scrollable class will be added to the modal-dialog
* @since 2.0.9 * @since 2.0.9
*/ */
public bool $scrollable = false; public $scrollable = false;
/** /**
* @var array modal dialog options * @var array modal dialog options
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @since 2.0.9 * @since 2.0.9
*/ */
public array $dialogOptions = []; public $dialogOptions = [];
/** /**
* {@inheritDoc} * {@inheritDoc}
* @throws \yii\base\InvalidConfigException * @throws InvalidConfigException
*/ */
public function init() public function init()
{ {
@ -184,6 +185,7 @@ class Modal extends Widget
return ''; return '';
} }
Html::addCssClass($this->headerOptions, ['widget' => 'modal-header']); Html::addCssClass($this->headerOptions, ['widget' => 'modal-header']);
return Html::tag('div', "\n" . $header . "\n", $this->headerOptions); return Html::tag('div', "\n" . $header . "\n", $this->headerOptions);
} }
@ -194,6 +196,7 @@ class Modal extends Widget
protected function renderBodyBegin(): string protected function renderBodyBegin(): string
{ {
Html::addCssClass($this->bodyOptions, ['widget' => 'modal-body']); Html::addCssClass($this->bodyOptions, ['widget' => 'modal-body']);
return Html::beginTag('div', $this->bodyOptions); return Html::beginTag('div', $this->bodyOptions);
} }
@ -208,12 +211,13 @@ class Modal extends Widget
/** /**
* Renders the HTML markup for the footer of the modal * Renders the HTML markup for the footer of the modal
* @return string the rendering result * @return string|null the rendering result
*/ */
protected function renderFooter(): ?string protected function renderFooter()
{ {
if (isset($this->footer)) { if (isset($this->footer)) {
Html::addCssClass($this->footerOptions, ['widget' => 'modal-footer']); Html::addCssClass($this->footerOptions, ['widget' => 'modal-footer']);
return Html::tag('div', "\n" . $this->footer . "\n", $this->footerOptions); return Html::tag('div', "\n" . $this->footer . "\n", $this->footerOptions);
} else { } else {
return null; return null;
@ -222,9 +226,9 @@ class Modal extends Widget
/** /**
* Renders the toggle button. * Renders the toggle button.
* @return string the rendering result * @return string|null the rendering result
*/ */
protected function renderToggleButton(): ?string protected function renderToggleButton()
{ {
if (($toggleButton = $this->toggleButton) !== false) { if (($toggleButton = $this->toggleButton) !== false) {
$tag = ArrayHelper::remove($toggleButton, 'tag', 'button'); $tag = ArrayHelper::remove($toggleButton, 'tag', 'button');
@ -238,9 +242,9 @@ class Modal extends Widget
/** /**
* Renders the close button. * Renders the close button.
* @return string the rendering result * @return string|null the rendering result
*/ */
protected function renderCloseButton(): ?string protected function renderCloseButton()
{ {
if (($closeButton = $this->closeButton) !== false) { if (($closeButton = $this->closeButton) !== false) {
$tag = ArrayHelper::remove($closeButton, 'tag', 'button'); $tag = ArrayHelper::remove($closeButton, 'tag', 'button');

View File

@ -4,9 +4,11 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use Exception;
use Throwable;
use Yii;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use Yii;
/** /**
* Nav renders a nav HTML component. * Nav renders a nav HTML component.
@ -67,39 +69,39 @@ class Nav extends Widget
* *
* If a menu item is a string, it will be rendered directly without HTML encoding. * If a menu item is a string, it will be rendered directly without HTML encoding.
*/ */
public array $items = []; public $items = [];
/** /**
* @var bool whether the nav items labels should be HTML-encoded. * @var bool whether the nav items labels should be HTML-encoded.
*/ */
public bool $encodeLabels = true; public $encodeLabels = true;
/** /**
* @var bool whether to automatically activate items according to whether their route setting * @var bool whether to automatically activate items according to whether their route setting
* matches the currently requested route. * matches the currently requested route.
* @see isItemActive * @see isItemActive
*/ */
public bool $activateItems = true; public $activateItems = true;
/** /**
* @var bool whether to activate parent menu items when one of the corresponding child menu items is active. * @var bool whether to activate parent menu items when one of the corresponding child menu items is active.
*/ */
public bool $activateParents = false; public $activateParents = false;
/** /**
* @var string|null the route used to determine if a menu item is active or not. * @var string|null the route used to determine if a menu item is active or not.
* If not set, it will use the route of the current request. * If not set, it will use the route of the current request.
* @see params * @see params
* @see isItemActive * @see isItemActive
*/ */
public ?string $route = null; public $route = null;
/** /**
* @var array|null the parameters used to determine if a menu item is active or not. * @var array|null the parameters used to determine if a menu item is active or not.
* If not set, it will use `$_GET`. * If not set, it will use `$_GET`.
* @see route * @see route
* @see isItemActive * @see isItemActive
*/ */
public ?array $params = null; public $params = null;
/** /**
* @var string name of a class to use for rendering dropdowns within this widget. Defaults to [[Dropdown]]. * @var string name of a class to use for rendering dropdowns within this widget. Defaults to [[Dropdown]].
*/ */
public string $dropdownClass = Dropdown::class; public $dropdownClass = Dropdown::class;
/** /**
@ -120,18 +122,19 @@ class Nav extends Widget
/** /**
* Renders the widget. * Renders the widget.
* @return string * @return string
* @throws InvalidConfigException|\Throwable * @throws InvalidConfigException|Throwable
*/ */
public function run(): string public function run(): string
{ {
BootstrapAsset::register($this->getView()); BootstrapAsset::register($this->getView());
return $this->renderItems(); return $this->renderItems();
} }
/** /**
* Renders widget items. * Renders widget items.
* @return string * @return string
* @throws InvalidConfigException|\Throwable * @throws InvalidConfigException|Throwable
*/ */
public function renderItems(): string public function renderItems(): string
{ {
@ -151,7 +154,7 @@ class Nav extends Widget
* @param string|array $item the item to render. * @param string|array $item the item to render.
* @return string the rendering result. * @return string the rendering result.
* @throws InvalidConfigException * @throws InvalidConfigException
* @throws \Throwable * @throws Throwable
*/ */
public function renderItem($item): string public function renderItem($item): string
{ {
@ -203,12 +206,13 @@ class Nav extends Widget
* @param array $items the given items. Please refer to [[Dropdown::items]] for the array structure. * @param array $items the given items. Please refer to [[Dropdown::items]] for the array structure.
* @param array $parentItem the parent item information. Please refer to [[items]] for the structure of this array. * @param array $parentItem the parent item information. Please refer to [[items]] for the structure of this array.
* @return string the rendering result. * @return string the rendering result.
* @throws \Throwable * @throws Throwable
*/ */
protected function renderDropdown(array $items, array $parentItem): string protected function renderDropdown(array $items, array $parentItem): string
{ {
/** @var Widget $dropdownClass */ /** @var Widget $dropdownClass */
$dropdownClass = $this->dropdownClass; $dropdownClass = $this->dropdownClass;
return $dropdownClass::widget([ return $dropdownClass::widget([
'options' => ArrayHelper::getValue($parentItem, 'dropdownOptions', []), 'options' => ArrayHelper::getValue($parentItem, 'dropdownOptions', []),
'items' => $items, 'items' => $items,
@ -223,8 +227,8 @@ class Nav extends Widget
* @param array $items @see items * @param array $items @see items
* @param bool $active should the parent be active too * @param bool $active should the parent be active too
* @return array * @return array
* @throws Exception
* @see items * @see items
* @throws \Exception
*/ */
protected function isChildActive(array $items, bool &$active): array protected function isChildActive(array $items, bool &$active): array
{ {
@ -248,6 +252,7 @@ class Nav extends Widget
} }
} }
} }
return $items; return $items;
} }
@ -260,7 +265,7 @@ class Nav extends Widget
* be considered active. * be considered active.
* @param array $item the menu item to be checked * @param array $item the menu item to be checked
* @return bool whether the menu item is active * @return bool whether the menu item is active
* @throws \Exception * @throws Exception
*/ */
protected function isItemActive(array $item): bool protected function isItemActive(array $item): bool
{ {

View File

@ -47,7 +47,7 @@ class NavBar extends Widget
* *
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $options = []; public $options = [];
/** /**
* @var array the HTML attributes for the container tag. The following special options are recognized: * @var array the HTML attributes for the container tag. The following special options are recognized:
* *
@ -55,7 +55,7 @@ class NavBar extends Widget
* *
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $collapseOptions = []; public $collapseOptions = [];
/** /**
* @var string|bool the text of the brand or false if it's not used. Note that this is not HTML-encoded. * @var string|bool the text of the brand or false if it's not used. Note that this is not HTML-encoded.
* @see https://getbootstrap.com/docs/5.0/components/navbar/ * @see https://getbootstrap.com/docs/5.0/components/navbar/
@ -78,34 +78,34 @@ class NavBar extends Widget
* @var array the HTML attributes of the brand link. * @var array the HTML attributes of the brand link.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $brandOptions = []; public $brandOptions = [];
/** /**
* @var string text to show for screen readers for the button to toggle the navbar. * @var string text to show for screen readers for the button to toggle the navbar.
*/ */
public string $screenReaderToggleText = 'Toggle navigation'; public $screenReaderToggleText = 'Toggle navigation';
/** /**
* @var string the toggle button content. Defaults to bootstrap 5 default `<span class="navbar-toggler-icon"></span>` * @var string the toggle button content. Defaults to bootstrap 5 default `<span class="navbar-toggler-icon"></span>`
*/ */
public string $togglerContent = '<span class="navbar-toggler-icon"></span>'; public $togglerContent = '<span class="navbar-toggler-icon"></span>';
/** /**
* @var array the HTML attributes of the navbar toggler button. * @var array the HTML attributes of the navbar toggler button.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $togglerOptions = []; public $togglerOptions = [];
/** /**
* @var bool whether the navbar content should be included in an inner div container which by default * @var bool whether the navbar content should be included in an inner div container which by default
* adds left and right padding. Set this to false for a 100% width navbar. * adds left and right padding. Set this to false for a 100% width navbar.
*/ */
public bool $renderInnerContainer = true; public $renderInnerContainer = true;
/** /**
* @var array the HTML attributes of the inner container. * @var array the HTML attributes of the inner container.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $innerContainerOptions = []; public $innerContainerOptions = [];
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public array $clientOptions = []; public $clientOptions = [];
/** /**

View File

@ -44,27 +44,27 @@ class Popover extends Widget
/** /**
* @var string|null the tile content in the popover. * @var string|null the tile content in the popover.
*/ */
public ?string $title = null; public $title = null;
/** /**
* @var array additional header options * @var array additional header options
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $headerOptions = []; public $headerOptions = [];
/** /**
* @var array body options * @var array body options
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $bodyOptions = []; public $bodyOptions = [];
/** /**
* @var array arrow options * @var array arrow options
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $arrowOptions = []; public $arrowOptions = [];
/** /**
* @var string How to position the popover - [[PLACEMENT_AUTO]] | [[PLACEMENT_TOP]] | [[PLACEMENT_BOTTOM]] | * @var string How to position the popover - [[PLACEMENT_AUTO]] | [[PLACEMENT_TOP]] | [[PLACEMENT_BOTTOM]] |
* [[PLACEMENT_LEFT]] | [[PLACEMENT_RIGHT]]. When auto is specified, it will dynamically reorient the popover. * [[PLACEMENT_LEFT]] | [[PLACEMENT_RIGHT]]. When auto is specified, it will dynamically reorient the popover.
*/ */
public string $placement = self::PLACEMENT_AUTO; public $placement = self::PLACEMENT_AUTO;
/** /**
* @var array|false the options for rendering the toggle button tag. * @var array|false the options for rendering the toggle button tag.
* The toggle button is used to toggle the visibility of the popover. * The toggle button is used to toggle the visibility of the popover.
@ -96,7 +96,7 @@ class Popover extends Widget
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function run(): ?string public function run()
{ {
$content = ob_get_clean(); $content = ob_get_clean();
@ -117,6 +117,7 @@ class Popover extends Widget
protected function renderArrow(): string protected function renderArrow(): string
{ {
Html::addCssClass($this->arrowOptions, ['widget' => 'popover-arrow']); Html::addCssClass($this->arrowOptions, ['widget' => 'popover-arrow']);
return Html::tag('div', '', $this->arrowOptions); return Html::tag('div', '', $this->arrowOptions);
} }
@ -127,6 +128,7 @@ class Popover extends Widget
protected function renderHeader(): string protected function renderHeader(): string
{ {
Html::addCssClass($this->headerOptions, ['widget' => 'popover-header']); Html::addCssClass($this->headerOptions, ['widget' => 'popover-header']);
return Html::tag('h3', '', $this->headerOptions); return Html::tag('h3', '', $this->headerOptions);
} }
@ -137,14 +139,15 @@ class Popover extends Widget
protected function renderBody(): string protected function renderBody(): string
{ {
Html::addCssClass($this->bodyOptions, ['widget' => 'popover-body']); Html::addCssClass($this->bodyOptions, ['widget' => 'popover-body']);
return Html::tag('div', '', $this->bodyOptions); return Html::tag('div', '', $this->bodyOptions);
} }
/** /**
* Renders the toggle button. * Renders the toggle button.
* @return string the rendering result * @return string|null the rendering result
*/ */
protected function renderToggleButton(): ?string protected function renderToggleButton()
{ {
if (($toggleButton = $this->toggleButton) !== false) { if (($toggleButton = $this->toggleButton) !== false) {
$tag = ArrayHelper::remove($toggleButton, 'tag', 'button'); $tag = ArrayHelper::remove($toggleButton, 'tag', 'button');

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use Exception;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -80,17 +81,17 @@ class Progress extends Widget
/** /**
* @var string the button label. This property will only be considered if [[bars]] is empty * @var string the button label. This property will only be considered if [[bars]] is empty
*/ */
public string $label; public $label;
/** /**
* @var int the amount of progress as a percentage. This property will only be considered if [[bars]] is empty * @var int the amount of progress as a percentage. This property will only be considered if [[bars]] is empty
*/ */
public int $percent = 0; public $percent = 0;
/** /**
* @var array the HTML attributes of the bar. This property will only be considered if [[bars]] is empty * @var array the HTML attributes of the bar. This property will only be considered if [[bars]] is empty
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
* @since 2.0.6 * @since 2.0.6
*/ */
public array $barOptions = []; public $barOptions = [];
/** /**
* @var array a set of bars that are stacked together to form a single progress bar. * @var array a set of bars that are stacked together to form a single progress bar.
* Each bar is an array of the following structure: * Each bar is an array of the following structure:
@ -106,7 +107,7 @@ class Progress extends Widget
* ] * ]
* ``` * ```
*/ */
public array $bars; public $bars;
/** /**
@ -126,6 +127,7 @@ class Progress extends Widget
public function run(): string public function run(): string
{ {
BootstrapAsset::register($this->getView()); BootstrapAsset::register($this->getView());
return $this->renderProgress(); return $this->renderProgress();
} }
@ -133,7 +135,7 @@ class Progress extends Widget
* Renders the progress. * Renders the progress.
* @return string the rendering result. * @return string the rendering result.
* @throws InvalidConfigException if the "percent" option is not set in a stacked progress bar. * @throws InvalidConfigException if the "percent" option is not set in a stacked progress bar.
* @throws \Exception * @throws Exception
*/ */
protected function renderProgress(): string protected function renderProgress(): string
{ {

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use Exception;
use Throwable;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -81,7 +83,7 @@ class Tabs extends Widget
* * content: string, required if `items` is not set. The content (HTML) of the tab pane. * * content: string, required if `items` is not set. The content (HTML) of the tab pane.
* * options: optional, array, the HTML attributes of the tab content container. * * options: optional, array, the HTML attributes of the tab content container.
*/ */
public array $items = []; public $items = [];
/** /**
* @var array list of HTML attributes for the item container tags. This will be overwritten * @var array list of HTML attributes for the item container tags. This will be overwritten
* by the "options" set in individual [[items]]. The following special options are recognized: * by the "options" set in individual [[items]]. The following special options are recognized:
@ -90,46 +92,46 @@ class Tabs extends Widget
* *
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $itemOptions = []; public $itemOptions = [];
/** /**
* @var array list of HTML attributes for the header container tags. This will be overwritten * @var array list of HTML attributes for the header container tags. This will be overwritten
* by the "headerOptions" set in individual [[items]]. * by the "headerOptions" set in individual [[items]].
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $headerOptions = []; public $headerOptions = [];
/** /**
* @var array list of HTML attributes for the tab header link tags. This will be overwritten * @var array list of HTML attributes for the tab header link tags. This will be overwritten
* by the "linkOptions" set in individual [[items]]. * by the "linkOptions" set in individual [[items]].
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $linkOptions = []; public $linkOptions = [];
/** /**
* @var bool whether the labels for header items should be HTML-encoded. * @var bool whether the labels for header items should be HTML-encoded.
*/ */
public bool $encodeLabels = true; public $encodeLabels = true;
/** /**
* @var string specifies the Bootstrap tab styling. * @var string specifies the Bootstrap tab styling.
*/ */
public string $navType = 'nav-tabs'; public $navType = 'nav-tabs';
/** /**
* @var bool whether to render the `tab-content` container and its content. You may set this property * @var bool whether to render the `tab-content` container and its content. You may set this property
* to be false so that you can manually render `tab-content` yourself in case your tab contents are complex. * to be false so that you can manually render `tab-content` yourself in case your tab contents are complex.
*/ */
public bool $renderTabContent = true; public $renderTabContent = true;
/** /**
* @var array list of HTML attributes for the `tab-content` container. This will always contain the CSS class `tab-content`. * @var array list of HTML attributes for the `tab-content` container. This will always contain the CSS class `tab-content`.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $tabContentOptions = []; public $tabContentOptions = [];
/** /**
* @var string name of a class to use for rendering dropdowns withing this widget. Defaults to [[Dropdown]]. * @var string name of a class to use for rendering dropdowns withing this widget. Defaults to [[Dropdown]].
*/ */
public string $dropdownClass = Dropdown::class; public $dropdownClass = Dropdown::class;
/** /**
* @var array Tab panes (contents) * @var array Tab panes (contents)
*/ */
protected array $panes = []; protected $panes = [];
/** /**
@ -145,12 +147,13 @@ class Tabs extends Widget
/** /**
* {@inheritdoc} * {@inheritdoc}
* @throws InvalidConfigException * @throws InvalidConfigException
* @throws \Throwable * @throws Throwable
*/ */
public function run(): string public function run(): string
{ {
$this->registerPlugin('tab'); $this->registerPlugin('tab');
$this->prepareItems($this->items); $this->prepareItems($this->items);
return Nav::widget([ return Nav::widget([
'dropdownClass' => $this->dropdownClass, 'dropdownClass' => $this->dropdownClass,
'options' => ArrayHelper::merge(['role' => 'tablist'], $this->options), 'options' => ArrayHelper::merge(['role' => 'tablist'], $this->options),
@ -159,13 +162,24 @@ class Tabs extends Widget
]) . $this->renderPanes($this->panes); ]) . $this->renderPanes($this->panes);
} }
/**
* Renders tab panes.
*
* @param array $panes
* @return string the rendering result.
*/
public function renderPanes(array $panes): string
{
return $this->renderTabContent ? "\n" . Html::tag('div', implode("\n", $panes), $this->tabContentOptions) : '';
}
/** /**
* Renders tab items as specified on [[items]]. * Renders tab items as specified on [[items]].
* *
* @param array $items * @param array $items
* @param string $prefix * @param string $prefix
* @throws InvalidConfigException * @throws InvalidConfigException
* @throws \Exception * @throws Exception
*/ */
protected function prepareItems(array &$items, string $prefix = '') protected function prepareItems(array &$items, string $prefix = '')
{ {
@ -219,6 +233,8 @@ class Tabs extends Widget
} }
/** /**
* Check for active tab
*
* @return bool if there's active tab defined * @return bool if there's active tab defined
*/ */
protected function hasActiveTab(): bool protected function hasActiveTab(): bool
@ -237,7 +253,7 @@ class Tabs extends Widget
* *
* This method activates the first tab that is visible and * This method activates the first tab that is visible and
* not explicitly set to inactive (`'active' => false`). * not explicitly set to inactive (`'active' => false`).
* @throws \Exception * @throws Exception
*/ */
protected function activateFirstVisibleTab() protected function activateFirstVisibleTab()
{ {
@ -247,19 +263,9 @@ class Tabs extends Widget
$disabled = ArrayHelper::getValue($item, 'disabled', false); $disabled = ArrayHelper::getValue($item, 'disabled', false);
if ($visible && $active !== false && $disabled !== true) { if ($visible && $active !== false && $disabled !== true) {
$this->items[$i]['active'] = true; $this->items[$i]['active'] = true;
return; return;
} }
} }
} }
/**
* Renders tab panes.
*
* @param array $panes
* @return string the rendering result.
*/
public function renderPanes(array $panes): string
{
return $this->renderTabContent ? "\n" . Html::tag('div', implode("\n", $panes), $this->tabContentOptions) : '';
}
} }

View File

@ -4,6 +4,9 @@ declare(strict_types=1);
namespace yii\bootstrap5; namespace yii\bootstrap5;
use DateInterval;
use DateTime;
use DateTimeInterface;
use Yii; use Yii;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -44,13 +47,13 @@ class Toast extends Widget
* the [[begin()]] and [[end()]] calls of the Toast widget will also be treated * the [[begin()]] and [[end()]] calls of the Toast widget will also be treated
* as the body content, and will be rendered before this. * as the body content, and will be rendered before this.
*/ */
public ?string $body = null; public $body = null;
/** /**
* @var string|null The title content in the toast. * @var string|null The title content in the toast.
*/ */
public ?string $title = null; public $title = null;
/** /**
* @var int|string|\DateTime|\DateTimeInterface|\DateInterval|false The date time the toast message references to. * @var int|string|DateTime|DateTimeInterface|DateInterval|false The date time the toast message references to.
* This will be formatted as relative time (via formatter component). It will be omitted if * This will be formatted as relative time (via formatter component). It will be omitted if
* set to `false` (default). * set to `false` (default).
*/ */
@ -68,7 +71,7 @@ class Toast extends Widget
* Please refer to the [Toast documentation](https://getbootstrap.com/docs/5.0/components/toasts/) * Please refer to the [Toast documentation](https://getbootstrap.com/docs/5.0/components/toasts/)
* for the supported HTML attributes. * for the supported HTML attributes.
*/ */
public array $closeButton = []; public $closeButton = [];
/** /**
* @var array additional title options * @var array additional title options
* *
@ -78,7 +81,7 @@ class Toast extends Widget
* *
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $titleOptions = []; public $titleOptions = [];
/** /**
* @var array additional date time part options * @var array additional date time part options
* *
@ -88,17 +91,17 @@ class Toast extends Widget
* *
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $dateTimeOptions = []; public $dateTimeOptions = [];
/** /**
* @var array additional header options * @var array additional header options
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $headerOptions = []; public $headerOptions = [];
/** /**
* @var array body options * @var array body options
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $bodyOptions = []; public $bodyOptions = [];
/** /**
@ -146,6 +149,7 @@ class Toast extends Widget
$title .= "\n" . $button; $title .= "\n" . $button;
Html::addCssClass($this->headerOptions, ['widget' => 'toast-header']); Html::addCssClass($this->headerOptions, ['widget' => 'toast-header']);
return Html::tag('div', "\n" . $title . "\n", $this->headerOptions); return Html::tag('div', "\n" . $title . "\n", $this->headerOptions);
} }
@ -156,6 +160,7 @@ class Toast extends Widget
protected function renderBodyBegin(): string protected function renderBodyBegin(): string
{ {
Html::addCssClass($this->bodyOptions, ['widget' => 'toast-body']); Html::addCssClass($this->bodyOptions, ['widget' => 'toast-body']);
return Html::beginTag('div', $this->bodyOptions); return Html::beginTag('div', $this->bodyOptions);
} }

View File

@ -32,33 +32,33 @@ class ToggleButtonGroup extends InputWidget
/** /**
* Checkbox type * Checkbox type
*/ */
public const TYPE_CHECKBOX = 'checkbox'; const TYPE_CHECKBOX = 'checkbox';
/** /**
* Radio type * Radio type
*/ */
public const TYPE_RADIO = 'radio'; const TYPE_RADIO = 'radio';
/** /**
* @var string input type, can be [[TYPE_CHECKBOX]] or [[TYPE_RADIO]] * @var string input type, can be [[TYPE_CHECKBOX]] or [[TYPE_RADIO]]
*/ */
public string $type; public $type;
/** /**
* @var array the data item used to generate the checkboxes. * @var array the data item used to generate the checkboxes.
* The array values are the labels, while the array keys are the corresponding checkbox or radio values. * The array values are the labels, while the array keys are the corresponding checkbox or radio values.
*/ */
public array $items = []; public $items = [];
/** /**
* @var array, the HTML attributes for the label (button) tag. * @var array, the HTML attributes for the label (button) tag.
* @see Html::checkbox() * @see Html::checkbox()
* @see Html::radio() * @see Html::radio()
*/ */
public array $labelOptions = [ public $labelOptions = [
'class' => ['btn', 'btn-secondary'], 'class' => ['btn', 'btn-secondary'],
]; ];
/** /**
* @var bool whether the items labels should be HTML-encoded. * @var bool whether the items labels should be HTML-encoded.
*/ */
public bool $encodeLabels = true; public $encodeLabels = true;
/** /**
@ -124,6 +124,7 @@ class ToggleButtonGroup extends InputWidget
if ($this->encodeLabels) { if ($this->encodeLabels) {
$label = Html::encode($label); $label = Html::encode($label);
} }
return Html::$type($name, $checked, [ return Html::$type($name, $checked, [
'label' => $label, 'label' => $label,
'labelOptions' => $labelOptions, 'labelOptions' => $labelOptions,

View File

@ -15,5 +15,5 @@ class Widget extends \yii\base\Widget
* @var array the HTML attributes for the widget container tag. * @var array the HTML attributes for the widget container tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/ */
public array $options = []; public $options = [];
} }