Final Class Yiisoft\Bootstrap5\Breadcrumbs
| Inheritance | Yiisoft\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
| 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
| Constant | Value | Description | Defined By |
|---|---|---|---|
| ITEM_NAME | 'breadcrumb-item' | Yiisoft\Bootstrap5\Breadcrumbs | |
| LIST_NAME | 'breadcrumb' | Yiisoft\Bootstrap5\Breadcrumbs |
Method Details
Adds a sets of attributes.
| public self addAttributes ( array $attributes ) | ||
| $attributes | array |
Attribute values indexed by attribute names. for example, |
| return | self |
A new instance with the specified attributes added. Example usage:
|
|---|---|---|
public function addAttributes(array $attributes): self
{
$new = clone $this;
$new->attributes = [...$new->attributes, ...$attributes];
return $new;
}
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 |
| 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;
}
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, |
| $overwrite | boolean |
Whether to overwrite existing styles with the same name. If |
| return | self |
A new instance with the specified CSS style value added. Example usage:
// 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;
}
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);
}
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:
|
|---|---|---|
public function attribute(string $name, mixed $value): self
{
$new = clone $this;
$new->attributes[$name] = $value;
return $new;
}
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;
}
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 |
| return | self |
A new instance with the specified CSS classes set. Example usage:
|
|---|---|---|
public function class(BackedEnum|string|null ...$class): self
{
$new = clone $this;
$new->cssClasses = $class;
return $new;
}
Sets the divider.
| public self divider ( string $content ) | ||
| $content | string |
The divider. |
| return | self |
A new instance with the specified divider. Example usage:
|
|---|---|---|
| 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)]);
}
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:
|
|---|---|---|
public function itemActiveClass(string $class): self
{
$new = clone $this;
$new->itemActiveClass = $class;
return $new;
}
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;
}
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;
}
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. |
|---|---|---|
public function links(BreadcrumbLink ...$links): self
{
$new = clone $this;
$new->links = $links;
return $new;
}
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;
}
Sets the ID of the item list.
| public self listId ( boolean|string $id ) | ||
| $id | boolean|string |
The ID. If |
| return | self |
A new instance with the specified ID for the list of items. Example usage:
|
|---|---|---|
public function listId(bool|string $id): self
{
$new = clone $this;
$new->listId = $id;
return $new;
}
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:
|
|---|---|---|
| throws | InvalidArgumentException |
If the tag name is empty. |
public function listTagName(string $tag): self
{
$new = clone $this;
$new->listTagName = $tag;
return $new;
}
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();
}
Signup or Login in order to comment.