Project

General

Profile

Actions

Defect #3672

open

Unable to set "value" and "old_value" through :helper_issues_show_detail_after_setting hook

Added by Giovanni Junior over 14 years ago. Updated over 11 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Plugin API
Target version:
-
Start date:
2009-07-25
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

In http://www.redmine.org/wiki/1/Hooks, the description for :helper_issues_show_detail_after_setting states that it "Passes data to the hook to allow it to set the label and value", but it seems this is only partially true.

Setting context variables in a hook using the "=" operand just doesn't work. For "context[:label]", which is already initialized (as a String) when the hook is called, this may be worked around calling "context[:label].replace". However, as "context[:value]" and "context[:old_value]" may be uninitialized when the hook is called, I don't see a way to change their value at all. And setting "context[:detail].value" and "context[:detail].old_value" is obviously not as harmless as setting "context[:value]" and "context[:old_value]".

Using Redmine 0.8.4, Rails 2.1.2 and Ruby 1.8.6.


Files

issues_helper.rb.patch (844 Bytes) issues_helper.rb.patch Thomas Löber, 2010-02-19 13:39
Actions #1

Updated by Eric Davis over 14 years ago

Can you attach a test case showing this? I've been able to set context[:value] and context[:old_value] in my Budget plugin:

http://github.com/edavis10/redmine-budget-plugin/blob/8413b26a15b74817b28509c3664da76f072ab36d/lib/budget_issue_hook.rb#L82

Actions #2

Updated by Giovanni Junior over 14 years ago

Your plugin sets context[:detail].value and context[:detail].old_value, which are different from context[:value] and context[:old_value].

Unfortunately, the code in question is not very "testable". Indeed, I have no idea how to test it.

Actions #3

Updated by Eric Davis about 14 years ago

  • Status changed from New to 7

I just ran into this myself. Setting context[:object] to a new object isn't sent back to the calling code (new object reference). Setting context[:object].value works because :object is still the same object.

I've worked around this in some private code but it wasn't an easy implementation. I think we might need to split how the View Hooks return data from the Model/Controller hooks (View should merge the response strings, Model/Controller should check for reassignments).

Actions #4

Updated by Thomas Löber about 14 years ago

I worked around it by adding another hook for plugin-defined detail properties (see issues_helper.rb.patch for Redmine 0.9-stable).

Then the hook code would look like this:

    def helper_issues_show_detail_format(context)
      detail = context[:detail]
      if detail.property == "user_notified" 
        user = User.find_by_id(detail.prop_key) or return
        l(:label_user_notified, context[:html] ? link_to_user(user) : user.name)
      end
    end

Actions #5

Updated by Pascal Schoenhardt almost 14 years ago

Couldn't this issue be fixed quite easily by assigning the value, old_value, and label defaults before calling the hook in app/helpers/issues_helper.rb?

Current

    call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value })

    label ||= detail.prop_key
    value ||= detail.value
    old_value ||= detail.old_value

Fixed

    label ||= detail.prop_key
    value ||= detail.value
    old_value ||= detail.old_value

    call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value })

Now the objects are initialized, and the if the hook modifies them it will get passed back.

Actions #6

Updated by Eric Davis over 13 years ago

  • Assignee deleted (Eric Davis)

I am stepping down from working on Redmine. If someone else is interesting in working on this issue, feel free to reassign it to them.

Eric Davis

Actions #7

Updated by Jean-Philippe Lang over 11 years ago

  • Status changed from 7 to New

Assigned issue with no assignee back to New status.

Actions

Also available in: Atom PDF