ModelReferenceType.php 1.7 KB

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