CollectionType.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Form\FormInterface;
  15. use Symfony\Component\Form\FormView;
  16. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  17. use Sonata\AdminBundle\Form\EventListener\ResizeFormListener;
  18. class CollectionType extends AbstractType
  19. {
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public function buildForm(FormBuilderInterface $builder, array $options)
  24. {
  25. $listener = new ResizeFormListener(
  26. $builder->getFormFactory(),
  27. $options['type'],
  28. $options['type_options'],
  29. $options['modifiable']
  30. );
  31. $builder->addEventSubscriber($listener);
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function buildView(FormView $view, FormInterface $form, array $options)
  37. {
  38. $view->vars['btn_add'] = $options['btn_add'];
  39. $view->vars['btn_catalogue'] = $options['btn_catalogue'];
  40. }
  41. /**
  42. * {@inheritDoc}
  43. */
  44. public function setDefaultOptions(OptionsResolverInterface $resolver)
  45. {
  46. $resolver->setDefaults(array(
  47. 'modifiable' => false,
  48. 'type' => 'text',
  49. 'type_options' => array(),
  50. 'btn_add' => 'link_add',
  51. 'btn_catalogue' => 'SonataAdminBundle'
  52. ));
  53. }
  54. /**
  55. * {@inheritDoc}
  56. */
  57. public function getName()
  58. {
  59. return 'sonata_type_collection';
  60. }
  61. }