@param OptionsResolver $resolver

@throws \Exception
485461
public function configureOptions(OptionsResolver $resolver)
    {
        $this->fixDoctrineQueryBuilderNormalizer($resolver);

        $queryBuilder = function (EntityRepository $repository, $options) {
            $qb = $repository->createQueryBuilder('d');
            if (!empty($options['allowed_families'])) {
                /** @var FamilyInterface[] $families */
                $families = $options['allowed_families'];
                $familyCodes = [];
                foreach ($families as $family) {
                    $familyCodes[] = $family->getCode();
                }

                $qb
                    ->andWhere('d.family IN (:allowedFamilies)')
                    ->setParameter('allowedFamilies', $familyCodes);
            }
            $qb->setMaxResults($options['max_results']);

            return $qb;
        };

        $resolver->setDefaults(
            [
                'em' => $this->entityManager,
                'class' => $this->dataClass,
                'query_builder' => $queryBuilder,
                'max_results' => 100,
            ]
        );

        $this->allowedFamiliesOptionConfigurator->configureOptions($resolver);
    }
284293
protected function configureOptions(OptionsResolver $resolver)
    {
        $resolver->remove(['depth', 'parent_location_id', 'subtree']);
        $resolver->setRequired('location');
        $resolver->setAllowedTypes('location', SiteLocation::class);

        $resolver->setDefault('sort', function (Options $options) {
            /** @var \Netgen\EzPlatformSiteApi\API\Values\Location $location */
            $location = $options['location'];
            return $location->innerLocation->getSortClauses();
        });
    }
755930
private function configureLogProperties(OptionsResolver $resolver)
    {
        $resolver->setDefined('redirect_stderr')
            ->setAllowedTypes('redirect_stderr', 'bool');

        $this->configureStdoutLogProperties($resolver);
        $this->configureStderrLogProperties($resolver);
    }
1304206
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'hierarchy' => $this->roleHierarchy->getTreeHierarchy(),
                'required' => false,
            ]
        );
        $resolver->setNormalizer(
            'hierarchy',
            function (Options $options, $value) {
                $error = "'hierarchy' option must be a LeafRole or an array of LeafRole";
                if (!$value instanceof \Traversable && !$value instanceof LeafRole) {
                    throw new \UnexpectedValueException($error);
                }
                if (\is_array($value) || $value instanceof \Traversable) {
                    /** @var array $value */
                    foreach ($value as $item) {
                        if (!$item instanceof LeafRole) {
                            throw new \UnexpectedValueException($error);
                        }
                    }
                }

                return $value;
            }
        );
    }
1130566
protected function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'host' => 'localhost',
            'version' => 3,
            'connection_string' => null,
            'encryption' => 'none',
            'options' => [],
        ]);

        $resolver->setDefault('port', function (Options $options) {
            return 'ssl' === $options['encryption'] ? 636 : 389;
        });

        $resolver->setDefault('connection_string', function (Options $options) {
            return sprintf('ldap%s://%s:%s', 'ssl' === $options['encryption'] ? 's' : '', $options['host'], $options['port']);
        });

        $resolver->setAllowedTypes('host', 'string');
        $resolver->setAllowedTypes('port', 'numeric');
        $resolver->setAllowedTypes('connection_string', 'string');
        $resolver->setAllowedTypes('version', 'numeric');
        $resolver->setAllowedValues('encryption', ['none', 'ssl', 'tls']);
        $resolver->setAllowedTypes('options', 'array');
    }
429671
public function configureOptions(OptionsResolver $resolver)
    {
        $multiLanguagesChoiceManage = $this->multiLanguagesChoiceManager;
        $resolver->setDefaults(
            array(
                'multiple' => true,
                'expanded' => true,
                'required' => false,
                'class' => $this->workflowFunctionClass,
                'choice_label' => function (WorkflowFunctionInterface $choice) use ($multiLanguagesChoiceManage) {
                    return $multiLanguagesChoiceManage->choose($choice->getNames());
                },
            )
        );
    }
385526
private function configureStderrLogProperties(OptionsResolver $resolver)
    {
        $resolver
            ->setDefined('stderr_logfile')
            ->setAllowedTypes('stderr_logfile', 'string');

        $resolver->setDefined('stderr_logfile_maxbytes');
        $this->configureByteProperty('stderr_logfile_maxbytes', $resolver);

        $resolver->setDefined('stderr_logfile_backups')
            ->setAllowedTypes('stderr_logfile_backups', 'int');

        $resolver->setDefined('stderr_capture_maxbytes');
        $this->configureByteProperty('stderr_capture_maxbytes', $resolver);

        $resolver->setDefined('stderr_events_enabled')
            ->setAllowedTypes('stderr_events_enabled', 'bool');

        $resolver->setDefined('stderr_syslog')
            ->setAllowedTypes('stderr_syslog', 'bool');
    }
793420
public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        
        $defaultConfigs = array(
            'showOn' => 'button',
            'buttonImageOnly' => true,
        );
        
        $resolver->setDefaults(array(
            'input' => 'datetime',
            'format' => 'Y-m-d',
            'date_timezone' => null,
            'user_timezone' => null,
            'translation_domain' => 'ThraceFormBundle',
            'configs' => $defaultConfigs,
    
        ));
        
        $resolver->setNormalizers(array(
            'format' => function (Options $options, $value) {
                return 'Y-m-d';
            },
            'configs' => function (Options $options, $value) use ($defaultConfigs) {
                $configs = array_replace_recursive($defaultConfigs, $value);
                
                $configs['dateFormat'] = 'yy-mm-dd';
                
                return $configs;
            }
        ));

        $resolver->setAllowedValues(array(
            'input' => array(
                'datetime',
                'string',
                'timestamp',
                'array',
            )   
        ));
    }
573364
private function configureStartControlProperties(OptionsResolver $resolver)
    {
        $resolver->setDefined('autostart');
        $this->configureBooleanProperty('autostart', $resolver);


        $resolver
            ->setDefined('autorestart')
            ->setAllowedTypes('autorestart', ['bool', 'string'])
            ->setAllowedValues('autorestart', [true, false, 'true', 'false', 'unexpected'])
            ->setNormalizer('autorestart', function (Options $options, $value) {
                return (is_bool($value) or $value === 'unexpected') ? $value : ($value === 'true' ? true : false);
            });

        $resolver->setDefined('startsecs');
        $this->configureIntegerProperty('startsecs', $resolver);

        $resolver->setDefined('startretries');
        $this->configureIntegerProperty('startretries', $resolver);
    }
416607
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setRequired(
            [
                'admin_action',
            ]
        );
        $resolver->setAllowedTypes('admin_action', ['string', Action::class]);
        $resolver->setDefaults(
            [
                'admin' => null,
            ]
        );
        $resolver->setAllowedTypes('admin', ['NULL', 'string', Admin::class]);
        $resolver->setNormalizer(
            'admin',
            function (Options $options, $value) {
                if ($value instanceof Admin) {
                    return $value;
                }
                if (null === $value) {
                    return $this->adminRegistry->getCurrentAdmin();
                }

                return $this->adminRegistry->getAdmin($value);
            }
        );
        $resolver->setNormalizer(
            'admin_action',
            function (Options $options, $value) {
                /** @var Admin $admin */
                $admin = $options['admin'];

                if ($value instanceof Action) {
                    if ($value->getAdmin() !== $admin) {
                        throw new \LogicException(
                            "Wrong Admin for Action {$value->getCode()}: {$value->getAdmin()->getCode()}"
                        );
                    }

                    return $value;
                }

                return $admin->getAction($value);
            }
        );
        $resolver->setNormalizer(
            'uri',
            function (Options $options, $value) {
                if (null === $value) {
                    return $this->adminRouter->generateAdminPath(
                        $options['admin'],
                        $options['admin_action']->getCode(),
                        $options['route_parameters']
                    );
                }

                return $value;
            }
        );
    }
1129348
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver
            ->setDefaults([
                // enable or disable extra configuration listener
                'enable_extra_configuration' => true,
                'enable_security' => true,
                'enable_menus' => true,
                'enable_homepage' => true,
                'translation' => false,
                'translation_pattern' => false,
                'title' => 'AdminBundle application',
                'description' => '',
                'locale' => 'en',
                // Main base template as bundles are not loaded when reading the configuration, the kernel
                // locateResources will always failed. So we must not check resource existence here.
                'base_template' => '@LAGAdmin/base.html.twig',
                'block_template' => '@LAGAdmin/Form/fields.html.twig',
                'menu_template' => '@LAGAdmin/Menu/menu.html.twig',
                'list_template' => '@LAGAdmin/CRUD/list.html.twig',
                'edit_template' => '@LAGAdmin/CRUD/edit.html.twig',
                'create_template' => '@LAGAdmin/CRUD/create.html.twig',
                'delete_template' => '@LAGAdmin/CRUD/delete.html.twig',
                'homepage_template' => '@LAGAdmin/Pages/home.html.twig',
                'homepage_route' => 'lag.admin.homepage',
                'routing_url_pattern' => '/{admin}/{action}',
                'routing_name_pattern' => 'lag.admin.{admin}.{action}',
                'bootstrap' => true,
                'date_format' => 'Y/m/d',
                'pager' => 'pagerfanta',
                // string length before truncation (0 means no truncation)
                'string_length' => 200,
                'string_length_truncate' => '...',
                'max_per_page' => 20,
                'admin_class' => Admin::class,
                'action_class' => Action::class,
                'permissions' => 'ROLE_ADMIN',
                'page_parameter' => 'page',
            ])
            ->setAllowedTypes('enable_extra_configuration', 'boolean')
            ->setAllowedTypes('enable_security', 'boolean')
            ->setAllowedTypes('enable_menus', 'boolean')
            ->setAllowedTypes('title', 'string')
            ->setAllowedTypes('description', 'string')
            ->setAllowedTypes('locale', 'string')
            ->setAllowedTypes('base_template', 'string')
            ->setAllowedTypes('block_template', 'string')
            ->setAllowedTypes('bootstrap', 'boolean')
            ->setAllowedTypes('date_format', 'string')
            ->setAllowedTypes('string_length', 'integer')
            ->setAllowedTypes('string_length_truncate', 'string')
            ->setAllowedTypes('max_per_page', 'integer')
            ->setAllowedTypes('admin_class', 'string')
            ->setAllowedTypes('routing_name_pattern', 'string')
            ->setAllowedTypes('routing_url_pattern', 'string')
            ->setAllowedTypes('page_parameter', 'string')
            ->setNormalizer('routing_name_pattern', function(Options $options, $value) {
                if (false === strstr($value, '{admin}')) {
                    throw new InvalidOptionsException(
                        'Admin routing configuration pattern name should contains the {admin} placeholder'
                    );
                }
                if (false === strstr($value, '{action}')) {
                    throw new InvalidOptionsException(
                        'Admin routing configuration pattern name should contains the {action} placeholder'
                    );
                }

                return $value;
            })
            ->setNormalizer('routing_url_pattern', function(Options $options, $value) {
                if (false === strstr($value, '{admin}')) {
                    throw new InvalidOptionsException('Admin routing configuration url pattern should contains {admin} placeholder');
                }

                if (false === strstr($value, '{action}')) {
                    throw new InvalidOptionsException('Admin routing configuration url pattern should contains the {action} placeholder');
                }

                return $value;
            })
        ;
        // admin field type mapping
        $this->setFieldsOptions($resolver);
    }
1223502
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setRequired(
            [
                'family',
            ]
        );
        $resolver->setAllowedTypes('family', ['string', FamilyInterface::class]);
        $resolver->setDefaults(
            [
                'repository' => null,
                'ignore_missing' => true,
            ]
        );
        $resolver->setAllowedTypes('repository', ['NULL', DataRepository::class]);
        $resolver->setAllowedTypes('ignore_missing', ['bool']);

        /** @noinspection PhpUnusedParameterInspection */
        $resolver->setNormalizer(
            'family',
            function (Options $options, $value) {
                if ($value instanceof FamilyInterface) {
                    return $value;
                }

                return $this->familyRegistry->getFamily($value);
            }
        );
        $resolver->setNormalizer(
            'repository',
            function (Options $options, $value) {
                if ($value instanceof DataRepository) {
                    return $value;
                }
                /** @var FamilyInterface $family */
                $family = $options['family'];

                return $this->entityManager->getRepository($family->getDataClass());
            }
        );
    }
800559
public function setCommonResolver($resolver)
    {
        if (!$resolver instanceof EventResolverInterface) {
            $this->commonResolver = $this->handleException(new InvalidServiceException(
                'Resolver Service must implement'.EventResolverInterface::class
            ));

            return;
        }

        $this->commonResolver = $resolver;
    }
455724
public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        
        $defaultConfigs = array(
            'width' => '300px',
            'allowClear' => true,  
        );
        
        $defaults = array(
            'multiple' => false,
            'expanded' => false,
            'empty_value' => 'select.empty_value',
            'translation_domain' => 'ThraceFormBundle',
            'configs' => $defaultConfigs
        );
        
        $normalizers = array(
            'expanded' => function (Options $options, $value) {
                return false;
            },           
            'configs' => function (Options $options, $value) use ($defaultConfigs) {
                $configs = array_replace_recursive($defaultConfigs, $value);
                
                $configs['placeholder'] = $options->get('empty_value');
                
                if(true === $options->get('multiple') && isset($configs['ajax'])){
                    $configs['multiple'] = true;
                }

                return $configs;
            }
        );
         
        $resolver->setDefaults($defaults);
        
        $resolver->setNormalizers($normalizers);
    }
941627
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'empty_data' => null,
                'data_class' => null,
                'attributes_config' => null,
                'merge_attributes_config' => false,
                'attribute' => null,
                'family' => null,
                'fieldset_options' => [],
            ]
        );
        $resolver->setAllowedTypes('attributes_config', ['NULL', 'array']);
        $resolver->setAllowedTypes('merge_attributes_config', ['bool']);
        $resolver->setAllowedTypes('attribute', ['NULL', AttributeInterface::class]);
        $resolver->setAllowedTypes('family', ['NULL', 'string', FamilyInterface::class]);
        $resolver->setAllowedTypes('fieldset_options', ['array']);

        $resolver->setNormalizer(
            'family',
            function (Options $options, $value) {
                // If family option is not set, try to fetch the family from the attribute option
                if (null === $value) {
                    /** @var AttributeInterface $attribute */
                    $attribute = $options['attribute'];
                    if (!$attribute) {
                        throw new MissingOptionsException(
                            "An option is missing: you must set either the 'family' option or the 'attribute' option"
                        );
                    }
                    $allowedFamilies = $attribute->getOption('allowed_families', []);
                    if (1 !== \count($allowedFamilies)) {
                        $m = "Can't automatically compute the 'family' option with an attribute with no family allowed";
                        $m .= " or multiple allowed families, please set the 'family' option manually";
                        throw new MissingOptionsException($m);
                    }

                    $value = reset($allowedFamilies);
                }

                if ($value instanceof FamilyInterface) {
                    return $value;
                }

                return $this->familyRegistry->getFamily($value);
            }
        );
        $resolver->setNormalizer(
            'empty_data',
            function (Options $options, $value) {
                if (null !== $value) {
                    return $value;
                }
                /** @var FamilyInterface $family */
                $family = $options['family'];

                if ($family->isSingleton()) {
                    /** @var DataRepository $repository */
                    $repository = $this->repositoryFinder->getRepository($family->getDataClass());

                    return $repository->getInstance($family);
                }

                return $family->createData();
            }
        );
        $resolver->setNormalizer(
            'data_class',
            function (Options $options, $value) {
                if (null !== $value) {
                    $m = "DataType form does not supports the 'data_class' option, it will be automatically resolved";
                    $m .= ' with the family';
                    throw new \UnexpectedValueException($m);
                }
                /** @var FamilyInterface $family */
                $family = $options['family'];

                return $family->getDataClass();
            }
        );
    }
1074065
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'choices' => null,
                'families' => null,
            ]
        );

        $resolver->setNormalizer(
            'families',
            function (Options $options, $values) {
                if (null === $values) {
                    $values = $this->familyRegistry->getFamilies();
                }
                $families = [];
                foreach ($values as $value) {
                    if (!$value instanceof FamilyInterface) {
                        $value = $this->familyRegistry->getFamily($value);
                    }
                    if ($value->isInstantiable()) {
                        $families[$value->getCode()] = $value;
                    }
                }

                return $families;
            }
        );
        $resolver->setNormalizer(
            'choices',
            function (Options $options, $value) {
                if (null !== $value) {
                    throw new \UnexpectedValueException(
                        "'choices' options is not supported for family selector, please use 'families' option"
                    );
                }
                $choices = [];
                /** @var FamilyInterface[] $families */
                $families = $options['families'];
                $duplicates = [];
                foreach ($families as $family) {
                    if ($family->isInstantiable()) {
                        $label = ucfirst($family);
                        if (array_key_exists($label, $choices)) {
                            // Storing duplicates
                            $duplicates[] = $label;
                            $label = "{$label} ({$family->getCode()})";
                        }
                        $choices[$label] = $family->getCode();
                    }
                }

                // Recreating duplicates
                foreach ($duplicates as $duplicate) {
                    $choices["{$duplicate} ({$choices[$duplicate]})"] = $choices[$duplicate];
                    unset($choices[$duplicate]);
                }
                ksort($choices);

                return $choices;
            }
        );
    }
240758
protected function configureOptions(OptionsResolver $resolver)
    {
        $resolver->remove(['parent_location_id', 'subtree']);
        $resolver->setRequired(['location']);
        $resolver->setDefined([
            'exclude_self',
            'relative_depth',
        ]);

        $resolver->setAllowedTypes('location', [SiteLocation::class]);
        $resolver->setAllowedTypes('exclude_self', ['bool']);
        $resolver->setAllowedTypes('relative_depth', ['int', 'array']);

        $resolver->setDefaults([
            'exclude_self' => true,
        ]);
    }