1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Psi\Component\ContentType\Standard\Field; |
6
|
|
|
|
7
|
|
|
use Psi\Component\ContentType\FieldInterface; |
8
|
|
|
use Psi\Component\ContentType\OptionsResolver\FieldOptionsResolver; |
9
|
|
|
use Psi\Component\ContentType\Standard\Storage; |
10
|
|
|
use Psi\Component\ContentType\Standard\View; |
11
|
|
|
use Symfony\Component\Form\Extension\Core\Type as Form; |
12
|
|
|
|
13
|
|
|
class DateField implements FieldInterface |
14
|
|
|
{ |
15
|
|
|
public function getViewType(): string |
16
|
|
|
{ |
17
|
|
|
return View\DateType::class; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function getFormType(): string |
21
|
|
|
{ |
22
|
|
|
return Form\DateType::class; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getStorageType(): string |
26
|
|
|
{ |
27
|
|
|
return Storage\DateTimeType::class; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function configureOptions(FieldOptionsResolver $options) |
31
|
|
|
{ |
32
|
|
|
$options->setDefaults([ |
33
|
|
|
'format' => null, |
34
|
|
|
'date_format' => null, |
35
|
|
|
'widget' => null, |
36
|
|
|
'date_widget' => null, |
37
|
|
|
'time_widget' => null, |
38
|
|
|
'with_minutes' => true, |
39
|
|
|
'with_seconds' => false, |
40
|
|
|
'html5' => true, |
41
|
|
|
'by_reference' => false, |
42
|
|
|
'error_bubbling' => false, |
43
|
|
|
'data_class' => null, |
44
|
|
|
'compound' => true, |
45
|
|
|
|
46
|
|
|
'time_format' => null, |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$options->setFormMapper(function (array $options) { |
50
|
|
|
return array_intersect_key($options, array_flip([ |
51
|
|
|
'format', 'date_format', 'widget', 'date_widget', |
52
|
|
|
'time_widget', 'with_minutes', 'with_seconds', 'html5', |
53
|
|
|
'by_reference', 'error_bubbling', 'data_class', 'compound', |
54
|
|
|
])); |
55
|
|
|
}); |
56
|
|
|
|
57
|
|
|
$options->setViewMapper(function (array $options) { |
58
|
|
|
return array_intersect_key($options, array_flip([ |
59
|
|
|
'date_format', |
60
|
|
|
'time_format', |
61
|
|
|
])); |
62
|
|
|
}); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|