0 follower

Final Class Yiisoft\Html\Widget\CheckboxList\CheckboxList

InheritanceYiisoft\Html\Widget\CheckboxList\CheckboxList
ImplementsYiisoft\Html\NoEncodeStringableInterface

CheckboxList represents a list of checkboxes and their corresponding labels.

Public Methods

Hide inherited methods

Method Description Defined By
__toString() Yiisoft\Html\Widget\CheckboxList\CheckboxList
addCheckboxAttributes() Yiisoft\Html\Widget\CheckboxList\CheckboxList
addCheckboxLabelAttributes() Yiisoft\Html\Widget\CheckboxList\CheckboxList
addCheckboxWrapClass() Yiisoft\Html\Widget\CheckboxList\CheckboxList
addIndividualInputAttributes() Yiisoft\Html\Widget\CheckboxList\CheckboxList
checkboxAttributes() Yiisoft\Html\Widget\CheckboxList\CheckboxList
checkboxLabelAttributes() Yiisoft\Html\Widget\CheckboxList\CheckboxList
checkboxLabelWrap() Yiisoft\Html\Widget\CheckboxList\CheckboxList
checkboxWrapAttributes() Yiisoft\Html\Widget\CheckboxList\CheckboxList
checkboxWrapClass() Yiisoft\Html\Widget\CheckboxList\CheckboxList
checkboxWrapTag() Yiisoft\Html\Widget\CheckboxList\CheckboxList
containerAttributes() Yiisoft\Html\Widget\CheckboxList\CheckboxList
containerTag() Yiisoft\Html\Widget\CheckboxList\CheckboxList
create() Yiisoft\Html\Widget\CheckboxList\CheckboxList
disabled() Yiisoft\Html\Widget\CheckboxList\CheckboxList
form() Yiisoft\Html\Widget\CheckboxList\CheckboxList
individualInputAttributes() Yiisoft\Html\Widget\CheckboxList\CheckboxList
itemFormatter() Yiisoft\Html\Widget\CheckboxList\CheckboxList
items() Yiisoft\Html\Widget\CheckboxList\CheckboxList
itemsFromValues() Fills items from an array provided. Array values are used for both input labels and input values. Yiisoft\Html\Widget\CheckboxList\CheckboxList
name() Yiisoft\Html\Widget\CheckboxList\CheckboxList
readonly() Yiisoft\Html\Widget\CheckboxList\CheckboxList
render() Yiisoft\Html\Widget\CheckboxList\CheckboxList
separator() Yiisoft\Html\Widget\CheckboxList\CheckboxList
uncheckValue() Yiisoft\Html\Widget\CheckboxList\CheckboxList
value() Yiisoft\Html\Widget\CheckboxList\CheckboxList
values() Yiisoft\Html\Widget\CheckboxList\CheckboxList
withoutContainer() Yiisoft\Html\Widget\CheckboxList\CheckboxList

Method Details

Hide inherited methods

__toString() public method

public __toString( ): string

                public function __toString(): string
{
    return $this->render();
}

            
addCheckboxAttributes() public method

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

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

            
addCheckboxLabelAttributes() public method

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

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

            
addCheckboxWrapClass() public method

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

                public function addCheckboxWrapClass(?string ...$class): self
{
    $new = clone $this;
    Html::addCssClass(
        $new->checkboxWrapAttributes,
        array_filter($class, static fn($c) => $c !== null),
    );
    return $new;
}

            
addIndividualInputAttributes() public method

public addIndividualInputAttributes( array[] $attributes ): self
$attributes array[]

                public function addIndividualInputAttributes(array $attributes): self
{
    $new = clone $this;
    $new->individualInputAttributes = array_replace($new->individualInputAttributes, $attributes);
    return $new;
}

            
checkboxAttributes() public method

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

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

            
checkboxLabelAttributes() public method

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

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

            
checkboxLabelWrap() public method

public checkboxLabelWrap( boolean $wrap ): self
$wrap boolean

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

            
checkboxWrapAttributes() public method

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

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

            
checkboxWrapClass() public method

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

                public function checkboxWrapClass(?string ...$class): self
{
    $new = clone $this;
    $new->checkboxWrapAttributes['class'] = array_filter($class, static fn($c) => $c !== null);
    return $new;
}

            
checkboxWrapTag() public method

public checkboxWrapTag( string|null $name ): self
$name string|null

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

            
containerAttributes() public method

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

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

            
containerTag() public method

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

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

            
create() public static method

public static create( string $name ): self
$name string

                public static function create(string $name): self
{
    return new self($name);
}

            
disabled() public method

