8000 feature #7219 Add documentation for CallbackChoiceLoader (sawmurai, j… · matthieu88160/symfony-docs@dc8c0f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit dc8c0f3

Browse files
committed
feature symfony#7219 Add documentation for CallbackChoiceLoader (sawmurai, javiereguiluz)
This PR was merged into the 3.2 branch. Discussion ---------- Add documentation for CallbackChoiceLoader PR for symfony#7181 Commits ------- 5838635 Make lines shorter to comply with 80-char limit 731617f Clearify behaviour of CallbackChoiceLoader e5e9a5d Add documentation for CallbackChoiceLoader
2 parents c4a5ed6 + 5838635 commit dc8c0f3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

reference/forms/types/choice.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,27 @@ The ``choice_loader`` can be used to only partially load the choices in cases wh
184184
a fully-loaded list is not necessary. This is only needed in advanced cases and
185185
would replace the ``choices`` option.
186186

187+
You can use an instance of :class:`Symfony\\Component\\Form\\ChoiceList\\Loader\\CallbackChoiceLoader`
188+
if you want to take advantage of lazy loading::
189+
190+
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
191+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
192+
// ...
193+
194+
$builder->add('constants', ChoiceType::class, array(
195+
'choice_loader' => new CallbackChoiceLoader(function() {
196+
return StaticClass::getConstants();
197+
},
198+
));
199+
200+
This will cause the call of ``StaticClass::getConstants()`` to not happen if the
201+
request is redirected and if there is no pre set or submitted data. Otherwise
202+
the choice options would need to be resolved thus triggering the callback.
203+
204+
.. versionadded:: 3.2
205+
The ability to use an instance of :class:`Symfony\\Component\\Form\\ChoiceList\\Loader\\CallbackChoiceLoader`
206+
was introduced in Symfony 3.2
207+
187208
.. include:: /reference/forms/types/options/choice_name.rst.inc
188209

189210
.. include:: /reference/forms/types/options/choice_translation_domain.rst.inc

0 commit comments

Comments
 (0)
0