Jump to content

Really enjoying hooks.


bear

Recommended Posts

Really loving the menu and having to create hooks. No, really. It's great. 

"Knowledgebase" exists in the nav menu twice. I can edit the URI in the support dropdown instance, but also need to do so for the stand alone one that exists on some pages. Everything I've tried, including adding the hooks into one file (Oops!), editing to remove the "support' child (Oops!) from the existing one, making a separate file for each (Oops!). 

Seriously, huge fun. 
Anyone know how to get the knowledgebase, EVERYWHERE THE LINK EXISTS) to go to a new URI? The one below works for the support dropdown, but nothing I've done to it will work on that solo navbar link.

<?php
 
use WHMCS\View\Menu\Item as MenuItem;
 
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
    $navItem = $primaryNavbar->getChild('Support');
    if (is_null($navItem)) {
        return;
    }
 
    $navItem = $navItem->getChild('Knowledgebase');
    if (is_null($navItem)) {
        return;
    }
 
    $navItem->setUri('my link here');
 
});
Edited by bear
long night and day here
Link to comment
Share on other sites

Ah, was not seeing the "navitem" vs "primarynavbar" bit in it. This works. 

	<?php
	use WHMCS\View\Menu\Item as MenuItem;
	add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
    $navItem = $primaryNavbar->getChild('Knowledgebase');
    if (is_null($navItem)) {
        return;
    }
	    $navItem->setUri('my link');
});

sigh

Link to comment
Share on other sites

12 minutes ago, bear said:

Really loving the menu and having to create hooks. No, really. It's great. 

sarcasm is alive and well on a Sunday afternoon. 😛

22 minutes ago, bear said:

"Announcements" exists in the nav menu twice. I can edit the URI in the support dropdown instance, but also need to do so for the stand alone one that exists on some pages. Everything I've tried, including adding the hooks into one file (Oops!), editing to remove the "support' child (Oops!) from the existing one, making a separate file for each (Oops!).

once for non-logged in customers and again for clients... also exists in the Support sidebar too.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
	$newURL = 'https://www.google.com';
	if (!is_null($primaryNavbar->getChild('Announcements'))) {
		$primaryNavbar->getChild('Announcements')
			->setURI($newURL);
	}
	if (!is_null($primaryNavbar->getChild('Support'))) {
		$primaryNavbar->getChild('Support')
			->getChild('Announcements')
			->setURI($newURL);
	}
});

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar)
{
	$newURL = 'https://www.google.com';
	if (!is_null($secondarySidebar->getChild('Support'))) {
		$secondarySidebar->getChild('Support')
			->getChild('Announcements')
			->setURI($newURL);
	}
});

get rid of your hook and try the above... 1st part is the general announcements link that you're trying to change; 2nd is the support announcements link changed by your current hook; and the third changes the sidebar link... there are better ways to do 2 & 3, but assuming no other navbar hooks are modifying them at the same time, they should work fine.

26 minutes ago, bear said:

Anyone know how to get the announcements, EVERYWHERE THE LINK EXISTS) to go to a new URI?

I don't think there would be a generic way to do it with a hook - it would have to loop through all arrays to do it... i'd be tempted to change the link redirection using .htaccess, and that would avoid using hooks... but then you may have Friendly UR:s to contend with depending on where the new link is going to.

off-hand, I can only think of 4 announcements links in the menus - 2 in the navbar, 1 in the sidebar and 1 on the homepage panels...

 

Link to comment
Share on other sites

33 minutes ago, brian! said:

sarcasm is alive and well on a Sunday afternoon

get rid of your hook and try the above...

Sarcasm is just the long hours having to fix all this after avoiding it for a long while. Timing for something like this wasn't the best, so sleep has been nowhere to be found since Friday when it was first seen. 😉

That hook helps quite a lot; shows me how to stack these and have less, at least in the number of files, to get things done. 
As always, thanks. 

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