プロジェクト

全般

プロフィール

Vote #63131

完了

Hooks for plugins

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
-
対象バージョン:
開始日:
2008/04/29
期日:
進捗率:

0%

予定工数:
category_id:
0
version_id:
2
issue_org_id:
1143
author_id:
674
assigned_to_id:
0
comments:
6
status_id:
5
tracker_id:
2
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

This feature is just an idea, I don't have any particular application driving the requirement, although I think it could be used to allow people a bit more flexibility in implementing some of the feature requests into non-core plugins.

The technical requirements would be pre- and post-xxx hook functions defined around the major functions. Combined with ruby's ability to inject code into classes and redefine functions on the fly, I could create a module that customized the behavior of the system in small ways without patching the code directly.

For example, with a pre-issue-change hook I could implement issue reassignment based on the current state of the issue, so that new issues always went to the same person for triage, then when the bug is accepted it's assigned to the normal user-per-category. Then when resolved it could automatically get reassigned to QA person.

All it would take is some dummy functions that get fed pertinent data, which would allow a plugin writer to redefine for their own purposes.


journals

I've been thinking about this a lot lately and it's one thing that I think Wordpress did good on. A practical example would be allow a plugin to hook into the issue edit page to render some extra HTML after the main form. I'd like to just be able to hook into it like:

<pre>
Redmine.hooks[:post_issue_edit] << MyPluginController.action
</pre>

Jean-Philippe Lang, I have a plugin coming up that we could use as an experiment for this API.
--------------------------------------------------------------------------------
I wanted to post an update to this feature. I have successfully added hooks into Redmine and the Redmine Plugin API. It still needs some cleaning up before release but it's working great for a plugin I'm writting. Similar to Wordpress plugins, you can have a hook that inserts HTML or does an action. The plugin registers for a hook buy passing in a Ruby Proc to the @add_hook@ method:

<pre>
# Plugin's init.rb
add_hook(:issue_show, Proc.new { |context| MyClass.my_method(context) })
</pre>

To add a hook point, the core just needs a single line. Using the example above:
<pre>
# app/views/issues/show.rhtml
<%= Redmine::Plugin::Hook.call_hook(:issue_show, {:project => @project, :issue => @issue}) %>
</pre>

I'd like to have these hooks are critical points and we can also wrap some methods with around filters to do the pre/post processing.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Eric Davis wrote:
> The plugin registers for a hook buy passing in a Ruby Proc to the @add_hook@ method:

Very minor suggestion, but could you rename it to add_to_hook, which is what really happens, please ? Emacs did it wrong decades ago and we are now stuck with this improper name 'add_hook' :)

Other than that, it might be a useful facility, thanks.
--------------------------------------------------------------------------------
I've just added a patch for the Plugin hook API on #1677.
--------------------------------------------------------------------------------
Plugin hooks were added in #1677
--------------------------------------------------------------------------------


related_issues

relates,Closed,783,Real Plugin-System
relates,Closed,1677,Plugin hook API

Admin Redmine さんが約4年前に更新

  • 対象バージョン0.8_2 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0