CollectionType.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\AbstractType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  15. use Sonata\AdminBundle\Form\EventListener\ResizeFormListener;
  16. class CollectionType extends AbstractType
  17. {
  18. /**
  19. * {@inheritDoc}
  20. */
  21. public function buildForm(FormBuilderInterface $builder, array $options)
  22. {
  23. $listener = new ResizeFormListener(
  24. $builder->getFormFactory(),
  25. $options['type'],
  26. $options['type_options'],
  27. $options['modifiable']
  28. );
  29. $builder->addEventSubscriber($listener);
  30. }
  31. /**
  32. * {@inheritDoc}
  33. */
  34. public function setDefaultOptions(OptionsResolverInterface $resolver)
  35. {
  36. $resolver->setDefaults(array(
  37. 'modifiable' => false,
  38. 'type' => 'text',
  39. 'type_options' => array(),
  40. ));
  41. }
  42. /**
  43. * {@inheritDoc}
  44. */
  45. public function getName()
  46. {
  47. return 'sonata_type_collection';
  48. }
  49. }