1<?php
2/**
3 * Copyright since 2007 PrestaShop SA and Contributors
4 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5 *
6 * NOTICE OF LICENSE
7 *
8 * This source file is subject to the Open Software License (OSL 3.0)
9 * that is bundled with this package in the file LICENSE.md.
10 * It is also available through the world-wide-web at this URL:
11 * https://opensource.org/licenses/OSL-3.0
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@prestashop.com so we can send you a copy immediately.
15 *
16 * DISCLAIMER
17 *
18 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
19 * versions in the future. If you wish to customize PrestaShop for your
20 * needs please refer to https://devdocs.prestashop.com/ for more information.
21 *
22 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
23 * @copyright Since 2007 PrestaShop SA and Contributors
24 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
25 */
26
27namespace PrestaShopBundle\Form\Admin\Type;
28
29use Symfony\Component\Form\AbstractType;
30use Symfony\Component\Form\DataTransformerInterface;
31use Symfony\Component\Form\Extension\Core\Type\TextType;
32use Symfony\Component\Form\FormBuilderInterface;
33use Symfony\Component\Form\FormInterface;
34use Symfony\Component\Form\FormView;
35use Symfony\Component\OptionsResolver\OptionsResolver;
36
37/**
38 * This form class is responsible to create a date picker field.
39 */
40class DatePickerType extends AbstractType
41{
42    /**
43     * @var DataTransformerInterface
44     */
45    private $arabicToLatinDigitDataTransformer;
46
47    public function __construct(DataTransformerInterface $arabicToLatinDigitDataTransformer)
48    {
49        $this->arabicToLatinDigitDataTransformer = $arabicToLatinDigitDataTransformer;
50    }
51
52    /**
53     * {@inheritdoc}
54     */
55    public function getParent()
56    {
57        return TextType::class;
58    }
59
60    public function buildForm(FormBuilderInterface $builder, array $options)
61    {
62        $builder->addViewTransformer($this->arabicToLatinDigitDataTransformer);
63    }
64
65    /**
66     * {@inheritdoc}
67     */
68    public function buildView(FormView $view, FormInterface $form, array $options)
69    {
70        $view->vars['date_format'] = $options['date_format'];
71    }
72
73    /**
74     * {@inheritdoc}
75     */
76    public function configureOptions(OptionsResolver $resolver)
77    {
78        $resolver->setDefaults([
79            'widget' => 'single_text',
80            // date_format must be provided in javascript supported type
81            'date_format' => 'YYYY-MM-DD',
82        ]);
83        $resolver->setAllowedTypes('date_format', 'string');
84    }
85
86    /**
87     * Returns the block prefix of this type.
88     *
89     * @return string The prefix name
90     */
91    public function getBlockPrefix()
92    {
93        return 'date_picker';
94    }
95}
96