kongondo Posted May 10, 2023 Author 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
kongondo Posted May 10, 2023 Author 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.
Roych Posted May 10, 2023 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.
DV-JF Posted August 15, 2023 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
Roych Posted August 16, 2023 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
Clarity Posted October 27, 2023 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?
Roych Posted October 27, 2023 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
Ivan Gretsky Posted October 27, 2023 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
DV-JF Posted January 18, 2024 Posted January 18, 2024 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
Roych Posted March 13, 2024 Posted March 13, 2024 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
froot Posted May 16, 2024 Posted May 16, 2024 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?
Nicolas Posted May 16, 2024 Posted May 16, 2024 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
Ivan Gretsky Posted December 8, 2024 Posted December 8, 2024 How are you doing, @kongondo! Your module is a blast! Still finding some really cool ways to use it to control how menus could be controlled from the admin. The thing that really worries me is that the module seems to be not fully compatible with newer versions of php. https://github.com/kongondo/MenuBuilder/issues/48 https://github.com/kongondo/MenuBuilder/issues/54 Is there a chance you could find some time to upgrade it anytime soon? Or are you willing to accept PRs with fixes? I can see one that is not dealt with yet, so curious if me or someone else should try to come up with solutions with compatibility problems? Thanks!
Roych Posted December 9, 2024 Posted December 9, 2024 (edited) Hey, I had the same problem, and I think I found the bug it is working for me. I added the fix that is working for me here. I'm in PHP8.3 and it works. here is the fixed module: ProcessMenuBuilder.zip cheers R Edited December 9, 2024 by Roych 1
Ivan Gretsky Posted December 9, 2024 Posted December 9, 2024 5 hours ago, Roych said: I added the fix that is working for me here. I'm in PHP8.3 and it works. Great! Did you create a PR, so we can like it and make it easier for @kongondo to fix this for all of us?
Roych Posted December 9, 2024 Posted December 9, 2024 (edited) 3 minutes ago, Ivan Gretsky said: Did you create a PR Not sure what you mean by PR? I just posted by replying. Edited December 9, 2024 by Roych
Ivan Gretsky Posted December 9, 2024 Posted December 9, 2024 I mean pull request in the module repo - https://github.com/kongondo/MenuBuilder/pulls Thanks for the code! I've seen it. But didn't try yet. A github pull request is just an easier way to deal with code change proposals. 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