0

Final Class Yiisoft\Yii\DataView\Pagination\OffsetPagination

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

Widget for rendering {@see OffsetPaginator}.

Public Methods

Hide inherited methods

Method Description Defined By
addLinkAttributes() Yiisoft\Yii\DataView\Pagination\OffsetPagination
addLinkClass() Adds one or more CSS classes to the existing classes of each link (the a element, or the span element that replaces it when a first/previous/next/last control is disabled). Yiisoft\Yii\DataView\Pagination\OffsetPagination
ariaLabelFirst() Sets the aria-label of the "first page" link. Pass null to omit it. Yiisoft\Yii\DataView\Pagination\OffsetPagination
ariaLabelLast() Sets the aria-label of the "last page" link. Pass null to omit it. Yiisoft\Yii\DataView\Pagination\OffsetPagination
ariaLabelNav() Sets the aria-label of the nav container. Pass null to omit it. Yiisoft\Yii\DataView\Pagination\OffsetPagination
ariaLabelNext() Sets the aria-label of the "next page" link. Pass null to omit it. Yiisoft\Yii\DataView\Pagination\OffsetPagination
ariaLabelPage() Sets the aria-label of the numbered page links. Pass null to omit it. Yiisoft\Yii\DataView\Pagination\OffsetPagination
ariaLabelPrevious() Sets the aria-label of the "previous page" link. Pass null to omit it. Yiisoft\Yii\DataView\Pagination\OffsetPagination
containerAttributes() Yiisoft\Yii\DataView\Pagination\OffsetPagination
containerTag() Yiisoft\Yii\DataView\Pagination\OffsetPagination
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\OffsetPagination
currentItemClass() Yiisoft\Yii\DataView\Pagination\OffsetPagination
currentLinkAttributes() Sets HTML attributes for the current page link, layered on top of {@see linkAttributes()}. Yiisoft\Yii\DataView\Pagination\OffsetPagination
currentLinkClass() Yiisoft\Yii\DataView\Pagination\OffsetPagination
disabledItemClass() Yiisoft\Yii\DataView\Pagination\OffsetPagination
disabledLinkAttributes() Sets HTML attributes for a disabled control, layered on top of {@see linkAttributes()}. Yiisoft\Yii\DataView\Pagination\OffsetPagination
disabledLinkClass() Sets the CSS class for a disabled control. Yiisoft\Yii\DataView\Pagination\OffsetPagination
itemAttributes() Yiisoft\Yii\DataView\Pagination\OffsetPagination
itemTag() Yiisoft\Yii\DataView\Pagination\OffsetPagination
labelFirst() Yiisoft\Yii\DataView\Pagination\OffsetPagination
labelLast() Yiisoft\Yii\DataView\Pagination\OffsetPagination
labelNext() Yiisoft\Yii\DataView\Pagination\OffsetPagination
labelPrevious() Yiisoft\Yii\DataView\Pagination\OffsetPagination
linkAttributes() Yiisoft\Yii\DataView\Pagination\OffsetPagination
linkClass() Set new link classes. Yiisoft\Yii\DataView\Pagination\OffsetPagination
listAttributes() Yiisoft\Yii\DataView\Pagination\OffsetPagination
listTag() Yiisoft\Yii\DataView\Pagination\OffsetPagination
maxNavLinkCount() Return a new instance with a max nav link count. Yiisoft\Yii\DataView\Pagination\OffsetPagination
paginator() Creates a new instance with the specified paginator. Yiisoft\Yii\DataView\Pagination\OffsetPagination
render() Yiisoft\Yii\DataView\Pagination\OffsetPagination
showOnSinglePage() Yiisoft\Yii\DataView\Pagination\OffsetPagination

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

addLinkAttributes() public method

public self addLinkAttributes ( array $attributes )
$attributes array

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

            
addLinkClass() public method

Adds one or more CSS classes to the existing classes of each link (the a element, or the span element that replaces it when a first/previous/next/last control is disabled).

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

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

            
ariaLabelFirst() public method

Sets the aria-label of the "first page" link. Pass null to omit it.

The value is applied only when accessibility is enabled and only when aria-label is not already present in {@see \Yiisoft\Yii\DataView\Pagination\linkAttributes()}. When rendered via GridView/ListView, it is translated.

