ModelReferenceType.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 Sonata\AdminBundle\Form\EventListener\MergeCollectionListener;
  18. use Sonata\AdminBundle\Form\ChoiceList\ModelChoiceList;
  19. use Sonata\AdminBundle\Form\DataTransformer\ModelsToArrayTransformer;
  20. use Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer;
  21. use Sonata\AdminBundle\Model\ModelManagerInterface;
  22. class ModelReferenceType extends AbstractType
  23. {
  24. private $parent;
  25. /**
  26. * {@inheritDoc}
  27. */
  28. public function buildForm(FormBuilderInterface $builder, array $options)
  29. {
  30. $builder->prependClientTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']));
  31. $this->parent = $options['parent'];
  32. }
  33. /**
  34. * {@inheritDoc}
  35. */
  36. public function getDefaultOptions()
  37. {
  38. return array(
  39. 'model_manager' => null,
  40. 'class' => null,
  41. 'parent' => 'hidden',
  42. );
  43. }
  44. /**
  45. * {@inheritDoc}
  46. */
  47. public function getParent()
  48. {
  49. return $this->parent;
  50. }
  51. /**
  52. * {@inheritDoc}
  53. */
  54. public function getName()
  55. {
  56. return 'sonata_type_model_reference';
  57. }
  58. }