How do I stack component menu items in admin panel

For Joomla! 4.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
MarkRS
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

How do I stack component menu items in admin panel

Post by MarkRS » Thu May 19, 2022 9:52 am

My component has several options so I want to show them as submenus of the main component menu in the admin panel, in the same way that "Privacy" and "Messages" are shown in the Users menu.

I tried looking for the xml definition of the users menu but presumably there's a main admin definition somewhere, I can't find that :-[
It's a community, the more we all contribute, the better it will be.

User avatar
ceford
Joomla! Guru
Joomla! Guru
Posts: 817
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: How do I stack component menu items in admin panel

Post by ceford » Thu May 19, 2022 9:23 pm

You declare the menu structure in the administration section of your component manifest file. Example:

Code: Select all

		<menu img="class:default">bpsrc</menu>
		<submenu>
			<!--
				Note that all & must be escaped to &amp; for the file to be valid
				XML and be parsed by the installer
			-->
			<menu
				link="option=com_bpsrc&amp;view=bpsrc"
				img="default"
			>
				COM_BPSRC_BPSRC
			</menu>
		</submenu>

MarkRS
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: How do I stack component menu items in admin panel

Post by MarkRS » Fri May 20, 2022 9:42 am

Thanks for that.

I got that far, but I can't seem to get a second level of submenu, which is what I want. What I've got is

Code: Select all

<menu>Top Level</menu>
	<submenu>
		<menu link="option=com_myComponent&amp;task=x.display&amp;view=x&amp;alt=MyComponent/X">COM_MYC_X</menu>
        	<menu>Infrastructure>
 			<submenu>
				<menu link="option=com_myComponent&amp;task=y.display&amp;view=y&amp;alt=myComponent/Y">COM_MM_Y</menu>
				<menu link="option=com_myComponent&amp;task=z.display&amp;view=z&amp;alt=myComponent/Z">COM_MM_Z</menu>
			</submenu>
		</menu>
	</submenu>
expecting to see a link for "X" and then an "Infrastructure" line with a submenu of y & z.
The Infrastructure line is just a line, when I click it I get the default option for the component, not a submenu.
I have re-installed the component with this change.
What am I missing?
It's a community, the more we all contribute, the better it will be.

User avatar
ceford
Joomla! Guru
Joomla! Guru
Posts: 817
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: How do I stack component menu items in admin panel

Post by ceford » Fri May 20, 2022 9:55 am

Fix the typo: you need </menu> after Infrastructure

MarkRS
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: How do I stack component menu items in admin panel

Post by MarkRS » Fri May 20, 2022 4:12 pm

That warn't no typo, I thought it worked like that! :D :'(
I was expecting the menu tag to be a well-formed-like construct.

Anyway, I made that change, and it doesn't make a difference. To be clear, what I want to see is something like the user menu
Wanted.png
the first nested menu (Privacy) is open while the second (Messaging) is shut, clicking on them opens and closes the submenu for selection.

What I'm getting is
got.png

where clicking on Infrastructure or API just takes me to my component's default option.

Thanks for helping me with this.
You do not have the required permissions to view the files attached to this post.
It's a community, the more we all contribute, the better it will be.

User avatar
ceford
Joomla! Guru
Joomla! Guru
Posts: 817
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: How do I stack component menu items in admin panel

Post by ceford » Fri May 20, 2022 5:08 pm

Seems I do not know how to create a second level admin menu. The Privacy structure is declared in administrator/components/com_menus/presets/default.xml.

MarkRS
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: How do I stack component menu items in admin panel

Post by MarkRS » Fri May 20, 2022 5:23 pm

You and me both ;) , or in fact :(

Does that (also) mean you don't know how that xml file filters through to component installation?
It's a community, the more we all contribute, the better it will be.

User avatar
ceford
Joomla! Guru
Joomla! Guru
Posts: 817
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: How do I stack component menu items in admin panel

Post by ceford » Fri May 20, 2022 6:38 pm

Reading the code in libraries/src/Installer/Adapter/ComponentAdapter from line 1082 it looks like there is provision for only one level of submenu.

MarkRS
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: How do I stack component menu items in admin panel

Post by MarkRS » Fri May 20, 2022 7:03 pm

Hmm, we've got facilities you can't have?

Do you know anything about that "presets" thing? I notice a couple of the core components have it (well, com_content anyway). Is that the alternative strategy d'you think?
It's a community, the more we all contribute, the better it will be.

User avatar
ceford
Joomla! Guru
Joomla! Guru
Posts: 817
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: How do I stack component menu items in admin panel

Post by ceford » Fri May 20, 2022 8:19 pm

I suggest you see what you can do with a new Admin menu. You can import presets - I don't know how to make your own off-hand. You can create your own menu structure so you might be able to do what you need just as you would for a front-end menu. You may need this:

https://docs.joomla.org/J4.x:Adding_a_C ... rator_Menu

MarkRS
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: How do I stack component menu items in admin panel

Post by MarkRS » Fri May 20, 2022 8:35 pm

Oooh, that's quite interesting.

Not directly helpful for what I really want, but it might point the way. Many thanks.
It's a community, the more we all contribute, the better it will be.


Post Reply

Return to “Joomla! 4.x Coding”