StatusType.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. namespace Sonata\AdminBundle\Form\Type;
  11. use Symfony\Component\Form\AbstractType;
  12. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  13. class StatusType extends AbstractType
  14. {
  15. protected $class;
  16. protected $getter;
  17. protected $name;
  18. /**
  19. * @param string $class
  20. * @param string $getter
  21. * @param string $name
  22. */
  23. public function __construct($class, $getter, $name)
  24. {
  25. $this->class = $class;
  26. $this->getter = $getter;
  27. $this->name = $name;
  28. }
  29. /**
  30. * {@inheritDoc}
  31. */
  32. public function getParent()
  33. {
  34. return 'choice';
  35. }
  36. /**
  37. * {@inheritDoc}
  38. */
  39. public function getName()
  40. {
  41. return $this->name;
  42. }
  43. /**
  44. * {@inheritDoc}
  45. */
  46. public function setDefaultOptions(OptionsResolverInterface $resolver)
  47. {
  48. $resolver->setDefaults(array(
  49. 'choice' => call_user_func(array($this->class, $this->getter))
  50. ));
  51. }
  52. }