This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Form
Fabien Potencier 31fb219896 feature #34550 [Form] Added an AbstractChoiceLoader to simplify implementations and handle global optimizations (HeahDude)
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
-------

1394df2dea [Form] Added an AbstractChoiceLoader to simplify implementations and handle global optimizations
2020-02-12 20:40:35 +01:00
..
ChoiceList [Form] Added an AbstractChoiceLoader to simplify implementations and handle global optimizations 2020-02-10 00:49:37 +01:00
Command minor #33709 Add types to constructors and private/final/internal methods (Batch II) (derrabus) 2019-10-03 13:24:15 +02:00
Console Allow setting one info message per option 2020-02-09 19:42:47 -05:00
DependencyInjection Merge branch '4.4' 2019-10-07 11:06:09 +02:00
Event Make dispatched events really final 2019-09-06 22:41:54 +02:00
Exception [Form] TransformationFailedException: Support specifying message to display 2019-03-26 22:35:30 +01:00
Extension Leverage trigger_deprecation() from symfony/deprecation-contracts 2020-02-08 15:04:50 +01:00
Guess
Resources fix Danish translations 2019-08-09 11:35:22 +02:00
Test Merge branch '3.4' into 4.3 2019-09-19 17:51:53 +02:00
Tests Allow setting one info message per option 2020-02-09 19:42:47 -05:00
Util Merge branch '4.4' 2019-08-22 15:39:30 +02:00
.gitattributes Add .gitignore to .gitattributes 2019-10-12 01:35:04 +01:00
.gitignore
AbstractExtension.php Merge branch '4.4' 2019-08-20 16:46:00 +02:00
AbstractRendererEngine.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
AbstractType.php Fix CS 2020-02-04 09:04:52 +01:00
AbstractTypeExtension.php Fix CS 2020-02-04 10:32:40 +01:00
Button.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
ButtonBuilder.php [Form] Add "is empty callback" to form config 2020-02-03 18:27:57 +01:00
ButtonTypeInterface.php
CallbackTransformer.php Merge branch '3.4' into 4.2 2019-04-06 15:51:08 +02:00
CHANGELOG.md [Form] Added an AbstractChoiceLoader to simplify implementations and handle global optimizations 2020-02-10 00:49:37 +01:00
ClearableErrorsInterface.php [Form] Add ability to clear form errors 2018-06-25 11:51:51 +02:00
ClickableInterface.php
composer.json feature #35400 [RFC][DX][OptionsResolver] Allow setting info message per option (yceruto) 2020-02-10 09:05:33 +01:00
DataMapperInterface.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
DataTransformerInterface.php [Form] various minor fixes 2019-04-06 15:44:06 +02:00
Form.php Leverage trigger_deprecation() from symfony/deprecation-contracts 2020-02-08 15:04:50 +01:00
FormBuilder.php Merge branch '4.4' 2019-08-22 15:39:30 +02:00
FormBuilderInterface.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
FormConfigBuilder.php [Form] Add "is empty callback" to form config 2020-02-03 18:27:57 +01:00
FormConfigBuilderInterface.php [Form] Add "is empty callback" to form config 2020-02-03 18:27:57 +01:00
FormConfigInterface.php [Form] Add "is empty callback" to form config 2020-02-03 18:27:57 +01:00
FormError.php Merge branch '4.4' 2019-08-26 11:05:36 +02:00
FormErrorIterator.php Remove unneeded phpdocs 2019-08-08 11:37:48 +02:00
FormEvent.php Merge branch '4.4' 2019-08-08 11:49:33 +02:00
FormEvents.php Merge branch '4.2' 2019-04-06 16:04:46 +02:00
FormExtensionInterface.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
FormFactory.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
FormFactoryBuilder.php Merge branch '4.4' 2019-08-19 12:49:00 +02:00
FormFactoryBuilderInterface.php
FormFactoryInterface.php Merge branch '4.4' 2019-08-14 14:45:29 +02:00
FormInterface.php Merge branch '4.4' 2019-08-27 09:26:46 +02:00
FormRegistry.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
FormRegistryInterface.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
FormRenderer.php Merge branch '4.4' 2019-10-07 11:06:09 +02:00
FormRendererEngineInterface.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
FormRendererInterface.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
Forms.php Merge branch '4.2' 2019-04-07 15:57:40 +02:00
FormTypeExtensionInterface.php Merge branch '4.4' 2019-08-08 11:49:33 +02:00
FormTypeGuesserChain.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
FormTypeGuesserInterface.php add parameter type declarations where possible 2019-07-27 07:59:27 +02:00
FormTypeInterface.php Remove unneeded phpdocs 2019-08-08 11:37:48 +02:00
FormView.php switched array() to [] 2019-01-16 10:39:14 +01:00
LICENSE Update year in license files 2020-01-01 12:03:25 +01:00
NativeRequestHandler.php Turned return type annotations of private methods into php return types. 2019-08-07 16:19:54 +02:00
phpunit.xml.dist Bump phpunit XSD version to 5.2 2018-11-11 12:18:13 +01:00
PreloadedExtension.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
README.md Update links to documentation 2020-01-04 13:05:51 +01:00
RequestHandlerInterface.php Remove unneeded phpdocs 2019-08-08 11:37:48 +02:00
ResolvedFormType.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
ResolvedFormTypeFactory.php
ResolvedFormTypeFactoryInterface.php Remove superfluous phpdoc tags 2019-08-14 13:59:53 +02:00
ResolvedFormTypeInterface.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
ReversedTransformer.php
SubmitButton.php [Form] Add parameter type declarations 2019-08-13 09:00:05 +02:00
SubmitButtonBuilder.php
SubmitButtonTypeInterface.php

Form Component

The Form component allows you to easily create, process and reuse HTML forms.

Resources