Alpina Posted July 15, 2024 Posted July 15, 2024 (edited) 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 July 15, 2024 by Alpina
monollonom Posted July 15, 2024 Posted July 15, 2024 (edited) 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 Edited July 15, 2024 by monollonom 2
Alpina Posted July 15, 2024 Author Posted July 15, 2024 Thanks, but if I move there, it gave me an unknown path error.
monollonom Posted July 15, 2024 Posted July 15, 2024 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; });
monollonom Posted July 15, 2024 Posted July 15, 2024 Try moving the page in the page tree (e.g. above "Access" and then back) to clear the navigation cache, then it should work:
Alpina Posted July 15, 2024 Author Posted July 15, 2024 Just out of curiosity.Is there another approach for it? Can you achieve that same outcome without have it under the /admin/ page?
monollonom Posted July 15, 2024 Posted July 15, 2024 The simplest in this case would be to use the module you mentioned in your first post. To me, it’s not so overkill
da² Posted July 15, 2024 Posted July 15, 2024 (edited) 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. Go to modules page Click the tab Configure Find the module Page Edit and click Configure Check to enable bookmarks Go to menu Pages > Edit > Bookmarks Add the bookmark for your page with the corresponding user role (select everyone if no specific role is necessary) Now you can access this page with menu Pages > Edit > Your page Edited July 15, 2024 by da² 3
abmcr Posted October 3, 2024 Posted October 3, 2024 I have used this code in my init function of my module public function init() { $this->addHookAfter('AdminThemeFramework::getPrimaryNavArray', $this, 'addCustomMenuItem'); } public function addCustomMenuItem(HookEvent $event) { $nav = $event->return; // Ottiene l'array della navigazione principale $nav[] = [ 'id' => 0, 'parent_id' => 0, 'name' => '', 'title' => "Newsletter", 'url' => $this->wire('config')->urls->admin. "page/newletter/anteprima", 'children' => [] ]; // Restituisce il menu aggiornato $event->return = $nav; } May be useful... 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now