ChoiceFieldMaskType.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\OptionsResolver\OptionsResolverInterface;
  14. use Symfony\Component\Form\FormInterface;
  15. use Symfony\Component\Form\FormView;
  16. class ChoiceFieldMaskType extends AbstractType
  17. {
  18. /**
  19. * {@inheritDoc}
  20. */
  21. public function buildView(FormView $view, FormInterface $form, array $options)
  22. {
  23. $allFieldNames = array();
  24. foreach ($options['map'] as $value => $fieldNames) {
  25. foreach ($fieldNames as $fieldName) {
  26. $allFieldNames[$fieldName] = $fieldName;
  27. }
  28. }
  29. $allFieldNames = array_values($allFieldNames);
  30. $view->vars['all_fields'] = $allFieldNames;
  31. $view->vars['map'] = $options['map'];
  32. $options['expanded'] = false;
  33. parent::buildView($view, $form, $options);
  34. }
  35. /**
  36. * {@inheritDoc}
  37. */
  38. public function setDefaultOptions(OptionsResolverInterface $resolver)
  39. {
  40. parent::setDefaultOptions($resolver);
  41. $resolver->setDefaults(array(
  42. 'map' => array(),
  43. ));
  44. }
  45. /**
  46. * {@inheritDoc}
  47. */
  48. public function getParent()
  49. {
  50. return 'choice';
  51. }
  52. /**
  53. * {@inheritDoc}
  54. */
  55. public function getName()
  56. {
  57. return 'sonata_type_choice_field_mask';
  58. }
  59. }