0 follower

Final Class Yiisoft\Html\Widget\ButtonGroup

InheritanceYiisoft\Html\Widget\ButtonGroup
ImplementsYiisoft\Html\NoEncodeStringableInterface

ButtonGroup represents a group of buttons.

Method Details

Hide inherited methods

__toString() public method

public string __toString ( )

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

            
addButtonAttributes() public method

public self addButtonAttributes ( array $attributes )
$attributes array

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

            
buttonAttributes() public method

public self buttonAttributes ( array $attributes )
$attributes array

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

            
buttons() public method

public self buttons ( Yiisoft\Html\Tag\Button $buttons )
$buttons Yiisoft\Html\Tag\Button

                public function buttons(Button ...$buttons): self
{
    $new = clone $this;
    $new->buttons = $buttons;
    return $new;
}

            
buttonsData() public method

public self buttonsData ( array $data, boolean $encode true )
$data array

Array of buttons. Each button is an array with label as first element and additional name-value pairs as attributes of button.

Example: `php [

['Reset', 'type' => 'reset', 'class' => 'default'],
['Send', 'type' => 'submit', 'class' => 'primary'],

] `

$encode boolean

Whether button content should be HTML-encoded.

                public function buttonsData(array $data, bool $encode = true): self
{
    $buttons = [];
    foreach ($data as $row) {
        if (!is_array($row) || !isset($row[0]) || !is_string($row[0])) {
            throw new InvalidArgumentException(
                'Invalid buttons data. A data row must be array with label as first element '
                . 'and additional name-value pairs as attributes of button.',
            );
        }
        $label = $row[0];
        unset($row[0]);
        $buttons[] = Html::button($label, $row)->encode($encode);
    }
    return $this->buttons(...$buttons);
}

            
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|null $name )
$name string|null

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

            
create() public static method

public static self create ( )

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

            
disabled() public method

public self disabled ( boolean|null $disabled true )
$disabled boolean|null

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

            
form() public method

Specifies the form element the buttons belongs to. The value of this attribute must be the ID attribute of a form element in the same document.

public self form ( string|null $id )
$id string|null

ID of a form.

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

            
render() public method

public string render ( )

                public function render(): string
{
    if (empty($this->buttons)) {
        return '';
    }
    if (empty($this->buttonAttributes)) {
        $lines = $this->buttons;
    } else {
        $lines = [];
        foreach ($this->buttons as $button) {
            $lines[] = $button->unionAttributes($this->buttonAttributes);
        }
    }
    $html = [];
    if (!empty($this->containerTag)) {
        $html[] = Html::openTag($this->containerTag, $this->containerAttributes);
    }
    $html[] = implode($this->separator, $lines);
    if (!empty($this->containerTag)) {
        $html[] = Html::closeTag($this->containerTag);
    }
    return implode("\n", $html);
}

            
separator() public method

public self separator ( string $separator )
$separator string

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

            
withoutContainer() public method

public self withoutContainer ( )

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