Jump to content

How to Modify Navigation References


NorthCC

Recommended Posts

I have been looking through the documentation and the forums but nothing seems to answer the question fully: how does one change all navigational references for Knowledgebase, Tickets under Support, Contact Us, and Announcements?

The idea is to redirect these navigational links from the WHMCS' https://domain.com/submitticket.php to https://help.domain.com/{rest of URI}

I found this snippet of code but it does not modify the navigation across the entire platform (Code is truncated in some spots for links due to Nano mode selected to write script):

<?php
use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild('Announcements'))) {
       $primaryNavbar->getChild('Announcements')
                   ->setURI('http://domain.com/announcements');
   }
   if (!is_null($primaryNavbar->getChild('Knowledgebase'))) {
       $primaryNavbar->getChild('Knowledgebase')
                   ->setURI('https://help.domain.com');
  }
   if (!is_null($primaryNavbar->getChild('Open Ticket'))) {
       $primaryNavbar->getChild('Open Ticket')
                   ->setURI('https://help.domain.com/hc/en-us/requests/new?ticket_form$
  }
   if (!is_null($primaryNavbar->getChild('Contact Us'))) {
          $primaryNavbar->getChild('Contact Us')
                   ->setURI('https://help.domain.com/hc/en-us/requests/new?ticket_form$
  }

});

Is there a way to modify these links across the entire platform?

 

Link to comment
Share on other sites

21 hours ago, NorthCC said:

Is there a way to modify these links across the entire platform?

not a nice way - other than modifying the links in the navbar/sidebar/panels with hooks... though they wouldn't change any links that were shown in other template, or generated internally outside of the navigation.

I could be tempted to suggest htaccess redirection, but then you're potentially fighting against Friendly URLs settings and redirection loops.... though you could try it with one link type and see if it works, and then expand if it does.

Link to comment
Share on other sites

9 hours ago, brian! said:

not a nice way - other than modifying the links in the navbar/sidebar/panels with hooks... though they wouldn't change any links that were shown in other template, or generated internally outside of the navigation.

I could be tempted to suggest htaccess redirection, but then you're potentially fighting against Friendly URLs settings and redirection loops.... though you could try it with one link type and see if it works, and then expand if it does.

How can I hook into the Navbar/Sidebar/Panels universally? While I read the documentation it seems I'm missing something starting with the Navbar which only changes the links with the hook code if one is logged in.

After that, I think modify the htaccess for the directory to ensure all links are sent to the actual help center (ZenDesk) so that users work through the ZenDesk interface and not WHMCS would be something to try.

Link to comment
Share on other sites

10 hours ago, NorthCC said:

While I read the documentation it seems I'm missing something starting with the Navbar which only changes the links with the hook code if one is logged in.

that's not true - you can change the links (navbar/sidebar/panel) whether the user is logged in or not... you can even determine if they're logged in and send them to one of multiple different urls depending on whether they are or not... and who they are.

sometimes, you can be lazy, e.g as you did in your hook above, because you know (or can assume) a particular link is client only, e.g Open Ticket... only clients see that link, so you don't have to check whether they're logged in or not... other links, such as Home are shown to everyone, but their links change whether the user is logged in or not (clientarea.php / index.php)... so a trivial example hook, redirecting the home link to Google if they're logged in , Twitter if they're not...

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
	$client = Menu::context('client');
	if (!is_null($primaryNavbar->getChild('Home'))) {
		if ($client) {
			$primaryNavbar->getChild('Home')->setUri('https://google.com');
		} else {
			$primaryNavbar->getChild('Home')->setUri('https://twitter.com');
		}
	}
});
10 hours ago, NorthCC said:

How can I hook into the Navbar/Sidebar/Panels universally?

can I say "not in a nice way" again ?

there would be nothing to stop you using ClientAreaNavbars/Sidebars, getting the content of both navbars/sidebars in the hooks, looping through them and modifying URLs (e.g replace a with b, c with d etc) when you find an applicable link... but whether you should run such a hook every time the user changes pages, I doubt.

if htaccess works, then that's possibly going to be easier because you won't have to work through finding each link to change in the navigation (though I doubt there will be that many), the htaccess will just react to the specified rules.

Link to comment
Share on other sites

My solution ultimately ended up being a hybrid of the choices.

Using your code I was able to derive a hook that would change the navigation links while logged in or not logged in. Following that, I derived from WHMCS' sample code on changing the links of the drop down menus (this was causing the most headache). Finally, to handle the panels which looked like it would involve quite a lot of time that's not worth it when htaccess can do the job, used htaccess to do a mod_rewrite of the various client panel links to ZenDesk specific areas.

Ultimately, while not elegant given this is something that really should require writing hooks for, I did manage to convert all the links I wanted to convert.

Link to comment
Share on other sites

On 03/06/2020 at 11:16, NorthCC said:

Finally, to handle the panels which looked like it would involve quite a lot of time that's not worth it when htaccess can do the job, used htaccess to do a mod_rewrite of the various client panel links to ZenDesk specific areas.

it wouldn't have been difficult to write hooks to modify the links top-right of a panel - they'd be very similar to a sidebar/navbar hook... the real pain would have been any links within the bodies of the panels.

X1zk74K.png

<?php

use WHMCS\View\Menu\Item;

add_hook('ClientAreaHomepagePanels', 1, function(Item $homePagePanels)
{
	if (!is_null($homePagePanels->getChild('Recent Support Tickets'))) {
		$homePagePanels->getChild('Recent Support Tickets')->setExtra('btn-link','https://www.google.com');
	}
});

btw - it might be useful to share your rewrite rules (rename your links/domains) just in case someone wants to do this in the future.

On 03/06/2020 at 11:16, NorthCC said:

Ultimately, while not elegant given this is something that really should require writing hooks for, I did manage to convert all the links I wanted to convert.

very often with WHMCS, you can forego elegance just to get the job done - little point wasting time on elegance if/when the next update might kill your the solution and you're back to square one.

Link to comment
Share on other sites

  • 4 months later...
5 hours ago, jacksony said:

Anyone has the code to change the highlighted one in the png?

the links for those tiles are defined in the clientareahome.tpl template - for tickets, it would be...

        <div class="col-sm-3 col-xs-6 tile" onclick="window.location='supporttickets.php'">
            <a href="supporttickets.php">
                <div class="icon"><i class="fas fa-comments"></i></div>
                <div class="stat">{$clientsstats.numactivetickets}</div>
                <div class="title">{$LANG.navtickets}</div>
                <div class="highlight bg-color-red"></div>
            </a>
        </div>

these tiles aren't modified/created by way of the navbar/sidebar/panel type of menu hooks - so you either have to edit the template and change the URL, or use a JavaScript header output hook, limited to this page only to change the link URL.

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