KyleJ144 Posted February 3, 2018 Share Posted February 3, 2018 Hey guys, I have look everywhere and i finally managed to add a further menu item but i want the menu item to be a dropdown as i want to add "Windows Dedicated Servers" and "Linux Dedicated Servers to the new drop down menu and i want them to be removed from the web hosting drop down. I have enclosed 2 screenshots of what i mean the first one contains the drop down menu where i want the above to be deleted from and the second one contains the new menu item that i want to add the above and make a drop down menu. Any help would be greatly appreciated as i have tried following guides and adding hooks but nothing seems to me working. Thanks in advance Kind Regards Kyle Link to comment Share on other sites More sharing options...
brian! Posted February 4, 2018 Share Posted February 4, 2018 Hi Kyle, 19 hours ago, KyleJ144 said: I have look everywhere and i finally managed to add a further menu item but i want the menu item to be a dropdown as i want to add "Windows Dedicated Servers" and "Linux Dedicated Servers to the new drop down menu and i want them to be removed from the web hosting drop down. there are two important points to remember with these navbar menus... dropdowns will be created automatically when you add items to that specific menu - so if you added a link to the "Dedicated Servers" menu item, the dropdown would be added. you can't move items between separate menus - you have to delete from the first, and then recreate them in the second. so let's say that you want to split the "Store" dropdown into 3 separate menus - Web Hosting, Dedicated Servers & Domains (which you asked me about in a PM)... as a starting point, i'm going to use the hook that I posted in the thread below that renamed "Store" to "Web Hosting"... it's perfectly acceptable to do this using multiple hook files, but if you have many hooks modifying the same menu, you can easily cause issues if they aren't all coded correctly... so for the sake of time, i'll just use the one file. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { $client = Menu::context('client'); if (!is_null($primaryNavbar->getChild('Store'))) { $primaryNavbar->getChild('Store') ->setLabel('Web Hosting') ->removeChild('Linux Dedicated Server') ->removeChild('Windows Dedicated Servers') ->removeChild('Register a New Domain') ->removeChild('Transfer a Domain to Us'); } if (is_null($client) && is_null($primaryNavbar->getChild('Dedicated Servers'))) { $primaryNavbar->addChild('Dedicated Servers', array( 'label' => 'Dedicated Servers', 'order' => 16,)); } if (is_null($client) && !is_null($primaryNavbar->getChild('Dedicated Servers'))) { $primaryNavbar->getChild('Dedicated Servers') ->addChild('Linux Dedicated Server', array( 'label' => 'Linux Dedicated Server', 'uri' => 'cart.php?gid=3', 'order' => 10,)); $primaryNavbar->getChild('Dedicated Servers') ->addChild('Windows Dedicated Servers', array( 'label' => 'Windows Dedicated Servers', 'uri' => 'cart.php?gid=2', 'order' => 10,)); } if (is_null($client) && is_null($primaryNavbar->getChild('Domain Names'))) { $primaryNavbar->addChild('Domain Names', array( 'label' => Lang::trans('navdomains'), 'order' => 18,)); } if (is_null($client) && !is_null($primaryNavbar->getChild('Domain Names'))) { $primaryNavbar->getChild('Domain Names') ->addChild('Register Domain', array( 'label' => Lang::trans('navregisterdomain'), 'uri' => 'cart.php?a=add&domain=register', 'order' => 10,)); $primaryNavbar->getChild('Domain Names') ->addChild('Transfer Domain', array( 'label' => Lang::trans('navtransferdomain'), 'uri' => 'cart.php?a=add&domain=transfer', 'order' => 20,)); } }); a few things to note with the above file... because the "Store" menu is only visible for non-logged in clients, when creating the new additional menus, we need to check if the client is logged in - if they are, we do not create the new menus... if they are, we do. I haven't moved/removed all of the items from Web Hosting - but hopefully you can see what i've done in the above code... e.g adding them to the new menu and removing from the old. where I can, i've used existing language strings for the labels... so Register/Transfer domain will translate to the equivalent language string when changing the language from the dropdown... the others, such as "Dedicated Servers" will not.... but if you need it to, you can go sown the road of using Language Overrides. there's an argument that it might be easier to just delete the "Store" menu and create 3 new menus from scratch... not least because when you add a new product group, it will now automatically add it under "Web Hosting". as there is only limited space on the navbar, be aware that by adding these 3 menus, you may need to remove/consolidate the remaining menus... especially check how the menu looks in other languages. it's probably also worth mentioning that there are a few products in Marketplace that would allow you to easily manage the menus... https://marketplace.whmcs.com/product/582 https://marketplace.whmcs.com/product/1414 now in an ideal world, these tools shouldn't be necessary as WHMCS should either never have used a navigation system that required users to write hooks to modify them, or built similar modifying tools into the main program.... perhaps as you're now learning the basics, you won't need to buy such addons, but I just mention them in case you do to save time in the future. 1 Link to comment Share on other sites More sharing options...
KyleJ144 Posted February 4, 2018 Author Share Posted February 4, 2018 1 hour ago, brian! said: Hi Kyle, there are two important points to remember with these navbar menus... dropdowns will be created automatically when you add items to that specific menu - so if you added a link to the "Dedicated Servers" menu item, the dropdown would be added. you can't move items between separate menus - you have to delete from the first, and then recreate them in the second. so let's say that you want to split the "Store" dropdown into 3 separate menus - Web Hosting, Dedicated Servers & Domains (which you asked me about in a PM)... as a starting point, i'm going to use the hook that I posted in the thread below that renamed "Store" to "Web Hosting"... it's perfectly acceptable to do this using multiple hook files, but if you have many hooks modifying the same menu, you can easily cause issues if they aren't all coded correctly... so for the sake of time, i'll just use the one file. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { $client = Menu::context('client'); if (!is_null($primaryNavbar->getChild('Store'))) { $primaryNavbar->getChild('Store') ->setLabel('Web Hosting') ->removeChild('Linux Dedicated Server') ->removeChild('Windows Dedicated Servers') ->removeChild('Register a New Domain') ->removeChild('Transfer a Domain to Us'); } if (is_null($client) && is_null($primaryNavbar->getChild('Dedicated Servers'))) { $primaryNavbar->addChild('Dedicated Servers', array( 'label' => 'Dedicated Servers', 'order' => 16,)); } if (is_null($client) && !is_null($primaryNavbar->getChild('Dedicated Servers'))) { $primaryNavbar->getChild('Dedicated Servers') ->addChild('Linux Dedicated Server', array( 'label' => 'Linux Dedicated Server', 'uri' => 'cart.php?gid=3', 'order' => 10,)); $primaryNavbar->getChild('Dedicated Servers') ->addChild('Windows Dedicated Servers', array( 'label' => 'Windows Dedicated Servers', 'uri' => 'cart.php?gid=2', 'order' => 10,)); } if (is_null($client) && is_null($primaryNavbar->getChild('Domain Names'))) { $primaryNavbar->addChild('Domain Names', array( 'label' => Lang::trans('navdomains'), 'order' => 18,)); } if (is_null($client) && !is_null($primaryNavbar->getChild('Domain Names'))) { $primaryNavbar->getChild('Domain Names') ->addChild('Register Domain', array( 'label' => Lang::trans('navregisterdomain'), 'uri' => 'cart.php?a=add&domain=register', 'order' => 10,)); $primaryNavbar->getChild('Domain Names') ->addChild('Transfer Domain', array( 'label' => Lang::trans('navtransferdomain'), 'uri' => 'cart.php?a=add&domain=transfer', 'order' => 20,)); } }); a few things to note with the above file... because the "Store" menu is only visible for non-logged in clients, when creating the new additional menus, we need to check if the client is logged in - if they are, we do not create the new menus... if they are, we do. I haven't moved/removed all of the items from Web Hosting - but hopefully you can see what i've done in the above code... e.g adding them to the new menu and removing from the old. where I can, i've used existing language strings for the labels... so Register/Transfer domain will translate to the equivalent language string when changing the language from the dropdown... the others, such as "Dedicated Servers" will not.... but if you need it to, you can go sown the road of using Language Overrides. there's an argument that it might be easier to just delete the "Store" menu and create 3 new menus from scratch... not least because when you add a new product group, it will now automatically add it under "Web Hosting". as there is only limited space on the navbar, be aware that by adding these 3 menus, you may need to remove/consolidate the remaining menus... especially check how the menu looks in other languages. it's probably also worth mentioning that there are a few products in Marketplace that would allow you to easily manage the menus... https://marketplace.whmcs.com/product/582 https://marketplace.whmcs.com/product/1414 now in an ideal world, these tools shouldn't be necessary as WHMCS should either never have used a navigation system that required users to write hooks to modify them, or built similar modifying tools into the main program.... perhaps as you're now learning the basics, you won't need to buy such addons, but I just mention them in case you do to save time in the future. Thank you. This has bee greatly appreciated Link to comment Share on other sites More sharing options...
KyleJ144 Posted February 4, 2018 Author Share Posted February 4, 2018 Been* Link to comment Share on other sites More sharing options...
Recommended Posts