|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Form\Field; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Form\Field\Base\PartsField; |
|
8
|
|
|
use Yiisoft\Html\Tag\Button as ButtonTag; |
|
9
|
|
|
use Yiisoft\Html\Widget\ButtonGroup as ButtonGroupWidget; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Represents a button group widget. |
|
13
|
|
|
* |
|
14
|
|
|
* @see ButtonGroupWidget |
|
15
|
|
|
*/ |
|
16
|
|
|
final class ButtonGroup extends PartsField |
|
17
|
|
|
{ |
|
18
|
|
|
private ButtonGroupWidget $widget; |
|
19
|
|
|
|
|
20
|
12 |
|
public function __construct() |
|
21
|
|
|
{ |
|
22
|
12 |
|
$this->widget = ButtonGroupWidget::create()->withoutContainer(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
6 |
|
public function buttons(ButtonTag ...$buttons): self |
|
26
|
|
|
{ |
|
27
|
6 |
|
$new = clone $this; |
|
28
|
6 |
|
$new->widget = $this->widget->buttons(...$buttons); |
|
29
|
6 |
|
return $new; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param array $data Array of buttons. Each button is an array with label as first element and additional |
|
34
|
|
|
* name-value pairs as attributes of button. |
|
35
|
|
|
* |
|
36
|
|
|
* Example: |
|
37
|
|
|
* ```php |
|
38
|
|
|
* [ |
|
39
|
|
|
* ['Reset', 'type' => 'reset', 'class' => 'default'], |
|
40
|
|
|
* ['Send', 'type' => 'submit', 'class' => 'primary'], |
|
41
|
|
|
* ] |
|
42
|
|
|
* ``` |
|
43
|
|
|
* @param bool $encode Whether button content should be HTML-encoded. |
|
44
|
|
|
*/ |
|
45
|
7 |
|
public function buttonsData(array $data, bool $encode = true): self |
|
46
|
|
|
{ |
|
47
|
7 |
|
$new = clone $this; |
|
48
|
7 |
|
$new->widget = $this->widget->buttonsData($data, $encode); |
|
49
|
7 |
|
return $new; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
2 |
|
public function buttonAttributes(array $attributes): self |
|
53
|
|
|
{ |
|
54
|
2 |
|
$new = clone $this; |
|
55
|
2 |
|
$new->widget = $this->widget->buttonAttributes($attributes); |
|
56
|
2 |
|
return $new; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
public function addButtonAttributes(array $attributes): self |
|
60
|
|
|
{ |
|
61
|
2 |
|
$new = clone $this; |
|
62
|
2 |
|
$new->widget = $this->widget->addButtonAttributes($attributes); |
|
63
|
2 |
|
return $new; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @link https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-disabled |
|
68
|
|
|
*/ |
|
69
|
2 |
|
public function disabled(bool $disabled = true): self |
|
70
|
|
|
{ |
|
71
|
2 |
|
$new = clone $this; |
|
72
|
2 |
|
$new->widget = $this->widget->disabled($disabled); |
|
73
|
2 |
|
return $new; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
2 |
|
public function form(?string $formId): self |
|
77
|
|
|
{ |
|
78
|
2 |
|
$new = clone $this; |
|
79
|
2 |
|
$new->widget = $this->widget->form($formId); |
|
80
|
2 |
|
return $new; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
2 |
|
public function separator(string $separator): self |
|
84
|
|
|
{ |
|
85
|
2 |
|
$new = clone $this; |
|
86
|
2 |
|
$new->widget = $this->widget->separator($separator); |
|
87
|
2 |
|
return $new; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
11 |
|
protected function generateInput(): string |
|
91
|
|
|
{ |
|
92
|
11 |
|
return $this->widget->render(); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|