Repository navigation
Expand file tree
/
Copy pathConnectionFormType.php
More file actions
66 lines (59 loc) · 1.69 KB
/
Copy pathConnectionFormType.php
File metadata and controls
66 lines (59 loc) · 1.69 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
<?php
namespace SyncEngine\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use SyncEngine\Entity\Connection;
use SyncEngine\Form\Type\JsonType;
use SyncEngine\Model\ConnectionModel;
class ConnectionFormType extends AbstractType
{
public function buildForm( FormBuilderInterface $builder, array $options ): void
{
$model = $options['model'];
if ( ! isset( $options['model'] ) ) {
$model = ConnectionModel::create();
}
if ( ! $options['model'] instanceof ConnectionModel ) {
throw new \InvalidArgumentException( 'The "model" option must be an instance of ConnectionModel.' );
}
$builder
->add( 'name', TextType::class, [
'required' => true,
'row_attr' => [
'col-row-group' => 'name-desc',
'col-class' => 'col-12 col-lg-6',
'class' => 'form-floating mb-3',
],
] )
->add( 'description', TextType::class, [
'required' => false,
'row_attr' => [
'col-row-group' => 'name-desc',
'col-class' => 'col-12 col-lg-6',
'class' => 'form-floating mb-3',
],
] )
->add( 'config', JsonType::class, [
'row_attr' => [
'class' => 'form-floating mb-3',
],
'attr' => [
'data-controller' => 'react',
'data-type' => 'config',
'data-args' => json_encode( [
'fields' => $model->getFields()->normalize(),
'tags' => [],
] ),
]
] );
}
public function configureOptions( OptionsResolver $resolver ): void
{
$resolver->setDefaults( [
'data_class' => Connection::class,
'model' => null,
] );
}
}