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

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 }) %>
主站蜘蛛池模板: 邯郸市| 申扎县| 巴东县| 遵义县| 高邮市| 扶绥县| 抚顺县| 贡嘎县| 紫阳县| 浦东新区| 满城县| 高碑店市| 扶沟县| 理塘县| 思南县| 昌宁县| 美姑县| 洛扎县| 敦煌市| 辽宁省| 延川县| 民乐县| 辛集市| 密云县| 奇台县| 行唐县| 都匀市| 布拖县| 兴宁市| 莱州市| 宁德市| 临湘市| 五常市| 巴彦县| 晴隆县| 邢台市| 丹江口市| 东丽区| 桓台县| 德江县| 滦平县|