Forums » Development »
How to change the corresponding menu_item of a core module with a plugin?
Added by Bernhard Rohloff about 7 years ago
Hi all,
at the moment I'm trying to create a plugin to bring all issues relating views (issues, gantt, calendar) together under the issues tab. The different views shall be selected from the sidebar.
Until now I've managed to create the links in the sidebar and removed the calendars and gantts menu items from the main menu. The only problem I'm facing right now is the fact that if I'm selecting the calendar or gantts view from the sidebar, the issues menu item is no longer the selected item in the main menu.
So is there a way I can modify the gantts and calendars controller to show the issues menu item as the selected one?
Thanks in advance,
Bernhard
Replies (4)
RE: How to change the corresponding menu_item of a core module with a plugin? - Added by Marius BĂLTEANU about 7 years ago
Take a look at the menu_item property. For example: source:trunk/app/controllers/calendars_controller.rb#L19
RE: How to change the corresponding menu_item of a core module with a plugin? - Added by Bernhard Rohloff about 7 years ago
Hey Marius,
thank you for your answer. It was a bit tricky for me to get access to the menu_item property. Perhaps, with better ruby/rails skills this would be not that problem. I'm working on it. ;-)
To my surprise, I found a nice solution for my problem in source:trunk/app/controllers/issues_controller.rb#L400. By overriding the current_menu_item
method I'm getting the expected behavior.
Again thank you and greetings,
Bernhard
RE: How to change the corresponding menu_item of a core module with a plugin? - Added by Mischa The Evil almost 7 years ago
Bernhard Rohloff wrote:
[...] It was a bit tricky for me to get access to the menu_item property. Perhaps, with better ruby/rails skills this would be not that problem. I'm working on it. ;-) [...]
FWIW: it's implemented through Redmine::MenuManager::MenuController::ClassMethods#menu_item
, ..#menu_items
, ..#current_menu_item
& Redmine::MenuManager::MenuController::MenuHelper::current_menu_item
which are included by ApplicationController
(initially implemented, long ago, in r1076).
RE: How to change the corresponding menu_item of a core module with a plugin? - Added by Bernhard Rohloff almost 7 years ago
To round this up and make it last forever... ;-)
These lines in init.rb
solved my problem:
CalendarsController.class_eval do def current_menu_item :issues end end
Cheers!