Creation of menu

Hello All,

I have two separate plugins where i have created two separate menu items .

Now i want to combined both menus under common menu item:

I have created main menu into the first plugin:

sub_menu :top_menu, :ConfigMonitor, :caption=> N_('Config-Monitor'),
:after=> :infrastructure_menu do
menu :top_menu, :level1, :caption=>N_('Versions'), :url_hash =>
{:controller=> :'foreman_config_monitor/versions', :action=>:version}

And create second menu under second plugin:

menu :top_menu, :patchmanagement, url_hash => {:controller=>
:'foreman_patch_management/patchmanagements', :action=>:patchstatus},
:caption=> N_(''Patch-Management'),
:parent => :ConfigMonitor,
:first => true

but i am unable to create submenu under custom menu item.that is not

But if i changed parent to existing menu item like "host_menu" then it is
working fine.

Could you please help.


I never tried to add items into plugin's menu from another plugin, but I
think the issue here is that plugin registration is not ordered in any way.
So if you have plugin A with

sub_menu :top_menu, :ConfigMonitor

and plugin B with:

menu :top_menu, :patchmanagement, :parent => :ConfigMonitor

your B plugin may be registered before A, so B is trying to add items into
menu that does not yet exist.
You can get list of already registered plugins if you put a breakpoint
right before the Foreman::Plugin.register block in your Engine
and call Foreman::Plugin.registered_plugins

You could try to create a third plugin, whose sole purpose would be to add
menu into navbar and make it a dependency for your existing plugins. Then
adding the items into common menu could work, but I haven't really tried it.