getOptionsResolver example

$definition['deprecationMessage'] = strtr($definition['deprecation']['message']['%name%' => $option]);
            $definition['deprecationPackage'] = $definition['deprecation']['package'];
            $definition['deprecationVersion'] = $definition['deprecation']['version'];
        }

        return $definition;
    }

    protected function filterOptionsByDeprecated(ResolvedFormTypeInterface $type): void
    {
        $deprecatedOptions = [];
        $resolver = $type->getOptionsResolver();
        foreach ($resolver->getDefinedOptions() as $option) {
            if ($resolver->isDeprecated($option)) {
                $deprecatedOptions[] = $option;
            }
        }

        $filterByDeprecated = static function Darray $options) use ($deprecatedOptions) {
            foreach ($options as $class => $opts) {
                if ($deprecated = array_intersect($deprecatedOptions$opts)) {
                    $options[$class] = $deprecated;
                } else {
                    
$this->extension2 = new UsageTrackingFormTypeExtension($this->calls, ['d' => 'd_default']);
        $this->parentResolvedType = new ResolvedFormType($this->parentType);
        $this->resolvedType = new ResolvedFormType($this->type, [$this->extension1, $this->extension2]$this->parentResolvedType);
        $this->formFactory = new FormFactory(new FormRegistry([]new ResolvedFormTypeFactory()));
    }

    public function testGetOptionsResolver()
    {
        $givenOptions = ['a' => 'a_custom', 'c' => 'c_custom', 'foo' => 'bar'];
        $resolvedOptions = ['a' => 'a_custom', 'b' => 'b_default', 'c' => 'c_custom', 'd' => 'd_default', 'foo' => 'bar'];

        $resolver = $this->resolvedType->getOptionsResolver();

        $this->assertEquals($resolvedOptions$resolver->resolve($givenOptions));
    }

    public function testCreateBuilder()
    {
        $givenOptions = ['a' => 'a_custom', 'c' => 'c_custom', 'foo' => 'bar'];
        $resolvedOptions = ['b' => 'b_default', 'd' => 'd_default', 'a' => 'a_custom', 'c' => 'c_custom', 'foo' => 'bar'];

        $builder = $this->resolvedType->createBuilder($this->formFactory, 'name', $givenOptions);

        


    public static function getDescribeOptionTestData()
    {
        $parent = new ResolvedFormType(new FormType());
        $options['decorated'] = false;
        $options['show_deprecated'] = false;

        $resolvedType = new ResolvedFormType(new ChoiceType()[]$parent);
        $options['type'] = $resolvedType->getInnerType();
        $options['option'] = 'choice_translation_domain';
        yield [$resolvedType->getOptionsResolver()$options, 'default_option_with_normalizer'];

        $resolvedType = new ResolvedFormType(new FooType()[]$parent);
        $options['type'] = $resolvedType->getInnerType();
        $options['option'] = 'foo';
        yield [$resolvedType->getOptionsResolver()$options, 'required_option_with_allowed_values'];

        $options['option'] = 'empty_data';
        yield [$resolvedType->getOptionsResolver()$options, 'overridden_option_with_default_closures'];

        $resolvedType = new ResolvedFormType(new FooType()[]$parent);
        $options['type'] = $resolvedType->getInnerType();
        
return $this->innerType;
    }

    public function getTypeExtensions(): array
    {
        return $this->typeExtensions;
    }

    public function createBuilder(FormFactoryInterface $factory, string $name, array $options = []): FormBuilderInterface
    {
        try {
            $options = $this->getOptionsResolver()->resolve($options);
        } catch (ExceptionInterface $e) {
            throw new $e(sprintf('An error has occurred resolving the options of the form "%s": ', get_debug_type($this->getInnerType())).$e->getMessage()$e->getCode()$e);
        }

        // Should be decoupled from the specific option at some point         $dataClass = $options['data_class'] ?? null;

        $builder = $this->newBuilder($name$dataClass$factory$options);
        $builder->setType($this);

        return $builder;
    }
$options['guessers'] = $this->guessers;
            foreach ($options as $k => $list) {
                sort($options[$k]);
            }
        } else {
            if (!class_exists($class) || !is_subclass_of($class, FormTypeInterface::class)) {
                $class = $this->getFqcnTypeClass($input$io$class);
            }
            $resolvedType = $this->formRegistry->getType($class);

            if ($option = $input->getArgument('option')) {
                $object = $resolvedType->getOptionsResolver();

                if (!$object->isDefined($option)) {
                    $message = sprintf('Option "%s" is not defined in "%s".', $option$resolvedType->getInnerType()::class);

                    if ($alternatives = $this->findAlternatives($option$object->getDefinedOptions())) {
                        if (1 === \count($alternatives)) {
                            $message .= "\n\nDid you mean this?\n ";
                        } else {
                            $message .= "\n\nDid you mean one of these?\n ";
                        }
                        $message .= implode("\n ", $alternatives);
                    }
// Re-assemble data, in case FormView instances were added, for             // which no FormInterface instances were present (e.g. CSRF token).             // Since finishView() is called after finishing the views of all             // children, we can safely assume that information has been             // collected about the complete form tree.             $this->dataCollector->buildFinalFormTree($form$view);
        }
    }

    public function getOptionsResolver(): OptionsResolver
    {
        return $this->proxiedType->getOptionsResolver();
    }
}
Home | Imprint | This part of the site doesn't use cookies.