官术网_书友最值得收藏!

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 }) %>
主站蜘蛛池模板: 利川市| 滕州市| 嘉黎县| 舟山市| 盐边县| 增城市| 合川市| 绍兴市| 延边| 游戏| 祁连县| 山东| 汝阳县| 乐都县| 阳信县| 榆社县| 门头沟区| 万州区| 长治县| 惠来县| 兰坪| 黄浦区| 眉山市| 汶川县| 玉屏| 富锦市| 汝南县| 定边县| 那曲县| 隆子县| 松原市| 凭祥市| 咸丰县| 沂南县| 新乡县| 吉首市| 东乌珠穆沁旗| 江门市| 西宁市| 龙州县| 仁怀市|