Benbodhi Posted October 5, 2016 Share Posted October 5, 2016 Hi, I am using a PayPal Billing gateway and have added the menu item to both the ClientAreaPrimaryNavbar and ClientAreaSecondarySidebar using the following in a hook file: <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Billing'))) { $primaryNavbar->getChild('Billing')->addChild('Manage PayPal Billing', array( 'label' => 'Manage PayPal Billing', 'uri' => 'paypalbilling.php', 'order' => '30' )); } }); add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { if (!is_null($secondarySidebar->getChild('Billing'))) { $secondarySidebar->getChild('Billing')->addChild('Manage PayPal Billing', array( 'label' => 'Manage PayPal Billing', 'uri' => 'paypalbilling.php', 'order' => '30' )); } }); Now I need to get the "Billing" menu item to have the class "open" when someone is on the paypalbilling.php page and also highlight the "Manage PayPal Billing" child item under "Billing" with the class "active". Then I need to get the "Manage PayPal Billing" menu item in the ClientAreaSecondarySidebar to be highlighted also with the class "active". Obviously I only need to add the classes when this is the active page. I have a feeling it might be to do with the core paypalbilling.php page not defining breadcrumbs.. but not certain. That custom page code is not open source, so I can't see it or edit it I have tried using "setClass" in this hook in all different ways, but can't figure out the conditional for "if is current page = paypalbilling.php". Any help would be greatly appreciated! Cheers Ben 0 Quote Link to comment Share on other sites More sharing options...
Benbodhi Posted October 5, 2016 Author Share Posted October 5, 2016 I found a hook that can tell what page you're on, but to use this conditional in the menu hooks function bodhi_set_active_classes($vars){ if ($vars['filename']=='paypalbilling'){ // this definitely fires on the correct page } } add_hook('ClientAreaPage', 1, 'bodhi_set_active_classes'); 0 Quote Link to comment Share on other sites More sharing options...
Benbodhi Posted October 5, 2016 Author Share Posted October 5, 2016 I'm almost there, just need to set class on the "Billing" menu item now, it doesn't seem to work like the sub items. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { $filename = basename($_SERVER['REQUEST_URI'], ".php"); $parseFile = explode('.', $filename); if (!is_null($primaryNavbar->getChild('Billing'))) { $primaryNavbar->getChild('Billing')->addChild('Manage PayPal Billing', array( 'label' => 'Manage PayPal Billing', 'uri' => 'paypalbilling.php', 'order' => '30' )); } if ($parseFile['0']=='paypalbilling'){ $primaryNavbar->getChild('Billing')->setClass('active'); // WHY DOES THIS LINE NOT WORK? $primaryNavbar->getChild('Billing')->getChild('Manage PayPal Billing')->setClass('active'); } }); add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $filename = basename($_SERVER['REQUEST_URI'], ".php"); $parseFile = explode('.', $filename); if (!is_null($secondarySidebar->getChild('Billing'))) { $secondarySidebar->getChild('Billing')->addChild('Manage PayPal Billing', array( 'label' => 'Manage PayPal Billing', 'uri' => 'paypalbilling.php', 'order' => '30' )); } if ($parseFile['0']=='paypalbilling'){ $secondarySidebar->getChild('Billing')->getChild('Manage PayPal Billing')->setClass('active'); } }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 5, 2016 Share Posted October 5, 2016 instead of using the $filename two lines of code, you should just need to use the if statement below... if (APP::getCurrentFileName()=="paypalbilling"){ $secondarySidebar->getChild('Billing') ->getChild('Manage PayPal Billing') ->setClass('active'); } and i'm not convinced you can do what you're trying to do to Billing dropdown (re open) without possibly making modifications to navbar.tpl - but i'm not near my notes at the mo, and WHMCS have seemingly removed (or moved) the Class Documentation from their website. 0 Quote Link to comment Share on other sites More sharing options...
Benbodhi Posted October 5, 2016 Author Share Posted October 5, 2016 instead of using the $filename two lines of code, you should just need to use the if statement below... if (APP::getCurrentFileName()=="paypalbilling"){ $secondarySidebar->getChild('Billing') ->getChild('Manage PayPal Billing') ->setClass('active'); } and i'm not convinced you can do what you're trying to do to Billing dropdown (re open) without possibly making modifications to navbar.tpl - but i'm not near my notes at the mo, and WHMCS have seemingly removed (or moved) the Class Documentation from their website. Thanks Brian, I did actually stumble across that also, I ended up being able to replace 3 lines in each function with that single one: if (App::getCurrentFilename() == 'paypalbilling') { $secondarySidebar->getChild('Billing')->getChild('Manage PayPal Billing')->setClass('active'); } It's this parent menu item that's baffling me. I have started looking into the theme menu files to see if there is something I can draw from or add to. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 6, 2016 Share Posted October 6, 2016 It's this parent menu item that's baffling me. I have started looking into the theme menu files to see if there is something I can draw from or add to. take a look in /templates/*six (or custom)*/includes/navbar,tpl - looks to be coded to create a dropdown in a menu has children... I suppose you could remove that, or tweak it with Smarty, and then define classes in the hook. 0 Quote Link to comment Share on other sites More sharing options...
Benbodhi Posted October 6, 2016 Author Share Posted October 6, 2016 Thanks Brian, I ended up finding it in that exact file... I just modified my theme file rather than trying to do it with a hook. All I had to do was add `or $filename eq "paypalbilling"` to the list: {elseif $item->getName() eq "Billing"} {if $templatefile eq "clientareainvoices" or $templatefile eq "clientareaquotes" or $templatefile eq "masspay" or $templatefile eq "clientareacreditcard" or $templatefile eq "clientareaaddfunds" or $filename eq "paypalbilling"} {assign var=itMenuItemActive value="yes"} {assign var=itMenuItemOpen value="yes"} {/if} Thanks for your help. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.