123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- /*
- * This file is part of the Sonata Project package.
- *
- * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Sonata\AdminBundle\Form\Type;
- use Symfony\Component\Form\AbstractType;
- use Symfony\Component\Form\FormInterface;
- use Symfony\Component\Form\FormView;
- use Symfony\Component\OptionsResolver\OptionsResolver;
- use Symfony\Component\OptionsResolver\OptionsResolverInterface;
- /**
- * Class ChoiceFieldMaskType.
- *
- * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
- */
- class ChoiceFieldMaskType extends AbstractType
- {
- /**
- * {@inheritdoc}
- */
- public function buildView(FormView $view, FormInterface $form, array $options)
- {
- $allFieldNames = array();
- foreach ($options['map'] as $value => $fieldNames) {
- foreach ($fieldNames as $fieldName) {
- $allFieldNames[$fieldName] = $fieldName;
- }
- }
- $allFieldNames = array_values($allFieldNames);
- $view->vars['all_fields'] = $allFieldNames;
- $view->vars['map'] = $options['map'];
- $options['expanded'] = false;
- parent::buildView($view, $form, $options);
- }
- /**
- * {@inheritdoc}
- *
- * @todo Remove it when bumping requirements to SF 2.7+
- */
- public function setDefaultOptions(OptionsResolverInterface $resolver)
- {
- $this->configureOptions($resolver);
- }
- /**
- * {@inheritdoc}
- */
- public function configureOptions(OptionsResolver $resolver)
- {
- // TODO: Remove conditional parent call when bumping requirements to SF 2.7+
- if (method_exists('Symfony\Component\Form\AbstractType', 'configureOptions')) {
- parent::configureOptions($resolver);
- } else {
- parent::setDefaultOptions($resolver);
- }
- $resolver->setDefaults(array(
- 'map' => array(),
- ));
- }
- /**
- * {@inheritdoc}
- */
- public function getParent()
- {
- return 'choice';
- }
- /**
- * {@inheritdoc}
- *
- * @todo Remove when dropping Symfony <2.8 support
- */
- public function getName()
- {
- return $this->getBlockPrefix();
- }
- /**
- * {@inheritdoc}
- */
- public function getBlockPrefix()
- {
- return 'sonata_type_choice_field_mask';
- }
- }
|