DateTimeRangeType.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\FormTypeInterface;
  14. use Symfony\Component\Form\FormBuilderInterface;
  15. use Symfony\Component\Translation\TranslatorInterface;
  16. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  17. class DateTimeRangeType extends AbstractType
  18. {
  19. protected $translator;
  20. /**
  21. * @param \Symfony\Component\Translation\TranslatorInterface $translator
  22. */
  23. public function __construct(TranslatorInterface $translator)
  24. {
  25. $this->translator = $translator;
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function buildForm(FormBuilderInterface $builder, array $options)
  31. {
  32. $builder->add('start', 'datetime', array_merge(array('required' => false), $options['field_options']));
  33. $builder->add('end', 'datetime', array_merge(array('required' => false), $options['field_options']));
  34. }
  35. /**
  36. * {@inheritDoc}
  37. */
  38. public function getName()
  39. {
  40. return 'sonata_type_datetime_range';
  41. }
  42. /**
  43. * {@inheritDoc}
  44. */
  45. public function setDefaultOptions(OptionsResolverInterface $resolver)
  46. {
  47. $resolver->setDefaults(array(
  48. 'field_options' => array()
  49. ));
  50. }
  51. }