0 follower

Final Class Yiisoft\Yii\Widgets\Dropdown

InheritanceYiisoft\Yii\Widgets\Dropdown » Yiisoft\Widget\Widget

Public Methods

Hide inherited 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

Hide inherited methods

activeClass() public method

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;
}

            
container() public method

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;
}

            
containerAttributes() public method

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;
}

            
containerClass() public method

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;
}

            
containerTag() public method

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;
}

            
disabledClass() public method

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;
}

            
dividerAttributes() public method

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;
}

            
dividerClass() public method

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;
}

            
dividerTag() public method

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;
}

            
headerClass() public method

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;
}

            
headerTag() public method

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;
}

            
id() public method

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;
}

            
itemClass() public method

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;
}

            
itemContainer() public method

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;
}

            
itemContainerAttributes() public method

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;
}

            
itemContainerClass() public method

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;
}

            
itemContainerTag() public method

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;
}

            
itemTag() public method

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;
}

            
items() public method

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 disabled is false.
  • enclose: bool, whether the item should be enclosed by a <li> tag or not. For default enclose is true.
  • encode: bool, whether the label should be HTML encoded or not. For default encodeLabel is true.
  • headerAttributes: array, HTML attributes to be rendered in the item header.
  • link: string, the item's href. Defaults to "#". For default link is "#".
  • linkAttributes: array, the HTML attributes of the item's link. For default linkAttributes is [].
  • icon: string, the item's icon. For default icon is ``.
  • iconAttributes: array, the HTML attributes of the item's icon. For default iconAttributes is [].
  • 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;
}

            
itemsContainerAttributes() public method

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;
}

            
itemsContainerClass() public method

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;
}

            
itemsContainerTag() public method

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;
}

            
render() public method

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,
    };
}

            
splitButtonAttributes() public method

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;
}

            
splitButtonClass() public method

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;
}

            
splitButtonSpanClass() public method

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;
}

            
toggleAttributes() public method

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;
}

            
toggleClass() public method

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;
}

            
toggleType() public method

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;
}