Configures the options for this type.

@param OptionsResolver $resolver The resolver for the options.
177552
public function configureOptions (OptionsResolver $resolver)
    {
        $allRoles = $this->roleCollection->getAllAvailableRoles();
        $allRoleKeys = array_keys($allRoles);

        $resolver->setDefaults([
            "roles_with_tags" => [],
            "choices" => function(Options $options) use ($allRoleKeys, $allRoles)
            {
                // if no tags are selected, just return all roles
                if (empty($options["roles_with_tags"]))
                {
                    return array_combine($allRoleKeys, $allRoleKeys);
                }

                // if tags are selected, only use the choices with the given tags
                $choices = [];

                foreach ($allRoles as $roleKey => $role)
                {
                    if (!empty(array_intersect($options["roles_with_tags"], $role->getTags())))
                    {
                        $choices[$roleKey] = $roleKey;
                    }
                }

                return $choices;
            },
            "choices_as_values" => true,
            "choice_label" => function ($choiceValue, $choiceKey, $index) use ($allRoles)
            {
                return $allRoles[$choiceKey]->getTitle();
            },
            "choice_attr" => function ($choiceValue, $choiceKey, $index) use ($allRoles)
            {
                return [
                    "data-role-description" => $allRoles[$choiceKey]->getDescription(),
                ];
            },
        ]);

        $resolver->setAllowedTypes("roles_with_tags", ["array"]);
    }
879147
public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver
            ->setRequired(array(
                'field'
            ))
            ->setOptional(array(
                'sobject_type',
                'fieldname',
                'recordtype_id'
            ))
            ->setDefaults(array(
                'recordtype_id' => null,
                'field' => $this->fieldOption,
                'sobject_type' => function(Options $options)
                {
                    return $options['field']->getSobjectType();
                },
                'fieldname' => function(Options $options)
                {
                    return $options['field']->getName();
                },
                'field_type' => function(Options $options)
                {
                    return $options['field']->getType();
                },
                'required' => function(Options $options, $previous)
                {
                    if(null !== ($req= $options['field']->getRequired()))
                    {
                        return $req;
                    }
                    return $previous;
                },
                'label' => function(Options $options, $previous)
                {
                    if(null !== ($label = $options['field']->getLabel()))
                    {
                        return $label;
                    }
                    return $previous;
                },
                'read_only' => function(Options $options, $previous)
                {
                    if(null !== ($readonly = $options['field']->getReadonly()))
                    {
                        return $readonly;
                    }
                    return $previous;
                }
            ));
    }
845849
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'widget' => 'single_text',
                'widget_position' => 'right',
                'html5' => false,
                'locale' => $this->locale,
                'format' => null,
                'date_type' => \IntlDateFormatter::SHORT,
                'time_type' => \IntlDateFormatter::SHORT,
            ]
        );
        $resolver->setNormalizer(
            'format',
            function (Options $options, $value) {
                if (null !== $value) {
                    return $value;
                }
                $locale = $options['locale'] ?: 'en';
                $formatter = \IntlDateFormatter::create(
                    $locale,
                    $options['date_type'],
                    $options['time_type']
                );

                return $formatter->getPattern();
            }
        );
    }
686187
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefault('synapse_form_options', array());

        $resolver->setDefined(array('synapse_theme'));
        $resolver->setNormalizer('synapse_theme', function (Options $options, $value) {
            switch (true) {
                case empty($value):
                    return $value;

                case $value instanceof Theme:
                    return $value;

                default:
                    if (!$theme = $this->themeLoader->retrieveByName($value)) {
                        throw new InvalidThemeException(sprintf(
                            'Theme "%s" not registered. Only %s are, check your configuration.',
                            $value,
                            $this->themeLoader->retrieveAll()->display('name')
                        ));
                    }

                    return $theme;
            }
        });
    }
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());
            }
        );
    }
1133786
protected function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'csrf_parameter' => '_csrf_token',
            'csrf_protection' => true,
            'collection_type' => FormCollectionInterface::COLLECTION_TYPE_ALL,
            'locale' => 'en_EN',
            'fallback_locales' => array('en_EN'),
            'translator_paths' => array(),
            'config_paths' => array(),
            'validation_groups' => null
        ));

        $resolver->setAllowedValues('collection_type', array(FormCollectionInterface::COLLECTION_TYPE_ALL, FormCollectionInterface::COLLECTION_TYPE_ANY, FormCollectionInterface::COLLECTION_TYPE_MANY, FormCollectionInterface::COLLECTION_TYPE_ONE));
    }
886093
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'auto_init' => true,
                'max_results' => 0,
                'choices' => [],
                'choice_loader' => null,
                'query_uri' => null,
            ]
        );

        $resolver->setNormalizer(
            'query_uri',
            function (Options $options, $value) {
                if (null !== $value) {
                    return $value;
                }
                /** @var AttributeInterface $attribute */
                $attribute = $options['attribute'];
                if (!$attribute) {
                    $allowedFamilies = $options['allowed_families'];
                    if (1 === \count($allowedFamilies)) {
                        try {
                            /** @var FamilyInterface $family */
                            $family = reset($allowedFamilies);

                            return $this->router->generate(
                                'sidus_autocomplete_api_family_search',
                                [
                                    'familyCode' => $family->getCode(),
                                ]
                            );
                        } catch (ExceptionInterface $e) {
                            throw new \RuntimeException('Unable to generate autocomplete route', 0, $e);
                        }
                    }

                    throw new UnexpectedValueException(
                        'Unable to generate API endpoint without an attribute option or a single allowed family'
                    );
                }
                $family = $attribute->getFamily();
                if (!$family) {
                    throw new UnexpectedValueException(
                        'Unable to generate API endpoint without an attribute option with a family'
                    );
                }
                try {
                    return $this->router->generate(
                        'sidus_autocomplete_api_attribute_search',
                        [
                            'attributePath' => $family->getCode().'.'.$attribute->getCode(),
                        ]
                    );
                } catch (ExceptionInterface $e) {
                    throw new \RuntimeException('Unable to generate autocomplete route', 0, $e);
                }
            }
        );
    }
938334
public function configureOptions(OptionsResolver $resolver)
    {
        // user can defined an admin name
        $resolver
            ->setDefault('admin', null)
            ->setDefault('action', null)
            ->setDefault('route', null)
            ->setDefault('url', null)
            ->setDefault('parameters', [])
            ->setDefault('text', '')
            ->setDefault('attr', [])
            ->setDefault('link_attr', [
                'class' => 'nav-link',
            ])
            ->setDefault('items', [])
            ->setDefault('icon', null)
            ->setDefault('link_css_class', 'nav-link')
            ->setNormalizer('admin', function(Options $options, $adminName) {
                // user has to defined either an admin name and an action name, or a route name with optional
                // parameters, or an url
                if (null === $adminName
                    && null === $options->offsetGet('route')
                    && null === $options->offsetGet('url')
                ) {
                    throw new InvalidOptionsException(
                        'You should either defined an admin name, or route name or an uri'
                    );
                }

                return $adminName;
            })
            // if an admin name is set, an action name can provided. This action will be the menu link
            ->setNormalizer('action', function(Options $options, $action) {
                // if an action name is provided, an admin name should be defined too
                if (null !== $action && null === $options->offsetGet('admin')) {
                    throw new InvalidOptionsException(
                        'You should provide an admin name for this action '.$action
                    );
                }

                // default to list action
                if (null !== $options->offsetGet('admin') && null === $action) {
                    $action = 'list';
                }

                return $action;
            })
            ->setAllowedTypes('parameters', 'array')
            ->setNormalizer('attr', function(Options $options, $attr) {
                if (!is_array($attr)) {
                    $attr = [];
                }

                if (empty($attr['id'])) {
                    $attr['id'] = uniqid('admin-menu-');
                }

                if ('horizontal' === $this->position && !key_exists('class', $attr)) {
                    $attr['class'] = 'nav-item';
                }

                return $attr;
            })
            ->setNormalizer('link_attr', function(Options $options, $value) {
                if (!is_array($value)) {
                    $value = [];
                }

                if (!key_exists('class', $value)) {
                    $value['class'] = 'nav-link';
                }

                return $value;
            })
            ->setNormalizer('items', function(Options $options, $items) {
                if (!is_array($items)) {
                    $items = [];
                }
                $resolver = new OptionsResolver();
                $resolvedItems = [];

                foreach ($items as $name => $item) {
                    $itemConfiguration = new MenuItemConfiguration($name, $this->position);
                    $itemConfiguration->configureOptions($resolver);
                    $itemConfiguration->setParameters($resolver->resolve($item));

                    $resolvedItems[$name] = $itemConfiguration;
                }

                return $resolvedItems;
            })
            ->setNormalizer('text', function(Options $options, $text) {
                if (!$text) {
                    // TODO use translation pattern key instead
                    $text = ucfirst($this->name);
                }

                return $text;
            })
        ;
    }
