Skip to content

Commit a716a92

Browse files
committed
Map flag attributes to methods and add default-value
1 parent 84c2517 commit a716a92

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/ComponentSupport.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@
66

77
class ComponentSupport
88
{
9-
private const BOOLEAN_ATTRIBUTES = ['required', 'disabled', 'readonly', 'autofocus', 'multiple', 'checked', 'selected'];
9+
private const FLAG_METHODS = [
10+
'required' => 'required',
11+
'disabled' => 'disabled',
12+
'readonly' => 'readonly',
13+
'autofocus' => 'autofocus',
14+
'multiple' => 'multiple',
15+
'checked' => 'checked',
16+
'selected' => 'selected',
17+
'inline' => 'inline',
18+
'hide-label' => 'hideLabel',
19+
];
1020

1121
public static function apply(mixed $control, ComponentAttributeBag $attributes): mixed
1222
{
1323
foreach ($attributes->getAttributes() as $key => $value) {
14-
if (in_array($key, self::BOOLEAN_ATTRIBUTES, true)) {
15-
if ($value === false) {
24+
if (array_key_exists($key, self::FLAG_METHODS)) {
25+
if ($value === false || $value === null) {
1626
continue;
1727
}
1828

19-
if ($value === null) {
20-
continue;
21-
}
22-
23-
$control->{$key}();
29+
$control->{self::FLAG_METHODS[$key]}();
2430

2531
continue;
2632
}
@@ -30,6 +36,7 @@ public static function apply(mixed $control, ComponentAttributeBag $attributes):
3036
'group-class' => $control->addGroupClass($value),
3137
'label-class' => $control->labelClass($value),
3238
'help' => $control->formText($value),
39+
'default-value' => $control->defaultValue($value),
3340
default => $control->attribute($key, $value),
3441
};
3542
}

0 commit comments

Comments
 (0)