Defect #3672
openUnable to set "value" and "old_value" through :helper_issues_show_detail_after_setting hook
0%
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
Updated by Eric Davis over 15 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:
Updated by Giovanni Junior over 15 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.
Updated by Eric Davis almost 15 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).
Updated by Thomas Löber almost 15 years ago
- File issues_helper.rb.patch issues_helper.rb.patch added
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
Updated by Pascal Schoenhardt over 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.
Updated by Eric Davis almost 14 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
Updated by Jean-Philippe Lang almost 12 years ago
- Status changed from 7 to New
Assigned issue with no assignee back to New status.