DateTimeRangeType.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. *
  10. */
  11. namespace Sonata\AdminBundle\Form\Type;
  12. use Symfony\Component\Form\AbstractType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Component\Translation\TranslatorInterface;
  15. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  16. class DateTimeRangeType extends AbstractType
  17. {
  18. protected $translator;
  19. /**
  20. * @param \Symfony\Component\Translation\TranslatorInterface $translator
  21. */
  22. public function __construct(TranslatorInterface $translator)
  23. {
  24. $this->translator = $translator;
  25. }
  26. /**
  27. * {@inheritDoc}
  28. */
  29. public function buildForm(FormBuilderInterface $builder, array $options)
  30. {
  31. $builder->add('start', 'datetime', array_merge(array('required' => false), $options['field_options']));
  32. $builder->add('end', 'datetime', array_merge(array('required' => false), $options['field_options']));
  33. }
  34. /**
  35. * {@inheritDoc}
  36. */
  37. public function getName()
  38. {
  39. return 'sonata_type_datetime_range';
  40. }
  41. /**
  42. * {@inheritDoc}
  43. */
  44. public function setDefaultOptions(OptionsResolverInterface $resolver)
  45. {
  46. $resolver->setDefaults(array(
  47. 'field_options' => array()
  48. ));
  49. }
  50. }