1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LAG\AdminBundle\Utils; |
6
|
|
|
|
7
|
|
|
use LAG\AdminBundle\Form\Type\DateRangeType; |
8
|
|
|
use LAG\AdminBundle\Form\Type\Select2\Select2EntityType; |
9
|
|
|
use LAG\AdminBundle\Form\Type\Select2\Select2Type; |
10
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
11
|
|
|
use Symfony\Component\Form\Extension\Core\Type\FileType; |
12
|
|
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType; |
13
|
|
|
use Symfony\Component\Form\Extension\Core\Type\NumberType; |
14
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
16
|
|
|
|
17
|
|
|
class FormUtils |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Convert a shortcut type into its class type. |
21
|
|
|
*/ |
22
|
1 |
|
public static function convertShortFormType(?string $shortType): ?string |
23
|
|
|
{ |
24
|
|
|
$mapping = [ |
25
|
1 |
|
'choice' => Select2Type::class, |
26
|
|
|
'string' => TextType::class, |
27
|
|
|
'entity' => Select2EntityType::class, |
28
|
|
|
'date' => DateRangeType::class, |
29
|
|
|
'datetime' => DateRangeType::class, |
30
|
|
|
'text' => TextareaType::class, |
31
|
|
|
'number' => NumberType::class, |
32
|
|
|
'float' => NumberType::class, |
33
|
|
|
'integer' => IntegerType::class, |
34
|
|
|
'smallint' => IntegerType::class, |
35
|
|
|
'boolean' => CheckboxType::class, |
36
|
|
|
'bigint' => NumberType::class, |
37
|
|
|
'decimal' => NumberType::class, |
38
|
|
|
'guid' => TextType::class, |
39
|
|
|
'array' => TextareaType::class, |
40
|
|
|
'simple_array' => TextareaType::class, |
41
|
|
|
'json_array' => TextareaType::class, |
42
|
|
|
'file' => FileType::class, |
43
|
|
|
'upload' => FileType::class, |
44
|
|
|
]; |
45
|
1 |
|
$type = $shortType; |
46
|
|
|
|
47
|
1 |
|
if (\array_key_exists($shortType, $mapping)) { |
48
|
1 |
|
$type = $mapping[$shortType]; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
return $type; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|