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

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 }) %>
主站蜘蛛池模板: 枝江市| 旬阳县| 潍坊市| 久治县| 崇仁县| 塔城市| 辛集市| 临颍县| 策勒县| 昆山市| 五莲县| 靖边县| 安国市| 霍山县| 宿州市| 宝兴县| 永川市| 建水县| 安泽县| 芦溪县| 常宁市| 綦江县| 长治县| 马公市| 托克逊县| 济南市| 泉州市| 巴里| 翁源县| 应城市| 清水县| 衡阳市| 焦作市| 丹寨县| 荆门市| 高台县| 分宜县| 夏河县| 黑水县| 房产| 靖州|