public disabled( boolean $disabled true ): self
$disabled boolean

                public function disabled(bool $disabled = true): self
{
    $new = clone $this;
    $new->checkboxAttributes['disabled'] = $disabled;
    return $new;
}

            
form() public method

public form( string|null $formId ): self
$formId string|null

                public function form(?string $formId): self
{
    $new = clone $this;
    $new->checkboxAttributes['form'] = $formId;
    return $new;
}

            
individualInputAttributes() public method

public individualInputAttributes( array[] $attributes ): self
$attributes array[]

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

            
itemFormatter() public method

public itemFormatter( Closure|null $formatter ): self
$formatter Closure|null

                public function itemFormatter(?Closure $formatter): self
{
    $new = clone $this;
    $new->itemFormatter = $formatter;
    return $new;
}

            
items() public method

public items( string[] $items, boolean $encodeLabels true ): self
$items string[]
$encodeLabels boolean

Whether labels should be encoded.

                public function items(array $items, bool $encodeLabels = true): self
{
    $new = clone $this;
    $new->items = $items;
    $new->encodeLabels = $encodeLabels;
    return $new;
}

            
itemsFromValues() public method

Fills items from an array provided. Array values are used for both input labels and input values.

public itemsFromValues( boolean[]|float[]|integer[]|string[]|\Stringable[] $values, boolean $encodeLabels true ): self
$values boolean[]|float[]|integer[]|string[]|\Stringable[]
$encodeLabels boolean

Whether labels should be encoded.

                public function itemsFromValues(array $values, bool $encodeLabels = true): self
{
    $values = array_map('\strval', $values);
    return $this->items(
        array_combine($values, $values),
        $encodeLabels,
    );
}

            
name() public method

public name( string $name ): self
$name string

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

            
readonly() public method

public readonly( boolean $readonly true ): self
$readonly boolean

                public function readonly(bool $readonly = true): self
{
    $new = clone $this;
    $new->checkboxAttributes['readonly'] = $readonly;
    return $new;
}

            
render() public method

public render( ): string

                public function render(): string
{
    $name = Html::getArrayableName($this->name);
    if ($this->checkboxWrapTag === null) {
        $beforeCheckbox = '';
        $afterCheckbox = '';
    } else {
        $beforeCheckbox = Html::openTag($this->checkboxWrapTag, $this->checkboxWrapAttributes) . "\n";
        $afterCheckbox = "\n" . Html::closeTag($this->checkboxWrapTag);
    }
    $lines = [];
    $index = 0;
    foreach ($this->items as $value => $label) {
        $item = new CheckboxItem(
            $index,
            $name,
            $value,
            ArrayHelper::isIn($value, $this->values),
            array_merge(
                $this->checkboxAttributes,
                $this->individualInputAttributes[$value] ?? [],
                ['name' => $name, 'value' => $value],
            ),
            $label,
            $this->encodeLabels,
            $this->checkboxLabelAttributes,
            $this->checkboxLabelWrap,
        );
        $lines[] = $beforeCheckbox . $this->formatItem($item) . $afterCheckbox;
        $index++;
    }
    $html = [];
    if ($this->uncheckValue !== null) {
        $html[] = $this->renderUncheckInput($this->uncheckValue);
    }
    if (!empty($this->containerTag)) {
        $html[] = Html::openTag($this->containerTag, $this->containerAttributes);
    }
    if ($lines) {
        $html[] = implode($this->separator, $lines);
    }
    if (!empty($this->containerTag)) {
        $html[] = Html::closeTag($this->containerTag);
    }
    return implode("\n", $html);
}

            
separator() public method

public separator( string $separator ): self
$separator string

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

            
uncheckValue() public method

public uncheckValue( boolean|float|integer|string|\Stringable|null $value ): self
$value boolean|float|integer|string|\Stringable|null

                public function uncheckValue(bool|float|int|string|Stringable|null $value): self
{
    $new = clone $this;
    $new->uncheckValue = $value === null ? null : (string) $value;
    return $new;
}

            
value() public method

public value( boolean|string|integer|float|\Stringable|\BackedEnum $value ): self
$value boolean|string|integer|float|\Stringable|\BackedEnum

                public function value(bool|string|int|float|Stringable|BackedEnum ...$value): self
{
    $new = clone $this;
    $new->values = array_map(
        static fn($v): string => (string) ($v instanceof BackedEnum ? $v->value : $v),
        array_values($value),
    );
    return $new;
}

            
values() public method

public values( iterable $values ): self
$values iterable

                public function values(iterable $values): self
{
    $values = is_array($values) ? $values : iterator_to_array($values);
    return $this->value(...$values);
}

            
withoutContainer() public method

public withoutContainer( ): self

                public function withoutContainer(): self
{
    $new = clone $this;
    $new->containerTag = null;
    return $new;
}