Http://www.redmine.org/wiki/redmine/Plugins
Http://www.redmine.org/wiki/redmine/Plugin_Internals
Overriding the redmine Core
You can override views but not controllers or models in redmine. Here's how redmine/rails works if you try to override a controller (or model) and a view for a fictional pluginMyplugin
:
Controllers (or models)
- Rails bootstraps and loads all it's Framework
- Rails starts to load code in the plugins
- Rails finds
Issuecontroller
In myplugin and see it definesShow
Action
- Rails loads all the other plugins
- Rails then loads the application from../APP
- Rails finds
Issuecontroller
Again and see it also definesShow
Action
- Rails (or rather Ruby) overwrites
Show
Action from the plugin with the one from../APP
- Rails finishes loading and serves up requests
Views
View loading is very similar but with one small difference (because of redmine's patch to engines)
- rails bootstraps and loads all it's framework
- rails starts to load code in the Plugins
- rails finds a views directory in .. /vendor/plugins/my_plugin/APP/views and pre-pends it to the Views path
- rails loads all the other plugins
- rails then loads the application from ../APP
- rails finishes loading and serves up requests
- request comes in, and a view needs to be rendered
- rails looks for a matching template and loads the plugin's template since it was pre-pended to the Views path
- rails renders the Plugins 'view
Due to the fact that it is so easy to extend models and controllers the Ruby way (via including modules), redmine shouldn't (and doesn't) maintain an API for overriding the core's models and/or controllers.Views on the other hand are tricky (because of rails magic) So an API for overriding them is way more useful (and thus implemented in redmine ).
To override an existing redmine core view just create a View File named exactly after the one in../APP/views/And redmine will use it. for example to override the project index page add a file../Vendor/plugins/my_plugin/APP/views/projects/index. rhtml.
Extending the redmine Core
As explained above: You rarely want to override a model/controller. Instead you shoshould either:
- Add new methods to a model/controller or
- Wrap an existing method.
Adding a new method
A quick exampleAdding a new methodCan be found on Eric Davis'Budget plugin. Here he added a new method to issue calledDeliverable_subject
And also declared a relationship.
Wrapping an existing Method
A quick exampleWrapping an existing MethodCan be found on Eric Davis'Rate plugin. Here he usesAlias_method_chain
To hook into the usershelper and wrapUser_settings_tabs
Method. So when the redmine core CILSUser_settings_tabs
The codepath looks like:
- Redmine core CILS
Usershelper # user_settings_tabs
Usershelper # user_settings_tabs
Runs (which is actuallyUsershelper # user_settings_tabs_with_rate_tab
)
Usershelper # user_settings_tabs_with_rate_tab
Callthe originalUsershelper # user_settings_tabs
(RenamedUsershelper # user_settings_tabs_without_rate_tab
)
- The result then has a new hash added to it
Usershelper # user_settings_tabs_with_rate_tab
Returns the combined result to the redmine core, which is then rendered
Alias_method_chain
Is a pretty advanced method but it's also really powerful.