@tsteur opened this Issue on May 11th 2015 Member

We have a couple of widgets such as Insights: https://github.com/piwik/piwik/blob/2.13.1/plugins/Insights/Widgets.php#L17

They define the widget in Widgets.php but the rendering is done in the Controller. This is usually good /ok since this is what a Controller does. But we want plugin developers to do all this in a Widgets.php or (Widget.php after #7861 is done). It would be nice to have many good examples in the code base and render the widget actually in the widget class. The pretty much only reason why they are rendered in the controller is because they use eg setBasicVariablesView: https://github.com/piwik/piwik/blob/2.13.1/plugins/Insights/Controller.php#L51 which won't be available in the Widget class. Personally, I'd like to avoid people having to use a controller anyway. I rather want them having to use only Report or Widget or ... which is more meaningful and they don't have to learn about too many classes etc. With a simple example generated by the command line it is fairly easy to create a widget this way. Of course if they want to create a plain page such as a "Help" page or so they will still have to use a Controller.

There is eg:

How can we make them more reusable and remove them from Controllers? Eg by decorators?

new GeneralVariablesView(new BasicVariablesView(new View))? Or shall we extract them into a different class? Which one?

This will also help us to solve "Having Controller and ControllerAdmin class is confusing #6151".

Any thoughts? @mattab @diosmosis @mnapoli @sgiehl

@mattab commented on July 15th 2015 Member

@tsteur Shall we target this for 3.0.0? It seems required for #7861 which is set for 3.0.0.. thoughts?

@tsteur commented on July 15th 2015 Member

We would ideally do this also for #7822 and other issues to have good examples for plugins in our code base. This will help us to move code from controllers into the widget class.

To find a solution we could talk about this in Berlin/Poland. Added a Trello card

@tsteur commented on November 23rd 2016 Member

Would have been nice to have in 3.0 but not really needed

@tsteur commented on February 11th 2020 Member

Closing this one as I think it isn't really needed anymore. All those methods do is pre-assigning a few view variables. Should the widget need any of these variables, then it is a lot easier to simply assign them as part of the widget render. What variables are assigned in those basic view variables etc is not transparent and not an API anyway.

This Issue was closed on February 11th 2020
Powered by GitHub Issue Mirror