It looks like you're new here. If you want to get involved, click one of these buttons!
I am writing a plugin that adds a page and I have run into an issue with making a pretty route for it (see below). I'm considering adding a controller to the plugin and it got me thinking: is it alright to add controllers to plugins and simple one-method controllers in general, or is it better to save controllers for larger applications? I would like to know your thoughts on this.
Perhaps it depends on how we define applications vs. plugins. Most of the time, we only see controllers in applications, but they are supported in plugins, and plugins tend to be smaller and extend the Vanilla application. This plugin I'm writing is a good example for discussing this, specifically when it comes to adding a simple one-method controller to the plugin.
The plugin adds one simple page that displays a Twitch live stream video embed and live chat embed, represented as the website's official live stream.
It creates a
/plugin/twitchpage endpoint in the PluginController and also creates a
/settings/twitchpage endpoint in SettingsController where ConfigurationModule is used to let you set the Twitch channel name to be displayed.
Also, it has code to display link shown as "Live" to
/plugin/twitchpage in the main menu. I would like to let you add a pretty route to this such as
/live. For example, they can add an internal route from the dashboard with
live$ (substituting "live" with whatever route you want) with the target
The issue is that the link in the main menu won't reflect the new route if one is added. This can't be solved by calling the
Gdn::Router()->matchRoute() method because it checks the route expression, which can be whatever the user has set, and not the target (should be
/liveas the route (I'd use this) and add an option to the settings page to add the route in; however, that means I wouldn't be able to use the ConfigurationModule, where all settings are meant to be saved in the
/conf/config.phpwhereas the route is set by other methods. Although I can write a custom settings page, this just adds complexity to a small plugin. It would be simpler to make the endpoint
What solution do you think is best for this plugin to achieve the pretty routing?