Jump to content

[SOLVED] How do I add an entry to the admin menu?


Alpina
 Share

Recommended Posts

Hi,

This 'simple' task doesn't seem to be so simple after all. I have a "Settings" page and I would like to create a top menu entry in the admin menu for it. How can I do that?

The information I found online is unclear, and the Custom Admin Menus module seems like overkill for my needs. Any help would be appreciated!

Cheers!

Edited by Alpina
Link to comment
Share on other sites

To have your page shown in the admin menu, you have to have it under the /admin/ page. Move it there, reload, and you should see "Settings" in the menu bar.

Edit: actually it's not that simple as the url in the menu is not the one to edit the page! My bad! Let me check for a fix

1774623965_Screenshot2024-07-15at13_43_07.thumb.png.d5f28920c69cfdda762d676008042480.png

Edited by monollonom
  • Like 2
Link to comment
Share on other sites

Yes I noticed it right after posting ?. It’s because the URL is not the one for editing the page. Add this hook to init.php and move back again the page to clear (and update) the navigation bar’s cache:

$wire->addHookAfter("AdminThemeFramework::getPrimaryNavArray", function(HookEvent $event) {
	$settingsPage = $event->pages->get("template=settings"); // replace accordingly
	$primaryNavArray = $event->return;
	foreach($primaryNavArray as &$adminPage) { // pass by reference
		if($adminPage["id"] === $settingsPage->id) {
			$adminPage["url"] = $settingsPage->editUrl();
			break;
		}
	}
	$event->return = $primaryNavArray;
});

 

Link to comment
Share on other sites

  • Alpina changed the title to [SOLVED] How do I add an entry to the admin menu?

I would say the easiest is to add an "edit bookmark" to this page, it requires no module or hook nor moving the page in a specific location.

  1. Go to modules page
  2. Click the tab Configure
  3. Find the module Page Edit and click Configure
  4. Check to enable bookmarks
  5. Go to menu Pages > Edit > Bookmarks
  6. Add the bookmark for your page with the corresponding user role (select everyone if no specific role is necessary)
  7. Now you can access this page with menu Pages > Edit > Your page
Edited by da²
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...