-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSettingsType.php
More file actions
79 lines (73 loc) · 2.32 KB
/
SettingsType.php
File metadata and controls
79 lines (73 loc) · 2.32 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
72
73
74
75
76
77
78
79
<?php
/*
* This file is part of Monsieur Biz' Settings plugin for Sylius.
*
* (c) Monsieur Biz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Form;
use MonsieurBiz\SyliusSettingsPlugin\Form\AbstractSettingsType;
use MonsieurBiz\SyliusSettingsPlugin\Form\SettingsTypeInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\UX\LiveComponent\Form\Type\LiveCollectionType;
class SettingsType extends AbstractSettingsType implements SettingsTypeInterface
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
if ($this->isDefaultForm($builder)) {
$this->addWithDefaultCheckbox(
$builder,
'demo_message',
TextType::class,
[
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
]
);
} else {
$this->addWithDefaultCheckbox(
$builder,
'demo_message',
TextType::class,
[
'required' => false,
]
);
}
$this->addWithDefaultCheckbox(
$builder,
'enabled',
CheckboxType::class,
[
'required' => false,
]
);
$this->addWithDefaultCheckbox(
$builder,
'demo_string_collection',
LiveCollectionType::class,
[
'entry_type' => TextType::class,
'label' => 'Demo String Collection',
'required' => false,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'delete_empty' => true,
'button_delete_options' => [
'attr' => [
'class' => 'btn-outline-danger',
],
],
]
);
}
}