Where should widgets store user data?

I’m building a little panel widget to locate placeholder content on a website. Right now, it pulls from an array or lorem-ipsum-esque strings that I’ve hardcoded in the plugin, but I was thinking that it would be pretty neat if I could have a way to manipulate that list from the widget UI itself.

But that raises an interesting question: Where should a plugin store user-entered permanent data? One obvious solution would be to have the developer modify the widget data via the config file, but there are use-cases where a user/editor may need to modify a widget’s settings, and they obviously have no access to the codebase.


I would probably use c::set(), even if it’s not in the configuration file your widget can get configuration values :slight_smile:

1 Like

You could store the settings in the site settings, using a field name that will definitely not be used by the site.

In your config:

c::set('some.widget.setting', site()->someWeirdFieldName());

In your plugin:

c::get('some.widget.setting', 'someDefaultValue');
1 Like