Final Class Yiisoft\Yii\DataView\PageSize\InputPageSize
| Inheritance | Yiisoft\Yii\DataView\PageSize\InputPageSize » Yiisoft\Widget\Widget |
|---|---|
| Implements | Yiisoft\Yii\DataView\PageSize\PageSizeWidgetInterface |
| Uses Traits | Yiisoft\Yii\DataView\PageSize\PageSizeContextTrait |
Widget that renders a text input for setting the page size.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| addAttributes() | Add a set of attributes to existing input tag attributes. | Yiisoft\Yii\DataView\PageSize\InputPageSize |
| attributes() | Replace input tag attributes with a new set. | Yiisoft\Yii\DataView\PageSize\InputPageSize |
| render() | Renders the page size input with the current context. | Yiisoft\Yii\DataView\PageSize\InputPageSize |
| withContext() | Creates a new instance with the specified page size context. | Yiisoft\Yii\DataView\PageSize\PageSizeContextTrait |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| getContext() | Gets the current page size context. | Yiisoft\Yii\DataView\PageSize\PageSizeContextTrait |
Method Details
Add a set of attributes to existing input tag attributes.
Same named attributes are replaced.
| public addAttributes( array $attributes ): self | ||
| $attributes | array |
Name-value set of attributes. |
| return | self |
New instance with added attributes. |
|---|---|---|
public function addAttributes(array $attributes): self
{
$new = clone $this;
$new->attributes = array_merge($new->attributes, $attributes);
return $new;
}
Replace input tag attributes with a new set.
| public attributes( array $attributes ): self | ||
| $attributes | array |
Name-value set of attributes. |
| return | self |
New instance with replaced attributes. |
|---|---|---|
public function attributes(array $attributes): self
{
$new = clone $this;
$new->attributes = $attributes;
return $new;
}
Defined in: Yiisoft\Yii\DataView\PageSize\PageSizeContextTrait::getContext()
Gets the current page size context.
| protected getContext( ): Yiisoft\Yii\DataView\PageSize\PageSizeContext | ||
| return | Yiisoft\Yii\DataView\PageSize\PageSizeContext |
The current page size context. |
|---|---|---|
| throws | LogicException |
If the context has not been set. |
final protected function getContext(): PageSizeContext
{
if ($this->context === null) {
throw new LogicException('Context is not set.');
}
return $this->context;
}
Renders the page size input with the current context.
| public render( ): string | ||
| return | string |
The rendered HTML input element. |
|---|---|---|
public function render(): string
{
$context = $this->getContext();
$attributes = array_merge($this->attributes, [
'data-default-page-size' => $context->defaultValue,
'data-url-pattern' => $context->urlPattern,
'data-default-url' => $context->defaultUrl,
'onchange' => 'window.location.href = this.value == this.dataset.defaultPageSize ? this.dataset.defaultUrl : this.dataset.urlPattern.replace("' . PageSizeContext::URL_PLACEHOLDER . '", this.value)',
]);
return Html::textInput(
value: $context->currentValue,
attributes: $attributes,
)->render();
}
Defined in: Yiisoft\Yii\DataView\PageSize\PageSizeContextTrait::withContext()
Creates a new instance with the specified page size context.
| public withContext( Yiisoft\Yii\DataView\PageSize\PageSizeContext $context ): Yiisoft\Yii\DataView\PageSize\InputPageSize | ||
| $context | Yiisoft\Yii\DataView\PageSize\PageSizeContext |
The page size context to use. |
| return | Yiisoft\Yii\DataView\PageSize\InputPageSize |
New instance with the specified context. |
|---|---|---|
final public function withContext(PageSizeContext $context): static
{
$new = clone $this;
$new->context = $context;
return $new;
}
Signup or Login in order to comment.