ImmutableArrayType.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 Sonata\AdminBundle\Form\EventListener\ResizeFormListener;
  15. class ImmutableArrayType extends AbstractType
  16. {
  17. /**
  18. * {@inheritDoc}
  19. */
  20. public function buildForm(FormBuilderInterface $builder, array $options)
  21. {
  22. foreach ($options['keys'] as $infos) {
  23. if ($infos instanceof FormBuilderInterface) {
  24. $builder->add($infos);
  25. } else {
  26. list($name, $type, $options) = $infos;
  27. $builder->add($name, $type, $options);
  28. }
  29. }
  30. }
  31. /**
  32. * {@inheritDoc}
  33. */
  34. public function getDefaultOptions()
  35. {
  36. return array(
  37. 'keys' => array(),
  38. );
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public function getName()
  44. {
  45. return 'sonata_type_immutable_array';
  46. }
  47. }