Created
October 25, 2015 12:41
-
-
Save bobvandevijver/b58ad53a9be0b1f0d244 to your computer and use it in GitHub Desktop.
Extended s2a_datetime_picker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Idb\IdbBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormInterface; | |
use Symfony\Component\Form\FormView; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
class DateTimePicker extends AbstractType | |
{ | |
const FORMAT_JS = 'DD-MM-YYYY HH:mm'; | |
const FORMAT_PHP = 'd-m-Y H:i'; | |
const FORMAT_SF = 'dd-MM-yyyy HH:mm'; | |
public function buildView(FormView $view, FormInterface $form, array $options) | |
{ | |
$view->vars['width'] = $options['width']; | |
$view->vars['config'] = array_replace($options['config'], array( | |
'icons' => array( | |
'time' => "fa fa-clock-o", | |
'date' => "fa fa-calendar", | |
'up' => "fa fa-arrow-up", | |
'down' => "fa fa-arrow-down" | |
) | |
)); | |
if ($view->vars['value']) { | |
$value = new \DateTime($view->vars['value']); | |
$view->vars['widget_value'] = $value->format(self::FORMAT_PHP); | |
} | |
$view->vars['widget_format'] = self::FORMAT_JS; | |
} | |
public function getName() | |
{ | |
return 'idb_datetime_picker'; | |
} | |
public function getParent() | |
{ | |
return 's2a_datetime_picker'; | |
} | |
public function configureOptions(OptionsResolver $resolver) | |
{ | |
$resolver->setDefaults(array( | |
'widget' => 'single_text', | |
'format' => self::FORMAT_SF, | |
'width' => NULL, | |
'config' => array( | |
'format' => self::FORMAT_JS, | |
'useCurrent' => false, | |
'sideBySide' => true, | |
'stepping' => 5, | |
'showClear' => true, | |
'showClose' => true, | |
'icons' => array( | |
'time' => "fa fa-clock-o", | |
'date' => "fa fa-calendar", | |
'up' => "fa fa-arrow-up", | |
'down' => "fa fa-arrow-down" | |
) | |
) | |
)); | |
$resolver->setAllowedTypes(array( | |
'width' => array('null', 'integer'), | |
'config' => array('array') | |
)); | |
$resolver->setAllowedValues(array( | |
'widget' => array('single_text'), | |
'format' => array(self::FORMAT_SF), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment