Settings page integration

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Settings page integration
« on February 25th, 2012, 12:40 AM »
Had a random idea about this today. The plugin info file already lists all the $settings variables that a plugin uses (so that it can set defaults and clean up properly later) but I've been thinking about the interface side of things.

Right now, if a plugin wants to add a settings page, even a simple one, it's going to have to create a file, use at least two hooks[1] and create a stub file that is almost entirely identical from plugin to plugin. Heck, when I start a plugin now that uses a simple settings page, I just copy everything from an earlier one.

So, here's what I'm thinking. Everything that you would normally have to set up for a settings page ($config_vars etc.) can be streamlined. Of course, more complex plugins (of the likes of WedgeDesk) would still do their own thing, but the smaller stuff could be simplified.

For example, I have a stub plugin that will grow into a big scary share-topics-with-services monster, dubbed Flitter because it was originally just Facebook + Twitter. Right now, it's very straightforward however, with its settings page being:

Code: [Select]
$config_vars = array(
array('desc', 'flitter_desc'),
array('select', 'flitter_position', array('topic' => $txt['flitter_position_topic'], 'sidebar' => $txt['flitter_position_sidebar'])),
array('title', 'flitter_fb'),
array('check', 'flitter_showfb'),

array('title', 'flitter_twitter'),
array('check', 'flitter_showtwitter'),
$txt['flitter_twitter_via_desc'],
array('text', 'flitter_twitter_via'),
array('text', 'flitter_twitter_related'),
array('text', 'flitter_twitter_related_desc'),

array('title', 'flitter_google'),
array('check', 'flitter_showgoogle'),
);

Then you have a function which binds to the admin menu, and the rest of the boilerplate in this function that's used for saving and calling the relevant templates and stuff. It gets set up as action=admin;area=flitter and uses 'Flitter' as the title (which is the plugin's title anyway)

I'm thinking we could handle this in the plugin-info.xml file directly instead.

Code: [Select]
<settings-page area="flitter" icon="mgallery.png" bigicon="$plugindir/flitter.png">
<load-language file="Flitter-Admin" />
<desc name="flitter_desc" />
<select name="flitter_position">
<opt value="topic" name="flitter_position_topic" />
<opt value="sidebar" name="flitter_position_sidebar" />
</select>
<title name="flitter_fb" />
<check name="flitter_showfb" />
<title name="flitter_twitter" />
<check name="flitter_showtwitter" />
<literal name="flitter_twitter_via_desc" />
<text name="flitter_twitter_via" />
<text name="flitter_twitter_related" />
<text name="flitter_twitter_related_desc" />
<title name="flitter_google" />
<check name="flitter_showgoogle" />
</settings-page>

Assuming the plugin author uses this, it should be able to handle the menu item, the settings themselves, making them searchable and auto-linking it in the plugins area (minimising the need for using the <acp-url> element though not obsoleting it)

The area= part specifies what admin area it should be, the icon is the icon for the dropdown menu, the bigicon is the big icon to use, <load-language> identifies what language file(s) should be loaded when running the page, so that the relevant strings can be loaded. Everything else just correlates to the above.

Personally, I think it's less effort for the plugin developer generally, it's less they have to deal with - you don't expressly have to deal with hooks when doing this and you're still doing less work than you would doing it manually.

Thoughts?
 1. Three if you want to make it searchable as well, yup, even that isn't automated.
Re: Settings page integration
« Reply #1, on February 25th, 2012, 01:01 AM »
While there is an implied performance aspect (since the admin menu has to be evaluated every page of the admin area) it's not a great stretch to actually cache all the active plugins' details and evaluate them in a single hit.
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
Re: Settings page integration
« Reply #2, on February 25th, 2012, 02:01 AM »
We used this concept for external modules in Dream Portal. The module uploader grabbed the parameters and copied them to the database.

A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Settings page integration
« Reply #3, on February 25th, 2012, 02:05 AM »
How well did it work out for you?

I never did find out how well Dream Portal's plugins stuff did, I was vaguely aware of what one had to do to create such a thing but I never made any, and I remember being something related to amazement at seeing raw PHP embedded into XML,[1] but anything other than that, I don't remember, and I might even be remembering that incorrectly.

(Note that I'm not looking to remove the existing <settings> block which is used for settings defaults and housekeeping, because plugins that don't use this setup because it's too limiting, e.g. WedgeDesk, will still use <settings> to clean up after removal)
 1. Since unless I'm much mistaken, that's eval() right there...

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
Re: Settings page integration
« Reply #4, on February 25th, 2012, 02:27 AM »
Quote
How well did it work out for you?
I did not notice any problems. My original draft did not modify any files, but, in the end, language entries got injected into a master file, if you remember.

Raw PHP code within XML? II have no idea on what's in the current development, but the first public debuts did not. Heck, the only eval call was for the custom code module.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Settings page integration
« Reply #5, on February 25th, 2012, 02:33 AM »
I thought the module's code was generally specified in the XML file and there was no extraneous files added (except for complete language files or sub files, but that the main block code was actually directly in the XML) - but that was a long time ago. Glancing through the current ones it doesn't seem like that now - though I think the format of embedding options into the XML sort of defeats the point of using XML a bit...
Quote
but, in the end, language entries got injected into a master file, if you remember.
I didn't remember but it seems to be that way based on the XML files.

So, all in all, it seems like it hasn't confused anyone?

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
Re: Settings page integration
« Reply #6, on February 25th, 2012, 02:46 AM »
Quote
though I think the format of embedding options into the XML sort of defeats the point of using XML a bit...
I don't know about the other developer, but I didn't know much about XML best practices back then.
Quote
So, all in all, it seems like it hasn't confused anyone?
Very hard to tell, since almost no one has used that. To this day, I see modules only be the project members. And they haven't complained about that syntax that I could see.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Settings page integration
« Reply #7, on February 25th, 2012, 02:48 AM »
Somehow that doesn't surprise me one bit.

OK, so more relevantly, do you like the syntax proposed? Would you use it for the intended case?

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
Re: Settings page integration
« Reply #8, on February 25th, 2012, 03:32 AM »
Yep! But why use the tag opt - seems too close to optgroup. Could you expand tit to the full word ''option'?

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Settings page integration
« Reply #9, on February 25th, 2012, 03:34 AM »
Because I was lazy :P I have no problem with using option instead of opt, just laziness on my part.

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Settings page integration
« Reply #11, on February 27th, 2012, 03:58 AM »
Bump in case anyone else has any opinions they want to voice before I go implement this.

Nao

  • Dadman with a boy
  • Posts: 16,082

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Settings page integration
« Reply #14, on February 27th, 2012, 06:36 PM »
This is now in r1397.
Posted: February 27th, 2012, 06:33 PM

And I've updated the contact page plugin in my repo to cover it too.