Skip to content

ChoiceType choice_loader option example incorrect #20395

@Thorry84

Description

@Thorry84

On this page: https://symfony.com/doc/current/reference/forms/types/choice.html#reference-form-choice-loader

The following example is seen:

            'choice_loader' => function (Options $options): ChoiceLoaderInterface {
                return ChoiceList::loader(
                    // pass the instance of the type or type extension which is
                    // currently configuring the choice list as first argument
                    $this,
                    // pass the other option to the loader
                    new CustomChoiceLoader($options['some_key']),
                    // ensure the type stores a loader per key
                    // by using the special third argument "$vary"
                    // an array containing anything that "changes" the loader
                    [$options['some_key']]
                );
            },

However it hasn't been possible to pass a Closure to the option choice_loader for some time now.
https://github.com/symfony/symfony/blob/4e1cf89449edfe2ac18ac5688e174a16f290bfe1/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php#L371
The allowed options are 'null', ChoiceLoaderInterface::class, ChoiceLoader::class

The example should probably be updated to the current syntax.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions