ModelReferenceType.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\OptionsResolverInterface;
  15. use Symfony\Component\OptionsResolver\Options;
  16. use Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer;
  17. class ModelReferenceType extends AbstractType
  18. {
  19. /**
  20. * {@inheritDoc}
  21. */
  22. public function buildForm(FormBuilderInterface $builder, array $options)
  23. {
  24. $builder->addModelTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']));
  25. }
  26. /**
  27. * {@inheritDoc}
  28. */
  29. public function setDefaultOptions(OptionsResolverInterface $resolver)
  30. {
  31. $resolver->setDefaults(array(
  32. 'compound' => false,
  33. 'model_manager' => null,
  34. 'class' => null,
  35. ));
  36. }
  37. /**
  38. * {@inheritDoc}
  39. */
  40. public function getParent()
  41. {
  42. return 'text';
  43. }
  44. /**
  45. * {@inheritDoc}
  46. */
  47. public function getName()
  48. {
  49. return 'sonata_type_model_reference';
  50. }
  51. }