0 follower

Final Class Yiisoft\Bootstrap5\CarouselItem

InheritanceYiisoft\Bootstrap5\CarouselItem

CarouselItem represents a single item within a Bootstrap Carousel widget.

Each item can contain content, caption, and caption placeholder.

The item can be set as active and supports autoplaying intervals.

  • Active state: When is true, sets this item as the first visible slide.
  • Auto-playing: When enabled, cycling can be paused by hovering over the carousel, focusing on it, or clicking on carousel controls/indicators.

Example usage: `php <?= CarouselItem::to(

    '<img src="example.jpg" alt="Example">',
    'Image Caption',
    'Caption Placeholder'
);

?>

// Create an active carousel item with autoplay. <?= CarouselItem::to(

    content: '<img src="example.jpg">',
    caption: 'Slide 1',
    active: true,
    autoPlayingInterval: 5000
);

?> `

Method Details

Hide inherited methods

active() public method

Sets the active state.

public self active ( boolean $enabled )
$enabled boolean

Whether the breadcrumb link is active.

return self

A new instance with the specified active state.

                public function active(bool $enabled): self
{
    $new = clone $this;
    $new->active = $enabled;
    return $new;
}

            
attributes() public method

Sets the HTML attributes for the link.

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

            
autoPlayingInterval() public method

Sets the autoplaying interval.

public self autoPlayingInterval ( integer $interval )
$interval integer

The autoplaying interval in milliseconds.

return self

A new instance with the specified autoplaying interval.

                public function autoPlayingInterval(int $interval): self
{
    $new = clone $this;
    $new->autoPlayingInterval = $interval;
    return $new;
}

            
caption() public method

Sets the caption content.

public self caption ( string $caption )
$caption string

The caption content.

return self

A new instance with the specified caption content.

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

            
captionAttributes() public method

Sets the HTML attributes for the caption.

public self captionAttributes ( array $captionAttributes )
$captionAttributes array

Attribute values indexed by attribute names.

return self

A new instance with the specified attributes for the caption.

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

            
captionPlaceholder() public method

Sets the caption placeholder content.

public self captionPlaceholder ( string $captionPlaceholder )
$captionPlaceholder string

The caption placeholder content.

return self

A new instance with the specified caption placeholder content.

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

            
captionPlaceholderAttributes() public method

Sets the HTML attributes for the caption placeholder.

public self captionPlaceholderAttributes ( array $captionPlaceholderAttributes )
$captionPlaceholderAttributes array

Attribute values indexed by attribute names.

return self

A new instance with the specified attributes for the caption placeholder.

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

            
content() public method

Sets the content.

public self content ( string|\Stringable $content )
$content string|\Stringable

The content.

return self

A new instance with the specified content.

                public function content(string|Stringable $content): self
{
    $new = clone $this;
    $new->content = $content;
    return $new;
}

            
encodeCaption() public method

Sets whether to encode the caption content.

public self encodeCaption ( boolean $encode )
$encode boolean

Whether to encode the caption content.

return self

A new instance with the specified encoding setting.

                public function encodeCaption(bool $encode): self
{
    $new = clone $this;
    $new->encodeCaption = $encode;
    return $new;
}

            
encodeCaptionPlaceholder() public method

Sets whether to encode the caption placeholder content.

public self encodeCaptionPlaceholder ( boolean $encode )
$encode boolean

Whether to encode the caption placeholder content.

return self

A new instance with the specified encoding setting.

                public function encodeCaptionPlaceholder(bool $encode): self
{
    $new = clone $this;
    $new->encodeCaptionPlaceholder = $encode;
    return $new;
}

            
getAttributes() public method

public array getAttributes ( )
return array

Returns the HTML attributes for the carousel item.

                public function getAttributes(): array
{
    return $this->attributes;
}

            
getAutoPlayingInterval() public method

public integer|null getAutoPlayingInterval ( )
return integer|null

Returns the autoplaying interval for the carousel item.

                public function getAutoPlayingInterval(): int|null
{
    return $this->autoPlayingInterval;
}

            
getCaption() public method

public string|null getCaption ( )
return string|null

Returns the caption content for the carousel item.

                public function getCaption(): string|null
{
    return $this->encodeCaption ? Html::encode($this->caption) : $this->caption;
}

            
getCaptionAttributes() public method

public array getCaptionAttributes ( )
return array

Returns the HTML attributes for the caption.

                public function getCaptionAttributes(): array
{
    return $this->captionAttributes;
}

            
getCaptionPlaceholder() public method

public string|null getCaptionPlaceholder ( )
return string|null

Returns the caption placeholder content for the carousel item.

                public function getCaptionPlaceholder(): string|null
{
    return $this->encodeCaptionPlaceholder ? Html::encode($this->captionPlaceholder) : $this->captionPlaceholder;
}

            
getCaptionPlaceholderAttributes() public method

public array getCaptionPlaceholderAttributes ( )
return array

Returns the HTML attributes for the caption placeholder.

                public function getCaptionPlaceholderAttributes(): array
{
    return $this->captionPlaceholderAttributes;
}

            
getContent() public method

public string|\Stringable getContent ( )
return string|\Stringable

Returns the content for the carousel item.

                public function getContent(): string|Stringable
{
    return $this->content;
}

            
isActive() public method

public boolean isActive ( )
return boolean

Whether the item is active.

                public function isActive(): bool
{
    return $this->active;
}

            
to() public static method

Creates a new {@see CarouselItem} instance.

public static self to ( string|\Stringable $content '', string|null $caption null, string|null $captionPlaceholder null, integer|null $autoPlayingInterval null, boolean $active false, boolean $encodeCaption true, boolean $encodeCaptionPlaceholder true, array $attributes = [], array $captionAttributes = [], array $captionPlaceholderAttributes = [] )
$content string|\Stringable

The content of the carousel item.

$caption string|null

The caption content for the carousel item.

$captionPlaceholder string|null

The caption placeholder content for the carousel item.

$autoPlayingInterval integer|null

The autoplaying interval for the carousel item.

$active boolean

Whether the item is active.

$encodeCaption boolean

Whether to encode the caption content.

$encodeCaptionPlaceholder boolean

Whether to encode the caption placeholder content.

$attributes array

The HTML attributes for the carousel item.

$captionAttributes array

The HTML attributes for the caption.

$captionPlaceholderAttributes array

The HTML attributes for the caption placeholder.

return self

A new instance with the specified configuration.

                public static function to(
    string|Stringable $content = '',
    string|null $caption = null,
    string|null $captionPlaceholder = null,
    int|null $autoPlayingInterval = null,
    bool $active = false,
    bool $encodeCaption = true,
    bool $encodeCaptionPlaceholder = true,
    array $attributes = [],
    array $captionAttributes = [],
    array $captionPlaceholderAttributes = [],
): self {
    return new self(
        $active,
        $attributes,
        $autoPlayingInterval,
        $caption,
        $captionAttributes,
        $captionPlaceholder,
        $captionPlaceholderAttributes,
        $content,
        $encodeCaption,
        $encodeCaptionPlaceholder,
    );
}