0 follower

Final Class Yiisoft\Bootstrap5\Breadcrumbs

InheritanceYiisoft\Bootstrap5\Breadcrumbs » Yiisoft\Widget\Widget

Button renders a bootstrap button.

For example,

<?= Breadcrumbs::widget()
        ->links(
            BreadcrumbLink::to('Home', '#'),
            BreadcrumbLink::to('Library', '#'),
            BreadcrumbLink::to('Data', active: true),
        )
        ->listId(false)
?>

See also https://getbootstrap.com/docs/5.3/components/breadcrumb/.

Public Methods

Hide inherited methods

Method Description Defined By
addAttributes() Adds a sets of attributes. Yiisoft\Bootstrap5\Breadcrumbs
addClass() Adds one or more CSS classes to the existing classes. Yiisoft\Bootstrap5\Breadcrumbs
addCssStyle() Adds a CSS style. Yiisoft\Bootstrap5\Breadcrumbs
ariaLabel() Sets the ARIA label. Yiisoft\Bootstrap5\Breadcrumbs
attribute() Adds a sets attribute value. Yiisoft\Bootstrap5\Breadcrumbs
attributes() Sets the HTML attributes. Yiisoft\Bootstrap5\Breadcrumbs
class() Replaces all existing CSS classes with the specified one(s). Yiisoft\Bootstrap5\Breadcrumbs
divider() Sets the divider. Yiisoft\Bootstrap5\Breadcrumbs
itemActiveClass() Sets the active class for the items. Yiisoft\Bootstrap5\Breadcrumbs
itemAttributes() Sets the HTML attributes for the items. Yiisoft\Bootstrap5\Breadcrumbs
linkAttributes() Sets the HTML attributes for the link of the items. Yiisoft\Bootstrap5\Breadcrumbs
links() List of links. If this property is empty, the widget will not render anything. Yiisoft\Bootstrap5\Breadcrumbs
listAttributes() Sets the HTML attributes for the list of items. Yiisoft\Bootstrap5\Breadcrumbs
listId() Sets the ID of the item list. Yiisoft\Bootstrap5\Breadcrumbs
listTagName() Sets the HTML tag to be used for the list of items. Yiisoft\Bootstrap5\Breadcrumbs
render() Run the widget. Yiisoft\Bootstrap5\Breadcrumbs

Constants

Hide inherited constants

Constant Value Description Defined By
ITEM_NAME 'breadcrumb-item' Yiisoft\Bootstrap5\Breadcrumbs
LIST_NAME 'breadcrumb' Yiisoft\Bootstrap5\Breadcrumbs

Method Details

Hide inherited methods

addAttributes() public method

Adds a sets of attributes.

public self addAttributes ( array $attributes )
$attributes array

Attribute values indexed by attribute names. for example, ['id' => 'my-id'].

return self

A new instance with the specified attributes added.

Example usage: `php $breadcrumb->addAttributes(['data-id' => '123']); `

                public function addAttributes(array $attributes): self
{
    $new = clone $this;
    $new->attributes = [...$new->attributes, ...$attributes];
    return $new;
}

            
addClass() public method

Adds one or more CSS classes to the existing classes.

Multiple classes can be added by passing them as separate arguments. null values are filtered out automatically.

public self addClass ( \BackedEnum|string|null $class )
$class \BackedEnum|string|null

One or more CSS class names to add. Pass null to skip adding a class.

return self

A new instance with the specified CSS classes added to existing ones.

                public function addClass(BackedEnum|string|null ...$class): self
{
    $new = clone $this;
    $new->cssClasses = [...$this->cssClasses, ...$class];
    return $new;
}

            
addCssStyle() public method

Adds a CSS style.

public self addCssStyle ( array|string $style, boolean $overwrite true )
$style array|string

The CSS style. If the value is an array, a space will separate the values. For example, ['color' => 'red', 'font-weight' => 'bold'] will be rendered as color: red; font-weight: bold;. If it is a string, it will be added as is, for example, color: red.

$overwrite boolean

Whether to overwrite existing styles with the same name. If false, the new value will be appended to the existing one.

return self

A new instance with the specified CSS style value added.

Example usage: `php $breadcrumb->addCssStyle('color: red');

// or $breadcrumb->addCssStyle(['color' => 'red', 'font-weight' => 'bold']); `

                public function addCssStyle(array|string $style, bool $overwrite = true): self
{
    $new = clone $this;
    Html::addCssStyle($new->attributes, $style, $overwrite);
    return $new;
}

            
ariaLabel() public method

Sets the ARIA label.

public self ariaLabel ( string $label )
$label string

The ARIA label.

return self

A new instance with the specified ARIA label.

                public function ariaLabel(string $label): self
{
    return $this->attribute('aria-label', $label);
}

            
attribute() public method

