New Settings Framework
-
Since many plugin devs may not have noticed the new utility I recently added (PR) to the core that may be helpful to plugin devs, here a short brief:
I've added a new Settings-Framework that provides the possibility to save whole objects within the database (gets stringified behind the scene).
The object-structure gets updated whenever it and the version (provided within server-side constructor) change without any work on your side.
Related to the server-side settings-module you can refer to the single (nested) object-attributes within client-side ACP templates.
The new client-side settings-methods aresettings.sync
andsettings.persist
rather than the oldsettings.load
andsettings.save
(left there for backwards compatibility).
Build-in support for many input-types, arrays, selects, textareas, keyboard-keys but easy to expand with your own object-/input-types.If you come across an common used field-type you may create a new PR to get it into core
(e.g. radio-button support is missing I just realize)For a whole (at least more complete than above) overview about what I'm talking see the docs
As always you have the choice (except you're using windows ) to put your complaints below or at
/dev/null
-
Could this, in theory, be used to say, allow someone to pick their own theme
-
@a_5mith Nope It's just a more powerful way for plugin devs to save the admin-settings in database
-
@frissdiegurke Awhhh. Good job either way buddy.
-
Looks like I have a shitload of refactoring to do for the Shoutbox... Will start using this with the poll plugin though!
Any plugins that already utilize this new framework that I can "steal" from?
Edit: nvm, didn't scroll down far enough.
-
Hello @frissdiegurke,
I've implemented the "new" (I guess, 7 months late) Settings framework in my plugin, but I don't seem to have it working all the way. I know something has been saved to the DB because the panel for my the imgbed's settings reflects it, but I'm still getting default values when I try to pull them out with
settings.get()
For example:
Structure:var defaultSettings = { booleans: { hasMarkdown: true }, strings: { extensions: 'jpg,jpeg,gif,gifv,png,svg' } };
Save:
$('#save').click(function(event) { event.preventDefault(); // TODO clean and organize extensions settings.persist('imgbed', wrapper, function persistImgbed() { socket.emit('admin.settings.syncImgbed'); }) });
Call:
var userExt = settings.get().strings.extensions;
userExt still reflects the original defaults....
-
@BDHarrington7
If you're referring to the master-branch the problem is that you cache the value ofvar userExt = settings.get('strings.extensions');
(and some further operations) once at plugin-start and don't refresh those values after
settings.sync();
(within a callback).So you need to re-calculate the
regex
variable within a callback forsettings.sync
.