ModelReferenceType.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\FormBuilder;
  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. public function buildForm(FormBuilder $builder, array $options)
  25. {
  26. $builder->prependClientTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']));
  27. }
  28. public function getDefaultOptions()
  29. {
  30. return array(
  31. 'model_manager' => null,
  32. 'class' => null,
  33. 'parent' => 'hidden',
  34. );
  35. }
  36. public function getParent(array $options)
  37. {
  38. return $options['parent'];
  39. }
  40. public function getName()
  41. {
  42. return 'sonata_type_model_reference';
  43. }
  44. }