ModelReferenceType.php 1.3 KB

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