-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathDateTypeExtension.php
More file actions
59 lines (53 loc) · 1.67 KB
/
Copy pathDateTypeExtension.php
File metadata and controls
59 lines (53 loc) · 1.67 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
<?php
namespace Mopa\Bundle\BootstrapBundle\Form\Extension;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class DateTypeExtension extends AbstractTypeExtension
{
/**
* {@inheritdoc}
*
* bypass the IntlDateFormatter default pattern, which comes always
* delivered as $options['formatter'] and
* $form->getConfig()->getAttribute('formatter')->getPattern();
* – use own pattern instead without changing the default date format
*/
public function finishView(FormView $view, FormInterface $form, array $options)
{
if ('single_text' === $options['widget'] && isset($options['datepicker'])) {
$view->vars['datepicker'] = $options['datepicker'];
$view->vars['format'] = $options['format'];
}
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setOptional(array(
'datepicker'
));
}
/**
* {@inheritdoc}
*
* @deprecated Remove it when bumping requirements to SF 2.7+
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}
/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Symfony\Component\Form\Extension\Core\Type\DateType'
: 'date' // SF <2.8 BC
;
}
}