SettingsBundle icon indicating copy to clipboard operation
SettingsBundle copied to clipboard

Load settings choices from database

Open seydu opened this issue 9 years ago • 4 comments

I have a use case where putting the choices for a setting in the configuration files is not naturel. I have content stored in a database and users can select some items from this content and put it in their preferences.

The form type class Dmishh\Bundle\SettingsBundle\Form\Type/SettingsType builds choices from the configuration and I think it does not allow to provide choices from another source.

By design the Symfont Form Component does not allow to change form options after it has been built.

Letting dev provide the choices from another source would add more flexibilite and allow building more complex settings.

What about doing it using Symfony Event dispatcher ?

seydu avatar Aug 20 '15 18:08 seydu

It's a good idea, actually. But how do you imagine utilization of the Event Dispatcher for this task?

dmishh avatar Aug 21 '15 00:08 dmishh

I am thinking of creating a tag to handle event listener services. An event will be fired for each field options before building the form field.

In the meantime a have changed the SettingsType class to call call a method that provides the options. This allows child classes to provide the extra options. See feature-custom-form-options

This is enough for my use case. If there is a more global need for this kind of behaviour I will submit a PR for the event listeners.

seydu avatar Aug 21 '15 18:08 seydu

Symfony 2.7 improved the ChoiceType, so we could make use of the choice_loader to make the setting choices dynamic.

More info: http://symfony.com/blog/new-in-symfony-2-7-choice-form-type-refactorization

rvanlaak avatar Mar 12 '16 16:03 rvanlaak

I can envision using this database persistence for user preferences that would exist across sessions. Is there any expectation of a date for a 2.1 release?

tcowin avatar Jun 16 '16 17:06 tcowin