From e5e9a5d2006b958e046d62b8064e746018b2f02f Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Sat, 3 Dec 2016 14:59:27 +0100 Subject: [PATCH 1/3] Add documentation for CallbackChoiceLoader --- reference/forms/types/choice.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index 80622a9ced3..b436a94c364 100644 --- a/reference/forms/types/choice.rst +++ b/reference/forms/types/choice.rst @@ -184,6 +184,19 @@ The ``choice_loader`` can be used to only partially load the choices in cases wh a fully-loaded list is not necessary. This is only needed in advanced cases and would replace the ``choices`` option. +You can use an instance of :class:`Symfony\\Component\\Form\\ChoiceList\\Loader\\CallbackChoiceLoader` +if you want to take advantage of lazy loading:: + + use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader; + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('constants', ChoiceType::class, array( + 'choice_loader' => new CallbackChoiceLoader(function() { + return StaticClass::getConstants(); + }, + )); + .. include:: /reference/forms/types/options/choice_name.rst.inc .. include:: /reference/forms/types/options/choice_translation_domain.rst.inc From 731617f6c7328f4488f64e6db6403cde9e6d63fc Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Sat, 3 Dec 2016 15:46:23 +0100 Subject: [PATCH 2/3] Clearify behaviour of CallbackChoiceLoader --- reference/forms/types/choice.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index b436a94c364..ab05e18c8e1 100644 --- a/reference/forms/types/choice.rst +++ b/reference/forms/types/choice.rst @@ -197,6 +197,14 @@ if you want to take advantage of lazy loading:: }, )); +This will cause the call of ``StaticClass::getConstants()`` to not happen if the request is redirected +and if there is no pre set or submitted data. Otherwise the choice options would need to be resolved thus +triggering the callback. + +.. versionadded:: 3.2 + The ability to use an instance of :class:`Symfony\\Component\\Form\\ChoiceList\\Loader\\CallbackChoiceLoader` + has been introduced in Symfony 3.2 + .. include:: /reference/forms/types/options/choice_name.rst.inc .. include:: /reference/forms/types/options/choice_translation_domain.rst.inc From 58386354fa0a0bff20ee15186522ebff97ee1ef5 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 5 Dec 2016 12:59:22 +0100 Subject: [PATCH 3/3] Make lines shorter to comply with 80-char limit --- reference/forms/types/choice.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index ab05e18c8e1..03a5b660bfa 100644 --- a/reference/forms/types/choice.rst +++ b/reference/forms/types/choice.rst @@ -197,13 +197,13 @@ if you want to take advantage of lazy loading:: }, )); -This will cause the call of ``StaticClass::getConstants()`` to not happen if the request is redirected -and if there is no pre set or submitted data. Otherwise the choice options would need to be resolved thus -triggering the callback. +This will cause the call of ``StaticClass::getConstants()`` to not happen if the +request is redirected and if there is no pre set or submitted data. Otherwise +the choice options would need to be resolved thus triggering the callback. .. versionadded:: 3.2 The ability to use an instance of :class:`Symfony\\Component\\Form\\ChoiceList\\Loader\\CallbackChoiceLoader` - has been introduced in Symfony 3.2 + was introduced in Symfony 3.2 .. include:: /reference/forms/types/options/choice_name.rst.inc