generated from ibexa/bundle-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathListField.php
More file actions
60 lines (51 loc) · 1.65 KB
/
ListField.php
File metadata and controls
60 lines (51 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\DesignSystemTwig\Twig\Components\Checkbox;
use Ibexa\DesignSystemTwig\Twig\Components\AbstractField;
use Ibexa\DesignSystemTwig\Twig\Components\ListFieldTrait;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
/**
* @phpstan-type CheckboxItem array{
* id: non-empty-string,
* value: string|int,
* label: string,
* disabled?: bool,
* name?: string,
* required?: bool,
* attributes?: array<string, mixed>,
* label_attributes?: array<string, mixed>,
* inputWrapperClassName?: string,
* labelClassName?: string,
* checked?: bool
* }
* @phpstan-type CheckboxItems list<CheckboxItem>
*/
#[AsTwigComponent('ibexa:checkbox:list_field')]
final class ListField extends AbstractField
{
use ListFieldTrait;
/** @var array<string|int> */
public array $value = [];
/**
* @param CheckboxItem $item
*
* @return CheckboxItem
*/
protected function modifyListItem(array $item): array
{
$item['checked'] = in_array($item['value'], $this->value, true);
return $item;
}
protected function configurePropsResolver(OptionsResolver $resolver): void
{
$this->validateListFieldProps($resolver);
// TODO: check if items are valid according to Checkbox/Field component
$resolver->setDefaults(['value' => []]);
$resolver->setAllowedTypes('value', 'array');
}
}