161840
protected function configureOptions(OptionsResolver $optionsResolver)
    {
        foreach ($this->constructorArgs as $name => $param) {
            if ($param->isOptional() && $param->isDefaultValueAvailable()) {
                $optionsResolver->setDefault($name, $param->getDefaultValue());
            } else {
                $optionsResolver->setRequired($name);
            }
        }
    }
1280465
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver
            ->setDefaults(array(
                'required'               => false,
                'data_extraction_method' => 'default',
                'reference_type'         => 'one',
                'reference_name'         => null,
            ))
            ->setRequired(array('reference_type'))
            ->setAllowedValues('data_extraction_method', array('default'))
            ->setAllowedValues('reference_type', array('one', 'many'))
        ;
    }
858717
public function configure(ResolverInterface $resolver): void
    {
        $resolver->type(Type::CALLABLE)
            ->validator(function (array $method) {
                return $this->validate($method);
            }, Type::ARRAY);
    }
584615
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver
            // filter option is required
            ->setRequired('filters')
            ->setAllowedTypes('filters', 'array')

            // sources is required and should be an array
            ->setRequired('sources')
            ->setAllowedTypes('sources', 'array')

            // destination should be a string, no array is allowed for now
            ->setRequired('destinations')
            ->setAllowedTypes('destinations', 'array')

            // debug mode (allow more verbosity)
            ->setDefault('debug', false)
            ->setAllowedTypes('debug', 'boolean')
        ;
    }
942351
private function configureStdoutLogProperties(OptionsResolver $resolver)
    {
        $resolver
            ->setDefined('stdout_logfile')
            ->setAllowedTypes('stdout_logfile', 'string');

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

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

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

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

        $resolver->setDefined('stdout_syslog')
            ->setAllowedTypes('stdout_syslog', 'bool');
    }
769854
public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        parent::setDefaultOptions($resolver);

        $resolver
            ->setDefaults(array(
                // ATOM/W3C
                'input' => 'string',
                'format' => \IntlDateFormatter::MEDIUM,
                'widget' => 'single_text'
        ));
    }
272380
protected function configureBaseOptions(OptionsResolver $resolver)
    {
        $resolver->setDefined([
            'content_type',
            'field',
            'publication_date',
            'section',
            'state',
        ]);
        $resolver->setDefaults([
            'sort' => [],
            'limit' => 25,
            'offset' => 0,
        ]);

        $resolver->setAllowedTypes('content_type', ['string', 'array']);
        $resolver->setAllowedTypes('section', ['string', 'array']);
        $resolver->setAllowedTypes('field', ['array']);
        $resolver->setAllowedTypes('limit', ['int']);
        $resolver->setAllowedTypes('offset', ['int']);
        $resolver->setAllowedTypes('publication_date', ['int', 'string', 'array']);
        $resolver->setAllowedTypes('state', ['array']);

        $identifierValuesCallback = function ($identifiers) {
            if (!is_array($identifiers)) {
                return true;
            }

            foreach ($identifiers as $identifier) {
                if (!is_string($identifier)) {
                    return false;
                }
            }

            return true;
        };

        $resolver->setAllowedValues('content_type', $identifierValuesCallback);
        $resolver->setAllowedValues('section', $identifierValuesCallback);
        $resolver->setAllowedValues(
            'publication_date',
            function ($dates) {
                if (!is_array($dates)) {
                    return true;
                }

                foreach ($dates as $date) {
                    if (!is_int($date) && !is_string($date)) {
                        return false;
                    }
                }

                return true;
            }
        );

        $class = SortClause::class;
        $resolver->setAllowedTypes('sort', ['string', $class, 'array']);
    }
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();
            }
        );
    }
132657
public function setDefaultOptions(OptionsResolver $resolver)
    {
        foreach ($this->middlewares as $middleware) {
            if ($middleware instanceof ConfigurableInterface) {
                $middleware->setDefaultOptions($resolver);
            }
        }
    }