0 follower

Final Class Yiisoft\Yii\DataView\Pagination\KeysetPagination

InheritanceYiisoft\Yii\DataView\Pagination\KeysetPagination » Yiisoft\Widget\Widget
ImplementsYiisoft\Yii\DataView\Pagination\PaginationWidgetInterface
Uses TraitsYiisoft\Yii\DataView\Pagination\PaginationContextTrait

Widget for rendering KeysetPaginator.

Public Methods

Hide inherited methods

Method Description Defined By
addLinkClass() Adds one or more CSS classes to the existing link classes. Yiisoft\Yii\DataView\Pagination\KeysetPagination
containerAttributes() Sets the container element attributes. Yiisoft\Yii\DataView\Pagination\KeysetPagination
containerTag() Sets the container tag name. Yiisoft\Yii\DataView\Pagination\KeysetPagination
context() Creates a new instance with the specified pagination context. Yiisoft\Yii\DataView\Pagination\PaginationContextTrait
create() Creates a new instance with the specified paginator and context. Yiisoft\Yii\DataView\Pagination\KeysetPagination
disabledItemClass() Sets the CSS class for disabled item elements. Yiisoft\Yii\DataView\Pagination\KeysetPagination
disabledLinkClass() Sets the CSS class for disabled link elements. Yiisoft\Yii\DataView\Pagination\KeysetPagination
itemAttributes() Sets the item element attributes. Yiisoft\Yii\DataView\Pagination\KeysetPagination
itemTag() Sets the item tag name. Yiisoft\Yii\DataView\Pagination\KeysetPagination
labelNext() Sets the label for the next page link. Yiisoft\Yii\DataView\Pagination\KeysetPagination
labelPrevious() Sets the label for the previous page link. Yiisoft\Yii\DataView\Pagination\KeysetPagination
linkAttributes() Sets the link attributes. Yiisoft\Yii\DataView\Pagination\KeysetPagination
linkClass() Set new link classes. Yiisoft\Yii\DataView\Pagination\KeysetPagination
listAttributes() Sets the list element attributes. Yiisoft\Yii\DataView\Pagination\KeysetPagination
listTag() Sets the list tag name. Yiisoft\Yii\DataView\Pagination\KeysetPagination
paginator() Creates a new instance with the specified paginator. Yiisoft\Yii\DataView\Pagination\KeysetPagination
render() Renders the pagination controls. Yiisoft\Yii\DataView\Pagination\KeysetPagination
showOnSinglePage() Yiisoft\Yii\DataView\Pagination\KeysetPagination

Protected Methods

Hide inherited methods

Method Description Defined By
getContext() Gets the current pagination context. Yiisoft\Yii\DataView\Pagination\PaginationContextTrait

Method Details

Hide inherited methods

addLinkClass() public method

Adds one or more CSS classes to the existing link classes.

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

public addLinkClass( \BackedEnum|string|null $class ): self
$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 addLinkClass(BackedEnum|string|null ...$class): self
{
    $new = clone $this;
    Html::addCssClass($new->linkAttributes, $class);
    return $new;
}

            
containerAttributes() public method

Sets the container element attributes.

public containerAttributes( array $attributes ): self
$attributes array

HTML attributes for the container element.

return self

New instance with the specified container attributes.

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

            
containerTag() public method

Sets the container tag name.

public containerTag( string|null $tag ): self
$tag string|null

The tag name for the container element. Common values: 'nav', 'div'. Use null to omit the container.

return self

New instance with the specified container tag.

throws InvalidArgumentException

If tag name is empty.

                public function containerTag(?string $tag): self
{
    if ($tag === '') {
        throw new InvalidArgumentException('Tag name cannot be empty.');
    }
    $new = clone $this;
    $new->containerTag = $tag;
    return $new;
}

            
context() public method

Defined in: Yiisoft\Yii\DataView\Pagination\PaginationContextTrait::context()

Creates a new instance with the specified pagination context.

public context( Yiisoft\Yii\DataView\Pagination\PaginationContext $context ): Yiisoft\Yii\DataView\Pagination\KeysetPagination
$context Yiisoft\Yii\DataView\Pagination\PaginationContext

The pagination context to use.

return Yiisoft\Yii\DataView\Pagination\KeysetPagination

New instance with the specified context.

                final public function context(PaginationContext $context): static
{
    $new = clone $this;
    $new->context = $context;
    return $new;
}

            
create() public static method

Creates a new instance with the specified paginator and context.

public static create( \Yiisoft\Data\Paginator\KeysetPaginator $paginator, string $nextUrlPattern, string $previousUrlPattern ): self
$paginator \Yiisoft\Data\Paginator\KeysetPaginator

The paginator to use.

$nextUrlPattern string

URL pattern for next page links. Must contain Yiisoft\Yii\DataView\Pagination\PaginationContext::URL_PLACEHOLDER.

$previousUrlPattern string

URL pattern for previous page links. Must contain Yiisoft\Yii\DataView\Pagination\PaginationContext::URL_PLACEHOLDER.

return self

New instance with the specified paginator and context.

                public static function create(KeysetPaginator $paginator, string $nextUrlPattern, string $previousUrlPattern): self
{
    return self::widget()
        ->paginator($paginator)
        ->context(
            new PaginationContext($nextUrlPattern, $previousUrlPattern, ''),
        );
}

            
disabledItemClass() public method

Sets the CSS class for disabled item elements.

public disabledItemClass( string|null $class ): self
$class string|null

The CSS class for disabled items.

return self

New instance with the specified disabled item class.

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

            
disabledLinkClass() public method

