kongondo Posted May 10, 2023 Author Share Posted May 10, 2023 (edited) 44 minutes ago, Roych said: not realy working. The children are not native children of a page, they are made with MenuBuilder drag&drop option. I want those in my header main menu, but in my footer I only want to show the first row. That's exactly what I said wouldn't work ?. You cannot control non-native children. If the children are MB (drag and drop) children, they are always shown (unless you disable them in the backend using the disable menu item option). I don't understand what you mean by 'not really working'. A little more detail would help. Edited May 10, 2023 by kongondo Link to comment Share on other sites More sharing options...
kongondo Posted May 10, 2023 Author Share Posted May 10, 2023 42 minutes ago, Roych said: Ohhh, with a lot of thinking, this is somehow working But not as expected ? Is your issue resolved then? I see your edit as well but I am still confused. Link to comment Share on other sites More sharing options...
Roych Posted May 10, 2023 Share Posted May 10, 2023 No, still not resolved, I tought that the code above works but when I looked closer it wasn't. So I guess the best approach would be to create another menu for the footer. Link to comment Share on other sites More sharing options...
DV-JF Posted August 15, 2023 Share Posted August 15, 2023 When I sort an existing menu and try to save it I get an error on PHP 8.1.x PW latest stable version: method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given search @kongondo It would be nice if you could fix this based on this issue: https://github.com/kongondo/MenuBuilder/issues/48 Link to comment Share on other sites More sharing options...
Roych Posted August 16, 2023 Share Posted August 16, 2023 I'have a strange problem, my drag and drop is not working anymore not sure why. All the settings are correct and should be working. It's quite annoying, anybody else have this problem? any ideas how to fix this? Menu is published, unlocked. ... Thank you R Link to comment Share on other sites More sharing options...
Clarity Posted October 27, 2023 Share Posted October 27, 2023 Hello, @kongondo! I use the module in this way: I'm creating a site with possibility of creating blank menu without items. On these lines I'm trying to get menu items: $menuBuilder = $this->modules->get('MarkupMenuBuilder'); $this->menuItems = $menuBuilder->getMenuItems($id); Then I get an error: "No menu items found! Confirm that such a menu exists and that it has menu items." if items are not present. This is caused by the line 1366: https://github.com/kongondo/MenuBuilder/blob/main/MarkupMenuBuilder.module#L1366 I tried to fix it manually using the fact that the menu is a page and menu items are being stored in menu_items variable: $menuBuilder = $this->modules->get('MarkupMenuBuilder'); $menu = $this->pages->get($id); if($menu->menu_items) { $this->menuItems = $menuBuilder->getMenuItems($id); } else { return; } However, it seems to be only a workaround. Am I using module correctly? If no, how can I use it to avoid such an error without adding items? If it is not possible, I suggest the following fix: Here https://github.com/kongondo/MenuBuilder/blob/main/MarkupMenuBuilder.module#L1366 return can be replaced from $this->throwError() to [] or array(). I created a new issue here: https://github.com/kongondo/MenuBuilder/issues/50. Can you please see this issue? Link to comment Share on other sites More sharing options...
Roych Posted October 27, 2023 Share Posted October 27, 2023 Maybe something like this? $menuBuilder = $this->modules->get('MarkupMenuBuilder'); $menu = $this->pages->get($id); if ($menu->menu_items->count()) { $this->menuItems = $menuBuilder->getMenuItems($id); } else { // Handle the case where there are no menu items, for example: $this->menuItems = []; // or any other appropriate action } Haven't tested! This code (should) first checks if there are any menu items by using the count() method on the menu_items field. If there are menu items, it proceeds to fetch and assign them using the getMenuItems method from the MenuBuilder module. If there are no items, you can handle it as needed. In the example above, an empty array is assigned to $this->menuItems, but you can customize it to match your specific requirements. This approach allows you to use the MenuBuilder module to create menus with or without items, without triggering the error you mentioned. Cheers, R 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted October 27, 2023 Share Posted October 27, 2023 On 10/27/2023 at 12:55 PM, Roych said: Maybe something like this? $menuBuilder = $this->modules->get('MarkupMenuBuilder'); $menu = $this->pages->get($id); if ($menu->menu_items->count()) { $this->menuItems = $menuBuilder->getMenuItems($id); } else { // Handle the case where there are no menu items, for example: $this->menuItems = []; // or any other appropriate action } Haven't tested! This code (should) first checks if there are any menu items by using the count() method on the menu_items field. If there are menu items, it proceeds to fetch and assign them using the getMenuItems method from the MenuBuilder module. If there are no items, you can handle it as needed. In the example above, an empty array is assigned to $this->menuItems, but you can customize it to match your specific requirements. This approach allows you to use the MenuBuilder module to create menus with or without items, without triggering the error you mentioned. Cheers, R @Roych, as I can see from his post @Clarity is already doing almost the same as you suggested. But he is looking for a cleaner way to handle it that already exist (or asks @kongondoto update the module to provide it). 1 Link to comment Share on other sites More sharing options...
DV-JF Posted January 18 Share Posted January 18 Hi @kongondo any news on this one: I'de run in this error again. Do you have any plans to fix this issue? Greets! 1 Link to comment Share on other sites More sharing options...
Roych Posted March 13 Share Posted March 13 Is it possible to upgrade module to work with PHP 8.2 or 8.3 maybe? It only works on PHP 7.4 at least here ... Thank you R 2 Link to comment Share on other sites More sharing options...
froot Posted May 16 Share Posted May 16 how to return an array of the menu items? So far I was not successful. $menu = $modules->get('MarkupMenuBuilder');// $menu is an example echo $menu->getMenuItems('topmenu'); // topmenu is the name of my menu But it only returns Menu|Menu|Menu How can that be? Link to comment Share on other sites More sharing options...
Nicolas Posted May 16 Share Posted May 16 You need to iterate over the menu items object. <?php $mainMenuItems = $mb->getMenuItems('Main navigation', 2, $options); foreach($mainMenuItems as $menu_item) { // You know have access to $menu_item->title // You know have access to $menu_item->url // See the doc for available $menu_item properties $has_children = ''; $has_children_dropdown = ''; $dropdown = ''; $tag_class = $menu_item->cssClass!=''?$menu_item->cssClass . ' ' . $has_children:$has_children; if($menu_item->isParent) { $has_children = 'has-submenu'; $has_children_dropdown = '<span uk-icon="chevron-down"></span>'; $children = $wire_pages->get($menu_item->pagesID)->children(); $dropdown = '<div uk-dropdown="animation: uk-animation-slide-top-small; duration: 300; animate-out: true; offset: 0; pos: bottom-left"><ul class="uk-nav uk-navbar-dropdown-nav">'; foreach($children as $child) { $dropdown .= '<li><a href="' . $child->url .'">'. $child->title . '</a></li>'; } $dropdown .= '</ul></div>'; } if($menu_item->pagesID == $current_page->parent->id || $menu_item->pagesID == $current_page->id) { $item = '<li class="current-item ' . $tag_class . '"><a href="' . $menu_item->url .'">'. $menu_item->title . $has_children_dropdown . '</a>' . $dropdown . '</li>'; } else { $item = '<li class="'. $tag_class .'"><a href="' . $menu_item->url .'">'. $menu_item->title . $has_children_dropdown . '</a>' . $dropdown . '</li>'; } if($menu_item->parentID == 0) { echo $item; } } 2 Link to comment Share on other sites More sharing options...
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