Plugin configuration: Empty Inputs

Creating and modifying plugins.
Post Reply
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Plugin configuration: Empty Inputs

Post by blog.brockha.us »

I came across a nasty habit of the plugin configuration. If I leave a configuration input empty and save it, it is saved as empty, but the input is filled after with the default value defined in the plugins code. This is very irritating, as I always thought, my empty value was not saved. First I thougt, Firefox is autofilling the empty values, but this value comes from the HTML code.

So it seems, Serendipity fills empty inputs with default values, no matter if the value is saved empty volitional, or if it is just not existing in the database (because it never was saved former). Only in the second case it should be filled with the default values.

You can reproduce this with the rss syndicate plugin i.e.: If you clear the last input (feedburner picture) it is saved empty but the input shows the default picture again after saving. So if I want to change a single setting I always have to remember to clear this input again before saving.
- Grischa Brockhaus - http://blog.brockha.us
- Want to make me happy? http://wishes.brockha.us/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Plugin configuration: Empty Inputs

Post by garvinhicking »

Hi!

Yes, that's an ugly glitch. It can't be really fixed in the core, because the 'empty' detection is required to see whether a default config value should be retrieved.

Instead, plugins should be crafted so that empty string values are not possible. Most plugins use "empty" or "none" as a string, if you want to remove a setting...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Re: Plugin configuration: Empty Inputs

Post by blog.brockha.us »

garvinhicking wrote:Yes, that's an ugly glitch. It can't be really fixed in the core, because the 'empty' detection is required to see whether a default config value should be retrieved.
Hmm? I don't get it yet. The default value is set by the core when loading from db, not by the plugin itself, isn't it? Why not use some kind of isset() instead of empty() here, while detecting, if the default value should be set or not? I didn't look into the code yet, so I'm just guessing at the moment..
- Grischa Brockhaus - http://blog.brockha.us
- Want to make me happy? http://wishes.brockha.us/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Plugin configuration: Empty Inputs

Post by garvinhicking »

Hi!

I can't tell that out of the top of my head. We've had problems like these in serendipity 0.5 or 0.6. A plugin should be usable also when the database column is not yet stored, and fetch default values.

I can only tell that changing the behaviour has a large trail of side-effects that all need to be considered. And sine we have no Unit tests, that would be a lot of work to stay backward compatible. :(

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Post by blog.brockha.us »

You mean: There may be plugins, that depend on it, that Serendipity loads default values if the user entered empty values? Phew.. That sounds very nasty, Plugins should do this on their own, if they dont want to have empty inputs..
- Grischa Brockhaus - http://blog.brockha.us
- Want to make me happy? http://wishes.brockha.us/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!
blog.brockha.us wrote:You mean: There may be plugins, that depend on it, that Serendipity loads default values if the user entered empty values? Phew.. That sounds very nasty, Plugins should do this on their own, if they dont want to have empty inputs..
No, it's hard to describe: I mean it might be that plugins do not load the default configuration if we add the isset() and empty() checks.

It should be very rare, that plugins should load a default value if the user explicitly configured a variable as empty. That'S fine. Only that the core need to fetch default values if the value is not configured needs to be properly coded.

If you don't save the configuration of a plugin, it should fetch default values to be able to work. A plugin shouldn't require a user to hit the 'Save configuration' button to get it to work.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Post by blog.brockha.us »

Well yes, I have the same opinion as you! Perhaps we should change to German email, it seems while writing English I'm not able to show you the point, I meen.. :-) (Whoa, this was bad English again.. ;-))
- Grischa Brockhaus - http://blog.brockha.us
- Want to make me happy? http://wishes.brockha.us/
Post Reply