Project

General

Profile

Need help with hook!

Added by Diego Sousa about 16 years ago

Hi!

Im in charge to develop a customized version of redmine, i did some things but now i can't merge with trunk because the changes in core, im moving to trunk version and rewriting everything with plugins but i don't know how work the hook system, dont have alot of documentation, can anyone help me with a example?
ex, in the time entry, i need record the start hour, end hour and the pause time, with this i can calculate the hour worked, how can i add this with plugins?

Thanks guys!
awesome work with redmine ^^


Replies (5)

RE: Need help with hook! - Added by Eric Davis about 16 years ago

For documentation on the hooks, #1677 is the primary place to look for now. Starting on Note 10 is the discussion of what was actually implemented in trunk.

If you want to see an example of them, my Budget plugin uses several hooks. Check lib/budget_project_hook.rb and lib/budget_issue_hook.rb.

ex, in the time entry, i need record the start hour, end hour and the pause time, with this i can calculate the hour worked, how can i add this with plugins?

You would probably need a few hooks added to that page but once they are in place Redmine would just run whatever code you send to the hook. The best course of action is to modify your Redmine core by adding the call_hook you need, build your plugin to make sure the hook is what you need, and then submit the hook as a patch. I'm trying to make it very easy to get new hooks into the core as long as they are named good and are in a useful place.

Eric

RE: Need help with hook! - Added by Diego Sousa about 16 years ago

Thanks Eric, now i understand how the hooks work, i have just one more question, i added some hooks in the issue controller and in issues views and everything works fine, than i added in timelog views too and worked, but when i add in timelog controller i get a error "undefined method 'call_hook' for #<TimelogController....>", the hook methods are in the same file, maybe the timelog controller don't have a listener? i just called like this "call_hook()" just to test and i get the same error, in issues controller i dont get error with this "call_hook()"

Thanks! :)

RE: Need help with hook! - Added by Eric Davis about 16 years ago

Could you open a bug report for that with the full stack trace from the log? Thanks.

Eric

RE: Need help with hook! - Added by Diego Sousa about 16 years ago

Here is the link to issue: http://www.redmine.org/issues/show/2111
I forgot to say, im using the last version of redmine

RE: Need help with hook! - Added by Diego Sousa about 16 years ago

i found the problem, in IssuesController i dont get error because of mixin with IssuesHelper and inside IssuesHelper have a mixin with ApplicationHelper that include the Redmine::Hook::Helper that have the method call_hook, TimelogController has a mixin too with TimelogHelper but TimelogHelper dont have a mixin with ApplicationHelper, well instead of mixin every helper i changed the hook.rb file lib/redmine/hook.rb in the last line i add ActionController::Base.send(:include, Redmine::Hook::Helper) now all the controllers have the call_hook method.

    (1-5/5)