public self ariaLabelFirst ( string|null $label )
$label string|null

The aria-label for the "first page" link.

return self

New instance with the specified first link aria-label.

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

            
ariaLabelLast() public method

Sets the aria-label of the "last page" link. Pass null to omit it.

The value is applied only when accessibility is enabled and only when aria-label is not already present in {@see \Yiisoft\Yii\DataView\Pagination\linkAttributes()}. When rendered via GridView/ListView, it is translated.

public self ariaLabelLast ( string|null $label )
$label string|null

The aria-label for the "last page" link.

return self

New instance with the specified last link aria-label.

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

            
ariaLabelNav() public method

Sets the aria-label of the nav container. Pass null to omit it.

The value is applied only when accessibility is enabled and only when aria-label is not already present in {@see \Yiisoft\Yii\DataView\Pagination\containerAttributes()}. When rendered via GridView/ListView, it is translated.

public self ariaLabelNav ( string|null $label )
$label string|null

The aria-label for the nav container.

return self

New instance with the specified nav aria-label.

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

            
ariaLabelNext() public method

Sets the aria-label of the "next page" link. Pass null to omit it.

The value is applied only when accessibility is enabled and only when aria-label is not already present in {@see \Yiisoft\Yii\DataView\Pagination\linkAttributes()}. When rendered via GridView/ListView, it is translated.

public self ariaLabelNext ( string|null $label )
$label string|null

The aria-label for the "next page" link.

return self

New instance with the specified next link aria-label.

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

            
ariaLabelPage() public method

Sets the aria-label of the numbered page links. Pass null to omit it.

The {page} placeholder is replaced with the page number. The value is applied only when accessibility is enabled and only when aria-label is not already present in {@see \Yiisoft\Yii\DataView\Pagination\linkAttributes()}. When rendered via GridView/ListView, it is translated.

public self ariaLabelPage ( string|null $label )
$label string|null

The aria-label for the numbered page links.

return self

New instance with the specified page link aria-label.

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

            
ariaLabelPrevious() public method

Sets the aria-label of the "previous page" link. Pass null to omit it.

The value is applied only when accessibility is enabled and only when aria-label is not already present in {@see \Yiisoft\Yii\DataView\Pagination\linkAttributes()}. When rendered via GridView/ListView, it is translated.

public self ariaLabelPrevious ( string|null $label )
$label string|null

The aria-label for the "previous page" link.

return self

New instance with the specified previous link aria-label.

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

            
containerAttributes() public method

public self containerAttributes ( array $attributes )
$attributes array

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

            
containerTag() public method

public self containerTag ( ?string $tag )
$tag ?string

                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 static context ( Yiisoft\Yii\DataView\Pagination\PaginationContext $context )
$context Yiisoft\Yii\DataView\Pagination\PaginationContext

The pagination context to use.

return Yiisoft\Yii\DataView\Pagination\OffsetPagination

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 self create ( \Yiisoft\Data\Paginator\OffsetPaginator $paginator, string $urlPattern, string $firstPageUrl, boolean $accessibility = false, \Yiisoft\Translator\TranslatorInterface|null $translator = null, string $translationCategory = BaseListView::DEFAULT_TRANSLATION_CATEGORY )
$paginator \Yiisoft\Data\Paginator\OffsetPaginator

The paginator to use.

$urlPattern string

URL pattern for page links. Must contain {@see \Yiisoft\Yii\DataView\Pagination\PaginationContext::URL_PLACEHOLDER}.

$firstPageUrl string

URL used on the first page.

$accessibility boolean

Whether to add aria-current, aria-disabled, aria-label and, on disabled items, role="link" attributes automatically.

$translator \Yiisoft\Translator\TranslatorInterface|null

Translator used for the aria-label texts. When null, the English defaults are emitted as is.

$translationCategory string

Category used with the translator.

return self

New instance with the specified paginator and context.

                public static function create(
    OffsetPaginator $paginator,
    string $urlPattern,
    string $firstPageUrl,
    bool $accessibility = false,
    ?TranslatorInterface $translator = null,
    string $translationCategory = BaseListView::DEFAULT_TRANSLATION_CATEGORY,
): self {
    return self::widget()
        ->paginator($paginator)
        ->context(
            new PaginationContext(
                $urlPattern,
                $urlPattern,
                $firstPageUrl,
                $accessibility,
                $translator,
                $translationCategory,
            ),
        );
}

            
currentItemClass() public method

