Skip to content

Commit e5e9a5d

Browse files
committed
Add documentation for CallbackChoiceLoader
1 parent b06a83a commit e5e9a5d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

reference/forms/types/choice.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,19 @@ 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+
187200
.. include:: /reference/forms/types/options/choice_name.rst.inc
188201

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

0 commit comments

Comments
 (0)