Final Class Yiisoft\Html\Widget\RadioList\RadioList
| Inheritance | Yiisoft\Html\Widget\RadioList\RadioList |
|---|---|
| Implements | Yiisoft\Html\NoEncodeStringableInterface |
RadioList represents a list of radios and their corresponding labels.
Public Methods
Method Details
| public self addIndividualInputAttributes ( array[] $attributes ) | ||
| $attributes | array[] | |
public function addIndividualInputAttributes(array $attributes): self
{
$new = clone $this;
$new->individualInputAttributes = array_replace($new->individualInputAttributes, $attributes);
return $new;
}
| public self addRadioAttributes ( array $attributes ) | ||
| $attributes | array | |
public function addRadioAttributes(array $attributes): self
{
$new = clone $this;
$new->radioAttributes = array_merge($new->radioAttributes, $attributes);
return $new;
}
| public self addRadioLabelAttributes ( array $attributes ) | ||
| $attributes | array | |
public function addRadioLabelAttributes(array $attributes): self
{
$new = clone $this;
$new->radioLabelAttributes = array_merge($new->radioLabelAttributes, $attributes);
return $new;
}
| public self addRadioWrapClass ( string|null $class ) | ||
| $class | string|null | |
public function addRadioWrapClass(?string ...$class): self
{
$new = clone $this;
Html::addCssClass(
$new->radioWrapAttributes,
array_filter($class, static fn($c) => $c !== null),
);
return $new;
}
| public self containerAttributes ( array $attributes ) | ||
| $attributes | array | |
public function containerAttributes(array $attributes): self
{
$new = clone $this;
$new->containerAttributes = $attributes;
return $new;
}
| public self containerTag ( string|null $name ) | ||
| $name | string|null | |
public function containerTag(?string $name): self
{
$new = clone $this;
$new->containerTag = $name;
return $new;
}
| public static self create ( string $name ) | ||
| $name | string | |
public static function create(string $name): self
{
return new self($name);
}
| public self disabled ( boolean $disabled = true ) | ||
| $disabled | boolean | |
public function disabled(bool $disabled = true): self
{
$new = clone $this;
$new->radioAttributes['disabled'] = $disabled;
return $new;
}
| public self form ( string|null $formId ) | ||
| $formId | string|null | |
public function form(?string $formId): self
{
$new = clone $this;
$new->radioAttributes['form'] = $formId;
return $new;
}
| public self individualInputAttributes ( array[] $attributes ) | ||
| $attributes | array[] | |
public function individualInputAttributes(array $attributes): self
{
$new = clone $this;
$new->individualInputAttributes = $attributes;
return $new;
}
| public self itemFormatter ( Closure|null $formatter ) | ||
| $formatter | Closure|null | |
public function itemFormatter(?Closure $formatter): self
{
$new = clone $this;
$new->itemFormatter = $formatter;
return $new;
}
| public self items ( string[] $items, boolean $encodeLabels = true ) | ||
| $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;
}
Fills items from an array provided. Array values are used for both input labels and input values.
| public self itemsFromValues ( boolean[]|float[]|integer[]|string[]|\Stringable[] $values, boolean $encodeLabels = true ) | ||
| $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,
);
}
| public self name ( string $name ) | ||
| $name | string | |
public function name(string $name): self
{
$new = clone $this;
$new->name = $name;
return $new;
}
| public self radioAttributes ( array $attributes ) | ||
| $attributes | array | |
public function radioAttributes(array $attributes): self
{
$new = clone $this;
$new->radioAttributes = $attributes;
return $new;
}
| public self radioLabelAttributes ( array $attributes ) | ||
| $attributes | array | |
public function radioLabelAttributes(array $attributes): self
{
$new = clone $this;
$new->radioLabelAttributes = $attributes;
return $new;
}
| public self radioLabelWrap ( boolean $wrap ) | ||
| $wrap | boolean | |
public function radioLabelWrap(bool $wrap): self
{
$new = clone $this;
$new->radioLabelWrap = $wrap;
return $new;
}
| public self radioWrapAttributes ( array $attributes ) | ||
| $attributes | array | |
public function radioWrapAttributes(array $attributes): self
{
$new = clone $this;
$new->radioWrapAttributes = $attributes;
return $new;
}
| public self radioWrapClass ( string|null $class ) | ||
| $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;
}
| public self radioWrapTag ( string|null $name ) | ||
| $name | string|null | |
public function radioWrapTag(?string $name): self
{
$new = clone $this;
$new->radioWrapTag = $name;
return $new;
}
| public self readonly ( boolean $readonly = true ) | ||
| $readonly | boolean | |
public function readonly(bool $readonly = true): self
{
$new = clone $this;
$new->radioAttributes['readonly'] = $readonly;
return $new;
}
| public string render ( ) |
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);
}
| public self separator ( string $separator ) | ||
| $separator | string | |
public function separator(string $separator): self
{
$new = clone $this;
$new->separator = $separator;
return $new;
}
| public self uncheckValue ( boolean|float|integer|string|\Stringable|null $value ) | ||
| $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;
}
| public self value ( boolean|float|integer|string|\Stringable|\BackedEnum|null $value ) | ||
| $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;
}
| public self withoutContainer ( ) |
public function withoutContainer(): self
{
$new = clone $this;
$new->containerTag = null;
return $new;
}
Signup or Login in order to comment.