0 follower

Final Class Yiisoft\Html\Widget\RadioList\RadioList

InheritanceYiisoft\Html\Widget\RadioList\RadioList
ImplementsYiisoft\Html\NoEncodeStringableInterface

RadioList represents a list of radios and their corresponding labels.

Public Methods

Hide inherited methods

Method Description Defined By
__toString() Yiisoft\Html\Widget\RadioList\RadioList
addIndividualInputAttributes() Yiisoft\Html\Widget\RadioList\RadioList
addRadioAttributes() Yiisoft\Html\Widget\RadioList\RadioList
addRadioLabelAttributes() Yiisoft\Html\Widget\RadioList\RadioList
addRadioWrapClass() Yiisoft\Html\Widget\RadioList\RadioList
containerAttributes() Yiisoft\Html\Widget\RadioList\RadioList
containerTag() Yiisoft\Html\Widget\RadioList\RadioList
create() Yiisoft\Html\Widget\RadioList\RadioList
disabled() Yiisoft\Html\Widget\RadioList\RadioList
form() Yiisoft\Html\Widget\RadioList\RadioList
individualInputAttributes() Yiisoft\Html\Widget\RadioList\RadioList
itemFormatter() Yiisoft\Html\Widget\RadioList\RadioList
items() Yiisoft\Html\Widget\RadioList\RadioList
itemsFromValues() Fills items from an array provided. Array values are used for both input labels and input values. Yiisoft\Html\Widget\RadioList\RadioList
name() Yiisoft\Html\Widget\RadioList\RadioList
radioAttributes() Yiisoft\Html\Widget\RadioList\RadioList
radioLabelAttributes() Yiisoft\Html\Widget\RadioList\RadioList
radioLabelWrap() Yiisoft\Html\Widget\RadioList\RadioList
radioWrapAttributes() Yiisoft\Html\Widget\RadioList\RadioList
radioWrapClass() Yiisoft\Html\Widget\RadioList\RadioList
radioWrapTag() Yiisoft\Html\Widget\RadioList\RadioList
readonly() Yiisoft\Html\Widget\RadioList\RadioList
render() Yiisoft\Html\Widget\RadioList\RadioList
separator() Yiisoft\Html\Widget\RadioList\RadioList
uncheckValue() Yiisoft\Html\Widget\RadioList\RadioList
value() Yiisoft\Html\Widget\RadioList\RadioList
withoutContainer() Yiisoft\Html\Widget\RadioList\RadioList

Method Details

Hide inherited methods

__toString() public method

public __toString( ): string

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

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

            
addRadioAttributes() public method

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

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

            
addRadioLabelAttributes() public method

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

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

            
addRadioWrapClass() public method

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

                public function addRadioWrapClass(?string ...$class): self
{
    $new = clone $this;
    Html::addCssClass($new->radioWrapAttributes, $class);
    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->radioAttributes['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->radioAttributes['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;
}

            
radioAttributes() public method

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

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

            
radioLabelAttributes() public method

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

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

            
radioLabelWrap() public method

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

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

            
radioWrapAttributes() public method

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

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

            
radioWrapClass() public method

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

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

            
radioWrapTag() public method

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

                public function radioWrapTag(?string $name): self
{
    $new = clone $this;
    $new->radioWrapTag = $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->radioAttributes['readonly'] = $readonly;
    return $new;
}

            
render() public method

public render( ): string

                public function render(): string
{
    if ($this->radioWrapTag === null) {
        $beforeRadio = '';
        $afterRadio = '';
    } else {
        $beforeRadio = Html::openTag($this->radioWrapTag, $this->radioWrapAttributes) . "\n";
        $afterRadio = "\n" . Html::closeTag($this->radioWrapTag);
    }
    $lines = [];
    $index = 0;
    foreach ($this->items as $value => $label) {
        $item = new RadioItem(
            $index,
            $this->name,
            $value,
            $this->value !== null && $this->value == $value,
            array_merge(
                $this->radioAttributes,
                $this->individualInputAttributes[$value] ?? [],
                ['name' => $this->name, 'value' => $value],
            ),
            $label,
            $this->encodeLabels,
            $this->radioLabelAttributes,
            $this->radioLabelWrap,
        );
        $lines[] = $beforeRadio . $this->formatItem($item) . $afterRadio;
        $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|float|integer|string|\Stringable|\BackedEnum|null $value ): self
$value boolean|float|integer|string|\Stringable|\BackedEnum|null

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

            
withoutContainer() public method

public withoutContainer( ): self

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