Page 1 of 1

How do I implement a stackable event plugin with one backend menu option?

Posted: Tue Nov 17, 2020 1:13 pm
by spunkjazz
I'm working on a stackable event plugin that should provide three different views and only one backend menu option. The event plugin allows the selection of a view and is therefore installed three times with a different view selection each.
In this setup and without any checks each installed event plugin adds the backend menu option for administration once making it appear three times overall.
At the moment I check for one specific view and add the backend menu option only if this view is selected. This requires one and only one plugin with this specific view selection.
Another approach would be to add another configuration option for the event plugin to enable adding of the backend menu option only in one of the installed plugins. This would require at least one plugin with no particular view selected.
Or I could add another view just for the backend menu option and check for this selection. This would completely remove the dependency of the backend menu option from the event plugin. Configuration options like permalink and pagetitle should then be ignored in events plugin configuration which is not very user-friendly.
Or I could even create two different plugins which is something i don't want to do.

Is there any best practise how to add a backend menu option only once if the event plugin is stackable?

Re: How do I implement a stackable event plugin with one backend menu option?

Posted: Thu Nov 19, 2020 8:05 am
by onli
Hi! Take my post with a grain of salt, I do not have much experience with stacked plugins.

But from what I gleaned from the code, there is very little extra code for them. I think it is just a tag that bypasses the installer check for the same type of plugin being already there. Configuration options are saved with their own instance id (I think), so it would not be possible to have all of them share the same configuration - not with how the plugin configuration usually work.

I'm not sure what you mean with view in your post, maybe you could explain a bit more.

My approach would be to circumvent the plugin configuration. It's an event plugin after all, so it's all powerful. Make it output its own backend page, and have a custom configuration there. You can use the serendipity database layer to create your own configuration table. Then, in the plugin code, you fetch that configuration in all of your plugin instances. That way they would have a shared configuration without you having to fight the serendipity layer.

Mid-term it actually could be worthwhile to provide an API for shared configuration options for stacked plugins, but I'm not sure it's realistic. And even if, it would definitely take some time until it's in a release. So to build it on your own has advantages.

If you need more pointers to how that would work, I'd be happy to provide some code examples. Please just say if that would be helpful.

Re: How do I implement a stackable event plugin with one backend menu option?

Posted: Sun Jan 31, 2021 10:43 am
by spunkjazz
Thanks for your answer and sorry for my late response. I finally decided to split backend administration and frontend display into two separate plugins as this seems to be the cleanest approach. My plugin folder serendipity_event_foobar contains one file for each plugin: serendipity_event_foobar.php for frontend display and serendipity_event_foobar_admin.php for backend administration.

With this separation I avoid the configuration problems I described in my first post. The plugin for backend administration has, for now, no configuration options. The plugin for frontend display has permalink, title and a few other options. One of them is a select field for different views of the data the plugin provides. One basically can select if records of type a or records of type b are shown in frontend. This is why I need the plugin for frontend display to be stackable. Each view has its own permalink.

Re: How do I implement a stackable event plugin with one backend menu option?

Posted: Sun Jan 31, 2021 11:32 am
by onli
Sounds like a clean solution, better than what I had suggested :)