Final Class Yiisoft\Yii\Widgets\Dropdown
| Inheritance | Yiisoft\Yii\Widgets\Dropdown » Yiisoft\Widget\Widget |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| activeClass() | Returns a new instance with the specified active class. | Yiisoft\Yii\Widgets\Dropdown |
| container() | Returns a new instance with the specified if the container is enabled, or not. Default is true. | Yiisoft\Yii\Widgets\Dropdown |
| containerAttributes() | Returns a new instance with the specified container HTML attributes. | Yiisoft\Yii\Widgets\Dropdown |
| containerClass() | Returns a new instance with the specified container class. | Yiisoft\Yii\Widgets\Dropdown |
| containerTag() | Returns a new instance with the specified container tag. | Yiisoft\Yii\Widgets\Dropdown |
| disabledClass() | Returns a new instance with the specified disabled class. | Yiisoft\Yii\Widgets\Dropdown |
| dividerAttributes() | Returns a new instance with the specified divider HTML attributes. | Yiisoft\Yii\Widgets\Dropdown |
| dividerClass() | Returns a new instance with the specified divider class. | Yiisoft\Yii\Widgets\Dropdown |
| dividerTag() | Returns a new instance with the specified divider tag. | Yiisoft\Yii\Widgets\Dropdown |
| headerClass() | Returns a new instance with the specified header class. | Yiisoft\Yii\Widgets\Dropdown |
| headerTag() | Returns a new instance with the specified header tag. | Yiisoft\Yii\Widgets\Dropdown |
| id() | Returns a new instance with the specified Widget ID. | Yiisoft\Yii\Widgets\Dropdown |
| itemClass() | Returns a new instance with the specified item class. | Yiisoft\Yii\Widgets\Dropdown |
| itemContainer() | Returns a new instance with the specified item container, if false, the item container will not be rendered. | Yiisoft\Yii\Widgets\Dropdown |
| itemContainerAttributes() | Returns a new instance with the specified item container HTML attributes. | Yiisoft\Yii\Widgets\Dropdown |
| itemContainerClass() | Returns a new instance with the specified item container class. | Yiisoft\Yii\Widgets\Dropdown |
| itemContainerTag() | Returns a new instance with the specified item container tag. | Yiisoft\Yii\Widgets\Dropdown |
| itemTag() | Returns a new instance with the specified item tag. | Yiisoft\Yii\Widgets\Dropdown |
| items() | List of menu items in the dropdown. Each array element can be either an HTML string, or an array representing a single menu with the following structure: | Yiisoft\Yii\Widgets\Dropdown |
| itemsContainerAttributes() | Returns a new instance with the specified items' container HTML attributes. | Yiisoft\Yii\Widgets\Dropdown |
| itemsContainerClass() | Returns a new instance with the specified item container class. | Yiisoft\Yii\Widgets\Dropdown |
| itemsContainerTag() | Returns a new instance with the specified items' container tag. | Yiisoft\Yii\Widgets\Dropdown |
| render() | Yiisoft\Yii\Widgets\Dropdown | |
| splitButtonAttributes() | Returns a new instance with the specified split button attributes. | Yiisoft\Yii\Widgets\Dropdown |
| splitButtonClass() | Returns a new instance with the specified split button class. | Yiisoft\Yii\Widgets\Dropdown |
| splitButtonSpanClass() | Returns a new instance with the specified split button span class. | Yiisoft\Yii\Widgets\Dropdown |
| toggleAttributes() | Returns a new instance with the specified toggle HTML attributes. | Yiisoft\Yii\Widgets\Dropdown |
| toggleClass() | Returns a new instance with the specified toggle class. | Yiisoft\Yii\Widgets\Dropdown |
| toggleType() | Returns a new instance with the specified toggle type, if button the toggle will be a button, otherwise a
a tag will be used. |
Yiisoft\Yii\Widgets\Dropdown |
Method Details
Returns a new instance with the specified active class.
| public self activeClass ( string $value ) | ||
| $value | string |
The active class. |
public function activeClass(string $value): self
{
$new = clone $this;
$new->activeClass = $value;
return $new;
}
Returns a new instance with the specified if the container is enabled, or not. Default is true.
| public self container ( boolean $value ) | ||
| $value | boolean |
The container enabled. |
public function container(bool $value): self
{
$new = clone $this;
$new->container = $value;
return $new;
}
Returns a new instance with the specified container HTML attributes.
| public self containerAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. |
public function containerAttributes(array $valuesMap): self
{
$new = clone $this;
$new->containerAttributes = $valuesMap;
return $new;
}
Returns a new instance with the specified container class.
| public self containerClass ( string $value ) | ||
| $value | string |
The container class. |
public function containerClass(string $value): self
{
$new = clone $this;
$new->containerClass = $value;
return $new;
}
Returns a new instance with the specified container tag.
| public self containerTag ( string $value ) | ||
| $value | string |
The container tag. |
public function containerTag(string $value): self
{
$new = clone $this;
$new->containerTag = $value;
return $new;
}
Returns a new instance with the specified disabled class.
| public self disabledClass ( string $value ) | ||
| $value | string |
The disabled class. |
public function disabledClass(string $value): self
{
$new = clone $this;
$new->disabledClass = $value;
return $new;
}
Returns a new instance with the specified divider HTML attributes.
| public self dividerAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. |
public function dividerAttributes(array $valuesMap): self
{
$new = clone $this;
$new->dividerAttributes = $valuesMap;
return $new;
}
Returns a new instance with the specified divider class.
| public self dividerClass ( string $value ) | ||
| $value | string |
The divider class. |
public function dividerClass(string $value): self
{
$new = clone $this;
$new->dividerClass = $value;
return $new;
}
Returns a new instance with the specified divider tag.
| public self dividerTag ( string $value ) | ||
| $value | string |
The divider tag. |
public function dividerTag(string $value): self
{
$new = clone $this;
$new->dividerTag = $value;
return $new;
}
Returns a new instance with the specified header class.
| public self headerClass ( string $value ) | ||
| $value | string |
The header class. |
public function headerClass(string $value): self
{
$new = clone $this;
$new->headerClass = $value;
return $new;
}
Returns a new instance with the specified header tag.
| public self headerTag ( string $value ) | ||
| $value | string |
The header tag. |
public function headerTag(string $value): self
{
$new = clone $this;
$new->headerTag = $value;
return $new;
}
Returns a new instance with the specified Widget ID.
| public self id ( string $value ) | ||
| $value | string |
The id of the widget. |
public function id(string $value): self
{
$new = clone $this;
$new->id = $value;
return $new;
}
Returns a new instance with the specified item class.
| public self itemClass ( string $value ) | ||
| $value | string |
The item class. |
public function itemClass(string $value): self
{
$new = clone $this;
$new->itemClass = $value;
return $new;
}
Returns a new instance with the specified item container, if false, the item container will not be rendered.
| public self itemContainer ( boolean $value ) | ||
| $value | boolean |
The item container. |
public function itemContainer(bool $value): self
{
$new = clone $this;
$new->itemContainer = $value;
return $new;
}
Returns a new instance with the specified item container HTML attributes.
| public self itemContainerAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. |
public function itemContainerAttributes(array $valuesMap): self
{
$new = clone $this;
$new->itemContainerAttributes = $valuesMap;
return $new;
}
Returns a new instance with the specified item container class.
| public self itemContainerClass ( string $value ) | ||
| $value | string |
The item container class. |
public function itemContainerClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->itemContainerAttributes, $value);
return $new;
}
Returns a new instance with the specified item container tag.
| public self itemContainerTag ( string $value ) | ||
| $value | string |
The item container tag. |
public function itemContainerTag(string $value): self
{
$new = clone $this;
$new->itemContainerTag = $value;
return $new;
}
Returns a new instance with the specified item tag.
| public self itemTag ( string $value ) | ||
| $value | string |
The item tag. |
public function itemTag(string $value): self
{
$new = clone $this;
$new->itemTag = $value;
return $new;
}
List of menu items in the dropdown. Each array element can be either an HTML string, or an array representing a single menu with the following structure:
- label: string, required, the nav item label.
- active: bool, whether the item should be on active state or not.
- disabled: bool, whether the item should be on disabled state or not. For default
disabledis false. - enclose: bool, whether the item should be enclosed by a
<li>tag or not. For defaultencloseis true. - encode: bool, whether the label should be HTML encoded or not. For default
encodeLabelis true. - headerAttributes: array, HTML attributes to be rendered in the item header.
- link: string, the item's href. Defaults to "#". For default
linkis "#". - linkAttributes: array, the HTML attributes of the item's link. For default
linkAttributesis[]. - icon: string, the item's icon. For default
iconis ``. - iconAttributes: array, the HTML attributes of the item's icon. For default
iconAttributesis[]. - visible: bool, optional, whether this menu item is visible. Defaults to true.
- items: array, optional, the submenu items. The structure is the same as this property. Note that Bootstrap doesn't support dropdown submenu. You have to add your own CSS styles to support it.
- itemsContainerAttributes: array, optional, the HTML attributes for tag
<li>.
To insert dropdown divider use -.
| public self items ( array $value ) | ||
| $value | array | |
public function items(array $value): self
{
$new = clone $this;
$new->items = $value;
return $new;
}
Returns a new instance with the specified items' container HTML attributes.
| public self itemsContainerAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. |
public function itemsContainerAttributes(array $valuesMap): self
{
$new = clone $this;
$new->itemsContainerAttributes = $valuesMap;
return $new;
}
Returns a new instance with the specified item container class.
| public self itemsContainerClass ( string $value ) | ||
| $value | string |
The item container class. |
public function itemsContainerClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->itemsContainerAttributes, $value);
return $new;
}
Returns a new instance with the specified items' container tag.
| public self itemsContainerTag ( string $value ) | ||
| $value | string |
The items' container tag. |
public function itemsContainerTag(string $value): self
{
$new = clone $this;
$new->itemsContainerTag = $value;
return $new;
}
| public string render ( ) | ||
| throws | \Yiisoft\Definitions\Exception\CircularReferenceException|\Yiisoft\Definitions\Exception\InvalidConfigException|\Yiisoft\Factory\NotFoundException|\Yiisoft\Definitions\Exception\NotInstantiableException | |
|---|---|---|
public function render(): string
{
/**
* @psalm-var array<
* array-key,
* array{
* label: string,
* link: string,
* linkAttributes: array,
* active: bool,
* disabled: bool,
* enclose: bool,
* headerAttributes: array,
* itemContainerAttributes: array,
* toggleAttributes: array,
* visible: bool,
* items: array,
* }|string
* > $normalizedItems
*/
$normalizedItems = Helper\Normalizer::dropdown($this->items);
$containerAttributes = $this->containerAttributes;
$items = $this->renderItems($normalizedItems) . PHP_EOL;
if (trim($items) === '') {
return '';
}
if ($this->containerClass !== '') {
Html::addCssClass($containerAttributes, $this->containerClass);
}
if ($this->containerTag === '') {
throw new InvalidArgumentException('Tag name must be a string and cannot be empty.');
}
return match ($this->container) {
true => Html::normalTag($this->containerTag, $items, $containerAttributes)->encode(false)->render(),
false => $items,
};
}
Returns a new instance with the specified split button attributes.
| public self splitButtonAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. |
public function splitButtonAttributes(array $valuesMap): self
{
$new = clone $this;
$new->splitButtonAttributes = $valuesMap;
return $new;
}
Returns a new instance with the specified split button class.
| public self splitButtonClass ( string $value ) | ||
| $value | string |
The split button class. |
public function splitButtonClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->splitButtonAttributes, $value);
return $new;
}
Returns a new instance with the specified split button span class.
| public self splitButtonSpanClass ( string $value ) | ||
| $value | string |
The split button span class. |
public function splitButtonSpanClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->splitButtonSpanAttributes, $value);
return $new;
}
Returns a new instance with the specified toggle HTML attributes.
| public self toggleAttributes ( array $valuesMap ) | ||
| $valuesMap | array |
Attribute values indexed by attribute names. |
public function toggleAttributes(array $valuesMap): self
{
$new = clone $this;
$new->toggleAttributes = $valuesMap;
return $new;
}
Returns a new instance with the specified toggle class.
| public self toggleClass ( string $value ) | ||
| $value | string |
The toggle class. |
public function toggleClass(string $value): self
{
$new = clone $this;
Html::addCssClass($new->toggleAttributes, $value);
return $new;
}
Returns a new instance with the specified toggle type, if button the toggle will be a button, otherwise a
a tag will be used.
| public self toggleType ( string $value ) | ||
| $value | string |
The toggle tag. |
public function toggleType(string $value): self
{
$new = clone $this;
$new->toggleType = $value;
return $new;
}
Signup or Login in order to comment.