/**
  * Constructor.
  *
  * @param EventDispatcherInterface   $dispatcher
  * @param RequestStack               $requestStack
  * @param RouterInterface            $router
  * @param string                     $type
  * @param int                        $defaultPageSize
  * @param ChoiceListFactoryInterface $choiceListFactory
  */
 public function __construct(EventDispatcherInterface $dispatcher, RequestStack $requestStack, RouterInterface $router, $type, $defaultPageSize = 10, ChoiceListFactoryInterface $choiceListFactory = null)
 {
     $this->dispatcher = $dispatcher;
     $this->requestStack = $requestStack;
     $this->router = $router;
     $this->type = $type;
     parent::__construct($defaultPageSize, $choiceListFactory);
 }
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('entry_type' => function (Options $options, $value) {
         return $options['select2']['enabled'] ? ChoiceType::class : $value;
     }, 'allow_add' => function (Options $options, $value) {
         return $options['select2']['enabled'] ? true : $value;
     }, 'allow_delete' => function (Options $options, $value) {
         return $options['select2']['enabled'] ? true : $value;
     }, 'prototype' => function (Options $options, $value) {
         return $options['select2']['enabled'] ? false : $value;
     }));
     $resolver->setNormalizer('prototype', function (Options $options, $value) {
         return $options['select2']['enabled'] ? false : $value;
     });
     $resolver->setNormalizer('entry_options', function (Options $options, $value) {
         if ($options['select2']['enabled']) {
             $value = array_merge($value, array('select2' => array_merge($options['select2'], array('tags' => $options['allow_add']))));
         }
         return $value;
     });
 }