Sets the CSS class for disabled link elements.

public disabledLinkClass( string|null $class ): self
$class string|null

The CSS class for disabled links.

return self

New instance with the specified disabled link class.

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

            
getContext() protected method

Defined in: Yiisoft\Yii\DataView\Pagination\PaginationContextTrait::getContext()

Gets the current pagination context.

protected getContext( ): Yiisoft\Yii\DataView\Pagination\PaginationContext
return Yiisoft\Yii\DataView\Pagination\PaginationContext

The current pagination context.

throws LogicException

If the context has not been set.

                final protected function getContext(): PaginationContext
{
    if ($this->context === null) {
        throw new LogicException('Context is not set.');
    }
    return $this->context;
}

            
itemAttributes() public method

Sets the item element attributes.

public itemAttributes( array $attributes ): self
$attributes array

HTML attributes for the item elements.

return self

New instance with the specified item attributes.

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

            
itemTag() public method

Sets the item tag name.

public itemTag( string|null $tag ): self
$tag string|null

The tag name for the item elements. Common values: 'li', 'div'. Use null to omit item containers.

return self

New instance with the specified item tag.

throws InvalidArgumentException

if tag name is empty.

                public function itemTag(?string $tag): self
{
    if ($tag === '') {
        throw new InvalidArgumentException('Tag name cannot be empty.');
    }
    $new = clone $this;
    $new->itemTag = $tag;
    return $new;
}

            
labelNext() public method

Sets the label for the next page link.

public labelNext( string|\Stringable $label ): self
$label string|\Stringable

The label for the next page link.

return self

New instance with the specified next label.

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

            
labelPrevious() public method

Sets the label for the previous page link.

public labelPrevious( string|\Stringable $label ): self
$label string|\Stringable

The label for the previous page link.

return self

New instance with the specified previous label.

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

            
linkAttributes() public method

Sets the link attributes.

public linkAttributes( array $attributes ): self
$attributes array

HTML attributes for the link elements.

return self

New instance with the specified link attributes.

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

            
linkClass() public method

Set new link classes.

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

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

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

                public function linkClass(BackedEnum|string|null ...$class): self
{
    $new = clone $this;
    $new->linkAttributes['class'] = [];
    Html::addCssClass($new->linkAttributes, $class);
    return $new;
}

            
listAttributes() public method

Sets the list element attributes.

public listAttributes( array $attributes ): self
$attributes array

HTML attributes for the list element.

return self

New instance with the specified list attributes.

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

            
listTag() public method

Sets the list tag name.

public listTag( string|null $tag ): self
$tag string|null

The tag name for the list element. Common values: 'ul', 'div'. Use null to omit the list container.

return self

New instance with the specified list tag.

throws InvalidArgumentException

if tag name is empty.

                public function listTag(?string $tag): self
{
    if ($tag === '') {
        throw new InvalidArgumentException('Tag name cannot be empty.');
    }
    $new = clone $this;
    $new->listTag = $tag;
    return $new;
}

            
paginator() public method

Creates a new instance with the specified paginator.

public paginator( \Yiisoft\Data\Paginator\PaginatorInterface $paginator ): Yiisoft\Yii\DataView\Pagination\KeysetPagination
$paginator \Yiisoft\Data\Paginator\PaginatorInterface

The paginator to use.

return Yiisoft\Yii\DataView\Pagination\KeysetPagination

New instance with the specified paginator.

throws Yiisoft\Yii\DataView\Pagination\PaginatorNotSupportedException

If paginator is not a \Yiisoft\Data\Paginator\KeysetPaginator.

                public function paginator(PaginatorInterface $paginator): static
{
    /** @psalm-suppress DocblockTypeContradiction, NoValue */
    if (!$paginator instanceof KeysetPaginator) {
        throw new PaginatorNotSupportedException($paginator);
    }
    $new = clone $this;
    $new->paginator = $paginator;
    return $new;
}

            
render() public method

Renders the pagination controls.

public render( ): string
return string

The rendered HTML pagination controls.

throws Yiisoft\Yii\DataView\Pagination\PaginatorNotSetException

If paginator is not set.

                public function render(): string
{
    if (!$this->showOnSinglePage && !$this->getPaginator()->isPaginationRequired()) {
        return '';
    }
    $result = '';
    if ($this->containerTag !== null) {
        $result .= Html::openTag($this->containerTag, $this->containerAttributes) . "\n";
    }
    if ($this->listTag !== null) {
        $result .= Html::openTag($this->listTag, $this->listAttributes) . "\n";
    }
    $context = $this->getContext();
    $paginator = $this->getPaginator();
    $previousToken = $paginator->getPreviousToken();
    $nextToken = $paginator->getNextToken();
    $result .= $this->renderItem(
        $this->labelPrevious,
        $previousToken === null ? null : $context->createUrl($previousToken),
        $previousToken === null,
    )
        . "\n"
        . $this->renderItem(
            $this->labelNext,
            $nextToken === null ? null : $context->createUrl($nextToken),
            $nextToken === null,
        );
    if ($this->listTag !== null) {
        $result .= "\n" . Html::closeTag($this->listTag);
    }
    if ($this->containerTag !== null) {
        $result .= "\n" . Html::closeTag($this->containerTag);
    }
    return $result;
}

            
showOnSinglePage() public method

public showOnSinglePage( boolean $show true ): self
$show boolean

                public function showOnSinglePage(bool $show = true): self
{
    $new = clone $this;
    $new->showOnSinglePage = $show;
    return $new;
}