Adds a sets attribute value.

public self attribute ( string $name, mixed $value )
$name string

The attribute name.

$value mixed

The attribute value.

return self

A new instance with the specified attribute added.

Example usage: `php $breadcrumb->attribute('data-id', '123'); `

                public function attribute(string $name, mixed $value): self
{
    $new = clone $this;
    $new->attributes[$name] = $value;
    return $new;
}

            
attributes() public method

Sets the HTML attributes.

public self attributes ( array $attributes )
$attributes array

Attribute values indexed by attribute names.

return self

A new instance with the specified attributes.

                public function attributes(array $attributes): self
{
    $new = clone $this;
    $new->attributes = $attributes;
    return $new;
}

            
class() public method

Replaces all existing CSS classes with the specified one(s).

Multiple classes can be added by passing them as separate arguments. null values are filtered out automatically.

public self class ( \BackedEnum|string|null $class )
$class \BackedEnum|string|null

One or more CSS class names to set. Pass null to skip setting a class.

return self

A new instance with the specified CSS classes set.

Example usage: `php $breadcrumb->class('custom-class', null, 'another-class', BackGroundColor::PRIMARY); `

                public function class(BackedEnum|string|null ...$class): self
{
    $new = clone $this;
    $new->cssClasses = $class;
    return $new;
}

            
divider() public method

Sets the divider.

public self divider ( string $content )
$content string

The divider.

return self

A new instance with the specified divider.

Example usage: `php $breadcrumb->divider('/'); `

throws InvalidArgumentException

If the divider is an empty string.

                public function divider(string $content): self
{
    if ($content === '') {
        throw new InvalidArgumentException('The "divider" cannot be empty.');
    }
    return $this->attribute('style', ['--bs-breadcrumb-divider' => sprintf("'%s'", $content)]);
}

            
itemActiveClass() public method

Sets the active class for the items.

public self itemActiveClass ( string $class )
$class string

The active class for the items.

return self

A new instance with the specified active class for the items.

Example usage: `php $breadcrumb->itemActiveClass('active'); `

                public function itemActiveClass(string $class): self
{
    $new = clone $this;
    $new->itemActiveClass = $class;
    return $new;
}

            
itemAttributes() public method

Sets the HTML attributes for the items.

public self itemAttributes ( array $attributes )
$attributes array

Attribute values indexed by attribute names.

return self

A new instance with the specified attributes for the items.

                public function itemAttributes(array $attributes): self
{
    $new = clone $this;
    $new->itemAttributes = $attributes;
    return $new;
}

            
linkAttributes() public method

Sets the HTML attributes for the link of the items.

public self linkAttributes ( array $attributes )
$attributes array

Attribute values indexed by attribute names.

return self

A new instance with the specified attributes for the link of the items.

                public function linkAttributes(array $attributes): self
{
    $new = clone $this;
    $new->linkAttributes = $attributes;
    return $new;
}

            
links() public method

List of links. If this property is empty, the widget will not render anything.

public self links ( Yiisoft\Bootstrap5\BreadcrumbLink $links )
$links Yiisoft\Bootstrap5\BreadcrumbLink

The links.

return self

A new instance with the specified links.

listAttributes() public method

Sets the HTML attributes for the list of items.

public self listAttributes ( array $attributes )
$attributes array

Attribute values indexed by attribute names.

return self

A new instance with the specified attributes for the list of items.

                public function listAttributes(array $attributes): self
{
    $new = clone $this;
    $new->listAttributes = $attributes;
    return $new;
}

            
listId() public method

Sets the ID of the item list.

public self listId ( boolean|string $id )
$id boolean|string

The ID. If true, an ID will be generated automatically.

return self

A new instance with the specified ID for the list of items.

Example usage: `php $breadcrumb->listId('my-id'); `

                public function listId(bool|string $id): self
{
    $new = clone $this;
    $new->listId = $id;
    return $new;
}

            
listTagName() public method

Sets the HTML tag to be used for the list of items.

public self listTagName ( string $tag )
$tag string

The HTML tag name for the list of items.

return self

A new instance class with the specified list tag name.

Example usage: `php $breadcrumb->listTagName('ul'); `

throws InvalidArgumentException

If the tag name is empty.

                public function listTagName(string $tag): self
{
    $new = clone $this;
    $new->listTagName = $tag;
    return $new;
}

            
render() public method

Run the widget.

public string render ( )
return string

The HTML representation of the element.

                public function render(): string
{
    $attributes = $this->attributes;
    $attributes['aria-label'] ??= 'breadcrumb';
    if ($this->links === []) {
        return '';
    }
    return Nav::tag()
        ->addAttributes($attributes)
        ->addClass(...$this->cssClasses)
        ->content("\n", $this->renderList(), "\n")
        ->encode(false)
        ->render();
}