ModelHiddenType.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\FormBuilderInterface;
  13. use Symfony\Component\Form\AbstractType;
  14. use Symfony\Component\OptionsResolver\Options;
  15. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  16. use Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer;
  17. /**
  18. * This type define a standard hidden field, that stored id to a object
  19. *
  20. * @author Andrej Hudec <pulzarraider@gmail.com>
  21. *
  22. */
  23. class ModelHiddenType extends AbstractType
  24. {
  25. /**
  26. * {@inheritDoc}
  27. */
  28. public function buildForm(FormBuilderInterface $builder, array $options)
  29. {
  30. $builder
  31. ->addViewTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']), true)
  32. ;
  33. }
  34. /**
  35. * {@inheritDoc}
  36. */
  37. public function setDefaultOptions(OptionsResolverInterface $resolver)
  38. {
  39. $resolver->setDefaults(array(
  40. 'model_manager' => null,
  41. 'class' => null,
  42. ));
  43. }
  44. /**
  45. * {@inheritDoc}
  46. */
  47. public function getParent()
  48. {
  49. return 'hidden';
  50. }
  51. /**
  52. * {@inheritDoc}
  53. */
  54. public function getName()
  55. {
  56. return 'sonata_type_model_hidden';
  57. }
  58. }