ImmutableArrayType.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\FormBuilder;
  14. use Sonata\AdminBundle\Form\EventListener\ResizeFormListener;
  15. class ImmutableArrayType extends AbstractType
  16. {
  17. public function buildForm(FormBuilder $builder, array $options)
  18. {
  19. foreach($options['keys'] as $infos) {
  20. if ($infos instanceof FormBuilder) {
  21. $builder->add($infos);
  22. } else {
  23. list($name, $type, $options) = $infos;
  24. $builder->add($name, $type, $options);
  25. }
  26. }
  27. }
  28. public function getDefaultOptions(array $options)
  29. {
  30. return array(
  31. 'keys' => array(),
  32. );
  33. }
  34. public function getName()
  35. {
  36. return 'sonata_type_immutable_array';
  37. }
  38. }