Overriding helpers in plugins?
Added by Alexey Palazhchenko over 14 years ago
Plugin Internals doesn't says anything about helpers? How to override them?
Replies (4)
RE: Overriding helpers in plugins? - Added by Rolando Kindelan Nuñez over 14 years ago
hello!
I develop a component management plugin for redmine, and I have to override the custom_fields_helpers. I copy the custom_fields_helpers.rb file in the .../my_plugin/app/helpers and override the custom_fields_tabs method and its works successfully. You can do this via Rails, a quick example of wrapping an existing method can be found on Eric Davis' Rate plugin and other quick example of adding a new method can be found on Eric Davis' Budget plugin. Personally I use my own way above explained.
I hope I can help you with this comment.
Best regards
Rolando
RE: Overriding helpers in plugins? - Added by Denis Savitskiy over 14 years ago
But how is the wrapping of method is used?
RE: Overriding helpers in plugins? - Added by Rolando Kindelan Nuñez over 14 years ago
You must redefine the method and implement your version that's all, for example:
if you want to overwrite the custom_fields_tabs method in custom_fields_helper you redefine the method with your new code like this:
original method:
def custom_fields_tabs
tabs = [{:name => 'IssueCustomField', :partial => 'custom_fields/index', :label => :label_issue_plural},
{:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
{:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
{:name => 'VersionCustomField', :partial => 'custom_fields/index', :label => :label_version_plural},
{:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
{:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural},
{:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index', :label => TimeEntryActivity::OptionName},
{:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index', :label => IssuePriority::OptionName},
{:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index', :label => DocumentCategory::OptionName}
]
end
wrapper method for make a documents custom field tab:
def custom_fields_tabs
tabs = [{:name => 'IssueCustomField', :partial => 'custom_fields/index', :label => :label_issue_plural},
{:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
{:name => 'DocumentCustomField', :partial => 'custom_fields/index', :label => :label_document_plural},
{:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
{:name => 'VersionCustomField', :partial => 'custom_fields/index', :label => :label_version_plural},
{:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
{:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural},
{:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index', :label => TimeEntryActivity::OptionName},
{:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index', :label => IssuePriority::OptionName},
{:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index', :label => DocumentCategory::OptionName}
]
end
and copy custom_fields_helper.rb file in your vendor/plugin/helpers and clean the methods except your new wrapper method... and that's all
this is one way.... the other way is via Rails like Eric Davis's Budget and Rate plugins.. you must see the init.rb and the file patch in lib folder.
regards.
Rolando
RE: Overriding helpers in plugins? - Added by charly clairmont over 13 years ago
Hi All,
I try to understand how to override a method in a helper module. But I did not found some samples : I searched in some Eric Davis plugins on github without success.
So, can someone give me please more advices to override a helper, and more precisely the ProjectsHelper ?
Cheers.