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

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 }) %>
主站蜘蛛池模板: 上林县| 广昌县| 镇坪县| 灵丘县| 彝良县| 青川县| 永城市| 务川| 子洲县| 凭祥市| 沁源县| 天长市| 忻城县| 乡城县| 且末县| 闻喜县| 米泉市| 宕昌县| 峨山| 景宁| 沧源| 高阳县| 砀山县| 徐水县| 华阴市| 上饶县| 天台县| 霍山县| 寻甸| 独山县| 绿春县| 鹤山市| 利辛县| 旬阳县| 望江县| 遵义县| 河南省| 吉木乃县| 察雅县| 蕉岭县| 雷州市|