generated from ibexa/bundle-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathField.php
More file actions
71 lines (61 loc) · 2.05 KB
/
Field.php
File metadata and controls
71 lines (61 loc) · 2.05 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
61
62
63
64
65
66
67
68
69
70
71
<?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\InputText;
use Ibexa\DesignSystemTwig\Twig\Components\AbstractField;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate;
/**
* @phpstan-type AttrMap array<string, scalar>
*/
#[AsTwigComponent('ibexa:input_text:field')]
final class Field extends AbstractField
{
/** @var non-empty-string */
public string $id;
/** @var AttrMap */
#[ExposeInTemplate(name: 'input', getter: 'getInput')]
public array $input = [];
public string $type = 'input-text';
public string $value = '';
/**
* @return AttrMap
*/
public function getLabelExtra(): array
{
return $this->labelExtra + ['for' => $this->id, 'required' => $this->required];
}
/**
* @return AttrMap
*/
public function getInput(): array
{
return $this->input + [
'id' => $this->id,
'name' => $this->name,
'required' => $this->required,
'value' => $this->value,
'data-ids-custom-init' => 'true',
];
}
protected function configurePropsResolver(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'id' => null,
'input' => [],
]);
$resolver->setAllowedTypes('input', 'array');
$resolver->setNormalizer('input', static function (Options $options, array $attributes) {
return self::assertForbidden($attributes, ['id', 'name', 'required', 'value'], 'input');
});
$resolver->setRequired(['name']);
$resolver->setAllowedTypes('id', ['null', 'string']);
$resolver->setDefaults(['value' => '']);
$resolver->setAllowedTypes('value', 'string');
}
}