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