CollectionType.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. public function setDefaultOptions(OptionsResolverInterface $resolver)
  32. {
  33. $resolver->setDefaults(array(
  34. 'modifiable' => false,
  35. 'type' => 'text',
  36. 'type_options' => array()
  37. ));
  38. }
  39. /**
  40. * {@inheritDoc}
  41. */
  42. public function getName()
  43. {
  44. return 'sonata_type_collection';
  45. }
  46. }