1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Form; |
6
|
|
|
|
7
|
|
|
final class FieldFactoryConfig |
8
|
|
|
{ |
9
|
|
|
// |
10
|
|
|
// Common |
11
|
|
|
// |
12
|
|
|
|
13
|
|
|
private ?string $containerTag = null; |
14
|
|
|
private array $containerTagAttributes = []; |
15
|
|
|
private ?bool $useContainer = null; |
16
|
|
|
|
17
|
|
|
private ?string $template = null; |
18
|
|
|
|
19
|
|
|
private ?bool $setInputIdAttribute = null; |
20
|
|
|
|
21
|
|
|
private array $formElementTagAttributes = []; |
22
|
|
|
|
23
|
|
|
private array $labelConfig = []; |
24
|
|
|
private array $hintConfig = []; |
25
|
|
|
private array $errorConfig = []; |
26
|
|
|
|
27
|
|
|
// |
28
|
|
|
// Placeholder |
29
|
|
|
// |
30
|
|
|
|
31
|
|
|
private ?bool $usePlaceholder = null; |
32
|
|
|
|
33
|
|
|
// |
34
|
|
|
// Field configurations |
35
|
|
|
// |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var array[] |
39
|
|
|
*/ |
40
|
|
|
private array $fieldConfigs = []; |
41
|
|
|
|
42
|
2 |
|
public function containerTag(?string $tag): self |
43
|
|
|
{ |
44
|
2 |
|
$new = clone $this; |
45
|
2 |
|
$new->containerTag = $tag; |
46
|
2 |
|
return $new; |
47
|
|
|
} |
48
|
|
|
|
49
|
2 |
|
public function containerTagAttributes(array $attributes): self |
50
|
|
|
{ |
51
|
2 |
|
$new = clone $this; |
52
|
2 |
|
$new->containerTagAttributes = $attributes; |
53
|
2 |
|
return $new; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
public function useContainer(?bool $use): self |
57
|
|
|
{ |
58
|
1 |
|
$new = clone $this; |
59
|
1 |
|
$new->useContainer = $use; |
60
|
1 |
|
return $new; |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
public function template(?string $template): self |
64
|
|
|
{ |
65
|
1 |
|
$new = clone $this; |
66
|
1 |
|
$new->template = $template; |
67
|
1 |
|
return $new; |
68
|
|
|
} |
69
|
|
|
|
70
|
2 |
|
public function setInputIdAttribute(?bool $value): self |
71
|
|
|
{ |
72
|
2 |
|
$new = clone $this; |
73
|
2 |
|
$new->setInputIdAttribute = $value; |
74
|
2 |
|
return $new; |
75
|
|
|
} |
76
|
|
|
|
77
|
2 |
|
public function formElementTagAttributes(array $attributes): self |
78
|
|
|
{ |
79
|
2 |
|
$new = clone $this; |
80
|
2 |
|
$new->formElementTagAttributes = $attributes; |
81
|
2 |
|
return $new; |
82
|
|
|
} |
83
|
|
|
|
84
|
2 |
|
public function labelConfig(array $config): self |
85
|
|
|
{ |
86
|
2 |
|
$new = clone $this; |
87
|
2 |
|
$new->labelConfig = $config; |
88
|
2 |
|
return $new; |
89
|
|
|
} |
90
|
|
|
|
91
|
2 |
|
public function hintConfig(array $config): self |
92
|
|
|
{ |
93
|
2 |
|
$new = clone $this; |
94
|
2 |
|
$new->hintConfig = $config; |
95
|
2 |
|
return $new; |
96
|
|
|
} |
97
|
|
|
|
98
|
2 |
|
public function errorConfig(array $config): self |
99
|
|
|
{ |
100
|
2 |
|
$new = clone $this; |
101
|
2 |
|
$new->errorConfig = $config; |
102
|
2 |
|
return $new; |
103
|
|
|
} |
104
|
|
|
|
105
|
2 |
|
public function usePlaceholder(?bool $use): self |
106
|
|
|
{ |
107
|
2 |
|
$new = clone $this; |
108
|
2 |
|
$new->usePlaceholder = $use; |
109
|
2 |
|
return $new; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param array[] $configs |
114
|
|
|
*/ |
115
|
1 |
|
public function addFieldConfigs(array $configs): self |
116
|
|
|
{ |
117
|
1 |
|
$new = clone $this; |
118
|
1 |
|
$new->fieldConfigs = array_merge($this->fieldConfigs, $configs); |
119
|
1 |
|
return $new; |
120
|
|
|
} |
121
|
|
|
|
122
|
24 |
|
public function getContainerTag(): ?string |
123
|
|
|
{ |
124
|
24 |
|
return $this->containerTag; |
125
|
|
|
} |
126
|
|
|
|
127
|
24 |
|
public function getContainerTagAttributes(): array |
128
|
|
|
{ |
129
|
24 |
|
return $this->containerTagAttributes; |
130
|
|
|
} |
131
|
|
|
|
132
|
24 |
|
public function getUseContainer(): ?bool |
133
|
|
|
{ |
134
|
24 |
|
return $this->useContainer; |
135
|
|
|
} |
136
|
|
|
|
137
|
24 |
|
public function getTemplate(): ?string |
138
|
|
|
{ |
139
|
24 |
|
return $this->template; |
140
|
|
|
} |
141
|
|
|
|
142
|
24 |
|
public function getSetInputIdAttribute(): ?bool |
143
|
|
|
{ |
144
|
24 |
|
return $this->setInputIdAttribute; |
145
|
|
|
} |
146
|
|
|
|
147
|
24 |
|
public function getFormElementTagAttributes(): array |
148
|
|
|
{ |
149
|
24 |
|
return $this->formElementTagAttributes; |
150
|
|
|
} |
151
|
|
|
|
152
|
24 |
|
public function getLabelConfig(): array |
153
|
|
|
{ |
154
|
24 |
|
return $this->labelConfig; |
155
|
|
|
} |
156
|
|
|
|
157
|
24 |
|
public function getHintConfig(): array |
158
|
|
|
{ |
159
|
24 |
|
return $this->hintConfig; |
160
|
|
|
} |
161
|
|
|
|
162
|
24 |
|
public function getErrorConfig(): array |
163
|
|
|
{ |
164
|
24 |
|
return $this->errorConfig; |
165
|
|
|
} |
166
|
|
|
|
167
|
24 |
|
public function getUsePlaceholder(): ?bool |
168
|
|
|
{ |
169
|
24 |
|
return $this->usePlaceholder; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return array[] |
174
|
|
|
*/ |
175
|
24 |
|
public function getFieldConfigs(): array |
176
|
|
|
{ |
177
|
24 |
|
return $this->fieldConfigs; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|