Project

General

Profile

Actions

Patch #1677

closed

Plugin hook API

Added by Eric Davis over 15 years ago. Updated over 15 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Plugin API
Target version:
Start date:
2008-07-24
Due date:
% Done:

100%

Estimated time:

Description

This patch to adds support for Plugin hooks into Redmine. By providing Plugin hooks, users can create custom plugins to modify Redmine's behavior without modifying the core. This patch includes a new Plugin API method, a few hooks in the Redmine core, a base hook class, and internal methods to manage and call the hooks.

Plugin API - add_hook(hook_name, method)

Registers a method to be called when Redmine runs a hook called hook_name.

# Run puts whenever the issue_show hook is called
add_hook :issue_show, Proc.new { puts 'Hello' }
# Call the class method +my_method+ passing in all the context
add_hook :issue_show, Proc.new {|context| MyPlugin.my_method(context)}

Hooks in Redmine core

Potentially anyplace in the Redmine core can have a hook point added. I added a few to some areas I needed:

  • Issue show view
  • Issue edit form
  • Issue bulk edit view
  • Issue bulk edit save (in IssuesController)
  • Issue update view
  • The Project's members page
  • IssueHelper#show_details helper

New hooks can be added by adding a symbol to Redmine::Plugin::Hook::Manger::hooks and adding the call_hook method in the core, passing in any parameters.

# Will call `my_new_hook` with the @project and @issue objects
Redmine::Plugin::Hook::Manager.call_hook(:my_new_hook, {:project => @project, :issue => @issue})

Base Hook Class

A new class is added called Redmine::Plugin::Hook::Base which can be subclassed by plugins to use Rails Helpers with the provided help object.

Internal modules

Two new classes are added: the Redmine::Plugin::Hook::Base mentioned earlier and Redmine::Plugin::Hook:Manager. The Manager class is responsible for tracking what plugins are registered for which hooks and to call those plugins once a call_hook method is run.


The attached file applies cleanly to svn r1694. I'll be maintaining this patch on Github on the plugin-hooks branch and would love feedback and patches against the code.


Files

redmine-hooks-svn-1694.patch (7.22 KB) redmine-hooks-svn-1694.patch Patch to add a Plugin Hook API Eric Davis, 2008-07-24 06:14
redmine-hooks-svn-1709.patch (12.9 KB) redmine-hooks-svn-1709.patch Patch to add a Plugin Hook API with unit tests Eric Davis, 2008-07-29 02:36
hook.rb (1.69 KB) hook.rb Jean-Philippe Lang, 2008-08-05 18:29

Related issues

Related to Redmine - Feature #1143: Hooks for pluginsClosed2008-04-29

Actions
Related to Redmine - Feature #783: Real Plugin-SystemClosed2008-03-04

Actions
Actions

Also available in: Atom PDF