- Redmine Plugin Extension and Development
- Alex Bevilacqua
- 211字
- 2021-07-16 12:20:24
Understanding hooks
A hook is essentially just a listener for which we've registered a callback function. These callback functions expect a single parameter: a hash that provides some context to the function. The contents of the hash depend on what type of hook is being evaluated.
There are four basic categories of hooks available in Redmine:
- View hooks
- Controller hooks
- Model hooks
- Helper hooks
For view and controller hooks, the context hash contains the following fields as well as data specific to the hook being used:
:project
: This is the current project:request
: This contains the current web request instance:controller
: This contains the current controller instance:hook_caller
: This holds the object that called the hook
Note
The full list of available hooks is maintained at http://www.redmine.org/projects/redmine/wiki/Hooks_List.
To quickly build the hook list for the version of Redmine you have installed, run the following commands:
cd /path/to/redmine/app grep -r call_hook *
By doing this from the app
directory, we prune out any results from the hook class definition or any of the test files.
Redmine has many hooks registered throughout the codebase by means of the call_hook
method, whose syntax is as follows:
call_hook(hook, context={})
For example, the partial /path/to/redmine/app/views/issues/_form.html.erb
contains the following hook declaration:
<%= call_hook(:view_issues_form_details_bottom, { :issue => @issue, :form => f }) %>
- Mastering Ext JS(Second Edition)
- Django+Vue.js商城項(xiàng)目實(shí)戰(zhàn)
- 微服務(wù)設(shè)計(jì)原理與架構(gòu)
- Android 7編程入門經(jīng)典:使用Android Studio 2(第4版)
- Java面向?qū)ο蟪绦蜷_發(fā)及實(shí)戰(zhàn)
- 鋒利的SQL(第2版)
- Internet of Things with ESP8266
- Struts 2.x權(quán)威指南
- Elasticsearch Blueprints
- JavaWeb從入門到精通(視頻實(shí)戰(zhàn)版)
- 循序漸進(jìn)Vue.js 3前端開發(fā)實(shí)戰(zhàn)
- Mastering Unity Scripting
- 大象:Thinking in UML(第二版)
- Python程序設(shè)計(jì)教程
- Java Web應(yīng)用設(shè)計(jì)及實(shí)戰(zhàn)