Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load settings choices from database #40

Open
seydu opened this issue Aug 20, 2015 · 4 comments
Open

Load settings choices from database #40

seydu opened this issue Aug 20, 2015 · 4 comments
Milestone

Comments

@seydu
Copy link

seydu commented Aug 20, 2015

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 ?

@dmishh
Copy link
Collaborator

dmishh commented Aug 21, 2015

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

@seydu
Copy link
Author

seydu commented Aug 21, 2015

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.

@dmishh dmishh modified the milestone: 2.1 Aug 24, 2015
@rvanlaak
Copy link
Owner

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

@tcowin
Copy link

tcowin commented Jun 16, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants