Jump to content

setClass active and open for custom child menu item


Benbodhi

Recommended Posts

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

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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');
}
});

Link to comment
Share on other sites

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. :roll:

Link to comment
Share on other sites

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. :roll:

 

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.

Link to comment
Share on other sites

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. :?:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated