-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add possibility to define the menu action in the menu class #6144
Comments
Maybe there can be a simple base 'ControllerComponent' class or interface that components (ie, Menu/Widgets/whatever) can extend to signify to the routing logic that they act as controllers. FrontController would look for an action in the first object it found in a plugin that extended ControllerComponent. Could do the same for APIs. What do you think? |
We should probably not extend such a class as extending a class is the strongest form of coupling. Especially since we cannot extend multiple classes. Interface could be possible but don't think it is designed for this (would not require anything?) and the developer would have to know that he has to implement this interface in order to make a method "routable". Would be nice if it worked automatically. Next problem could be that different components could implement the same method (this problem can probably happen with any solution). Also some classes would maybe have multiple public methods but only should be "routable". I was rather thinking like generating a prefix for menu items like "menuNotifications". We could detect the prefix in the router and then perform a check whether there is a public method But now that you are saying this I agree it is not a universal solution that can be used for anything. On the other side it is quite fast since we do not have to search for many classes and methods that are "routable". There could be otherwise a method which is in the beginning not really exposed as an API but used internally. So when someone is calling If a plugin wants to overwrite the action of another plugin it would have to listen to an event which is ok as it does not happen too often. So it can be a bit more complex to do something like this. |
I got a request from @czolnowski during the meetup for an annotation that would allow you to split an API into separate classes, something like:
Since we don't use annotations, inheritance (of some form, base or interface) appears to be the only alternative. I think classes that are meant to handle routes are controllers so the is-a relationship is appropriate in my eyes. Regarding speed, caching can be used to speed it up if speed's a problem. Or when DI is put in, we can look through the objects created for the plugin being routed through (and since php-di implements caching, we shouldn't have to worry about speed). That said, this isn't that important to me, so consider my comments a suggestion. I don't need or require this. |
Had another idea that might be useful or lead to something workable: maybe there can be a Routes component that allows plugins to specify where actions are? This isn't a full solution, but maybe it will lead to one. Or not, whatever ;) |
For a widget you can define the method to render the actual widget within the
Widget
class. For a task you can define the method to execute the actual task within theTasks
class. But for a menu item you have to create a controller and action in addition and it is not possible to define the method within the class.Because of having to stay backwards compatible it is not that easy to make the
Menu
class work similar toTasks
andWidgets
. After #6140 made it easy to generate URL's for controller actions (urlForAction()
,urlForModuleAction
, ...) we could add a method likeurlForMethod($nameOfMethodWithnMenuClass)
that makes it possible to define the related method within theMenu
class.Example
We might have to adjust the router slightly to resolve such URL's similar to widgets.
The text was updated successfully, but these errors were encountered: