31fb219896
This PR was merged into the 5.1-dev branch.
Discussion
----------
[Form] Added an AbstractChoiceLoader to simplify implementations and handle global optimizations
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | ~
| License | MIT
| Doc PR | ~
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.
Additionally (see https://symfony.com/roadmap):
- Always add tests and ensure they pass.
- Never break backward compatibility (see https://symfony.com/bc).
- Bug fixes must be submitted against the lowest maintained branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too.)
- Features and deprecations must be submitted against branch master.
-->
Taking over #33218 (taking over #30983)
The `ChoiceLoaderInterface` is not easy to understand/implement, while its goal is simple, lazy load an array of choices.
What may seem complicated is the how/what to optimize loading, we need to deal with a `$value` callback (which refers to the `choice_value` option allowing to transform a model choice to a unique string value that can be displayed/submitted).
We have now enough implementations in core to justify the need of an abstraction and provide a better DX in the process.
Before this PR we needed to implement 3 methods to create a loader:
- `loadChoiceList(?callable $value): ChoiceListInterface`
- `loadChoicesForValues(array $values, ?callable $value): array`
- `loadValuesForChoices(array $choices, ?callable $value): array`
and handle optimization, in each.
Now we only need to implement:
- `loadChoices(): iterable`
and optionnally:
- `doLoadChoicesForValues(array $values, ?callable $value): array`
if more optimization is needed to only load submitted values, (i.e the core intl loader prevents loading values that are the same as choices, and the doctrine one performs a `WHERE id IN ($ids)` query).
Commits
-------
|
||
---|---|---|
.. | ||
ChoiceList | ||
Command | ||
Console | ||
DependencyInjection | ||
Event | ||
Exception | ||
Extension | ||
Guess | ||
Resources | ||
Test | ||
Tests | ||
Util | ||
.gitattributes | ||
.gitignore | ||
AbstractExtension.php | ||
AbstractRendererEngine.php | ||
AbstractType.php | ||
AbstractTypeExtension.php | ||
Button.php | ||
ButtonBuilder.php | ||
ButtonTypeInterface.php | ||
CallbackTransformer.php | ||
CHANGELOG.md | ||
ClearableErrorsInterface.php | ||
ClickableInterface.php | ||
composer.json | ||
DataMapperInterface.php | ||
DataTransformerInterface.php | ||
Form.php | ||
FormBuilder.php | ||
FormBuilderInterface.php | ||
FormConfigBuilder.php | ||
FormConfigBuilderInterface.php | ||
FormConfigInterface.php | ||
FormError.php | ||
FormErrorIterator.php | ||
FormEvent.php | ||
FormEvents.php | ||
FormExtensionInterface.php | ||
FormFactory.php | ||
FormFactoryBuilder.php | ||
FormFactoryBuilderInterface.php | ||
FormFactoryInterface.php | ||
FormInterface.php | ||
FormRegistry.php | ||
FormRegistryInterface.php | ||
FormRenderer.php | ||
FormRendererEngineInterface.php | ||
FormRendererInterface.php | ||
Forms.php | ||
FormTypeExtensionInterface.php | ||
FormTypeGuesserChain.php | ||
FormTypeGuesserInterface.php | ||
FormTypeInterface.php | ||
FormView.php | ||
LICENSE | ||
NativeRequestHandler.php | ||
phpunit.xml.dist | ||
PreloadedExtension.php | ||
README.md | ||
RequestHandlerInterface.php | ||
ResolvedFormType.php | ||
ResolvedFormTypeFactory.php | ||
ResolvedFormTypeFactoryInterface.php | ||
ResolvedFormTypeInterface.php | ||
ReversedTransformer.php | ||
SubmitButton.php | ||
SubmitButtonBuilder.php | ||
SubmitButtonTypeInterface.php |
Form Component
The Form component allows you to easily create, process and reuse HTML forms.