public self currentItemClass ( ?string $class )
$class ?string

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

            
currentLinkAttributes() public method

Sets HTML attributes for the current page link, layered on top of {@see linkAttributes()}.

public self currentLinkAttributes ( array $attributes )
$attributes array

HTML attributes for the current page link.

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

            
currentLinkClass() public method

public self currentLinkClass ( ?string $class )
$class ?string

                public function currentLinkClass(?string $class): self
{
    $new = clone $this;
    $new->currentLinkAttributes['class'] = [];
    Html::addCssClass($new->currentLinkAttributes, $class);
    return $new;
}

            
disabledItemClass() public method

public self disabledItemClass ( ?string $class )
$class ?string

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

            
disabledLinkAttributes() public method

Sets HTML attributes for a disabled control, layered on top of {@see linkAttributes()}.

public self disabledLinkAttributes ( array $attributes )
$attributes array

HTML attributes for the span element of a disabled control.

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

            
disabledLinkClass() public method

Sets the CSS class for a disabled control.

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

The CSS class for the span element of a disabled control.

                public function disabledLinkClass(?string $class): self
{
    $new = clone $this;
    $new->disabledLinkAttributes['class'] = [];
    Html::addCssClass($new->disabledLinkAttributes, $class);
    return $new;
}

            
getContext() protected method

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

Gets the current pagination context.

protected Yiisoft\Yii\DataView\Pagination\PaginationContext getContext ( )
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

public self itemAttributes ( array $attributes )
$attributes array

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

            
itemTag() public method

public self itemTag ( ?string $tag )
$tag ?string

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

            
labelFirst() public method

public self labelFirst ( string|\Stringable|null $label )
$label string|\Stringable|null

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

            
labelLast() public method

public self labelLast ( string|\Stringable|null $label )
$label string|\Stringable|null

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

            
labelNext() public method

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

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

            
labelPrevious() public method

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

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

            
linkAttributes() public method

public self linkAttributes ( array $attributes )
$attributes array

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

            
linkClass() public method

Set new link classes.

The classes are applied to each link (the a element, or the span element that replaces it when a first/previous/next/last control is disabled).

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

public self linkClass ( \BackedEnum|string|null $class )
$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

public self listAttributes ( array $attributes )
$attributes array

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

            
listTag() public method

public self listTag ( ?string $tag )
$tag ?string

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

            
maxNavLinkCount() public method

Return a new instance with a max nav link count.

public self maxNavLinkCount ( integer $value )
$value integer

Max nav link count.

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

            
paginator() public method

Creates a new instance with the specified paginator.

public static paginator ( \Yiisoft\Data\Paginator\PaginatorInterface $paginator )
$paginator \Yiisoft\Data\Paginator\PaginatorInterface

The paginator to use.

return Yiisoft\Yii\DataView\Pagination\OffsetPagination

New instance with the specified paginator.

throws Yiisoft\Yii\DataView\Pagination\PaginatorNotSupportedException

If paginator is not a {@see \Yiisoft\Data\Paginator\OffsetPaginator}.

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

            
render() public method

public string render ( )

                public function render(): string
{
    if (!$this->showOnSinglePage && !$this->getPaginator()->isPaginationRequired()) {
        return '';
    }
    $result = '';
    $context = $this->getContext();
    if ($this->containerTag !== null) {
        $containerAttributes = $this->containerAttributes;
        if (
            $context->accessibility
            && $this->ariaLabelNav !== null
            && !array_key_exists('aria-label', $containerAttributes)
        ) {
            $containerAttributes['aria-label'] = $context->translate($this->ariaLabelNav);
        }
        $result .= Html::openTag($this->containerTag, $containerAttributes) . "\n";
    }
    if ($this->listTag !== null) {
        $result .= Html::openTag($this->listTag, $this->listAttributes) . "\n";
    }
    $items = $this->renderItems();
    $result .= implode("\n", $items);
    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 self showOnSinglePage ( boolean $show = true )
$show boolean

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