Jump to content

Changing Breadcrumbs - display EVERY step of the Navigation


Sybille

Recommended Posts

Hi,

 

I'm new to WHMCS and I would really appreciate your help.

I have a similar question as in threat “Changing-Breadcrumbs”

http://forum.whmcs.com/showthread.php?2286-Changing-Breadcrumbs

 

It would be useful if the breadcrumb nav would display EVERY step of the Navigation.

And the menu "Support" is not needed in the nav.

 

at the moment the navigation displays:

Support -> customer center -> my Domains

 

I would prefere:

customer center -> menu -> submenu

for example: customer center -> Domain -> my Domains

 

I really appreciate your help. Thanks in advanced.

Link to comment
Share on other sites

Hi Sentq

 

Thanks for your reply. :) Because I'm new :?: to WHMCS I would really appreciate if you could give me some more details.

I just created the hook as followed. But I don't know what I have to fill in, because the values are depending on the menu the user clicked at and I don't know the variable for the menu nor the submenu are.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPage', 1, function(MenuItem $[b]???[/b])
{
$return = array();
$return = array("[b]field1[/b]" => "[b]value1[/b]", "[b]field2[/b]" => "[b]value2[/b]");
return $return;
});

Link to comment
Share on other sites

Sybille,

 

Create new PHP file inside /includes/hooks/ directory, copy the following code inside it

 

<?php


add_hook("ClientAreaPage", 1, function($vars){

   # Get Current Breadcrumb & Apply Changes To
   foreach ($vars['breadcrumb'] as $index => $item){

       $item['link']; // Link
       $item['label']; // Title

       # Example Change First Link Title To "Dashboard"
       if ($index==0){
           $vars['breadcrumb'][$index]['label'] = "Dashboard";
       }

   }

   # Return Updated Breadcrumb To Smarty
   return array("breadcrumb" => $vars['breadcrumb']);

});

 

this should give you basic idea of how you can apply changes to breadcrumbs

Link to comment
Share on other sites

Hi Sentq,

 

Thanks for your script. With it it's possible to add a new fix menu item to the breadcrumb. I'd like to add the main menu (e.g. Services, Billing, Domain, Support and so on) as well in to the breadcrumb (of course without link, because neither of the main menu has an own page). The user should be able to see, which main menu he have clicked on to get to the sub menu he is at the moment.

 

for example:

- customer center -> Domain -> my Domains

- customer center -> Billing -> my Quote

 

Perhaps my explanation is a little bit complicated - sorry for that.

greets

Link to comment
Share on other sites

I think the simplest way to do that would require you to define which submenu items belong to which "menu" - the hook won't know unless you tell it! :)

 

if your site was only using one language, then you could probably have coded this to react to label values - you still can if you use language strings in the arrays, but then you'd potentially run into issues if you had changed the labels on these submenus via hooks... therefore, it's easier to use the links which should always be the same for all languages... although weirdly, i've had to make an exception to that because some of the support pages were not responding correctly to the link values... not sure why, it's probably something obvious i'm missing, but it should work ok with labels... though you might want to test it thoroughly. :idea:

 

<?php

add_hook("ClientAreaPage", 1, function($vars){

   $domains = array('clientarea.php?action=domains');
   $billing = array('clientarea.php?action=invoices','clientarea.php?action=quotes','clientarea.php?action=masspay&all=true#','clientarea.php?action=addfunds');
   $services = array('clientarea.php?action=products');
   $tickets = array('supporttickets.php');
   $myaccount = array('clientarea.php?action=details','clientarea.php?action=contacts','clientarea.php?action=changepw','clientarea.php?action=security','clientarea.php?action=emails');
   $support = array(Lang::trans('knowledgebasetitle'),Lang::trans('announcementstitle'),Lang::trans('downloadstitle'),Lang::trans('serverstatustitle'));

   # Get Current Breadcrumb & Apply Changes To
   foreach ($vars['breadcrumb'] as $index => $item){

       $item['link']; // Link
       $item['label']; // Title

       # Example Change First Link Title To "Customer Center"
       if ($index==0){
           $vars['breadcrumb'][$index]['label'] = "Customer Center";
       }

       # Change Other Labels To Their Parent Menu Array Label
       if (in_array($vars['breadcrumb'][$index]['link'],$domains)) {
           $vars['breadcrumb'][$index-1]['label'] = Lang::trans('navdomains');    
       }
       elseif (in_array($vars['breadcrumb'][$index]['link'],$billing)) {
           $vars['breadcrumb'][$index-1]['label'] = Lang::trans('navbilling');    
       }
       elseif (in_array($vars['breadcrumb'][$index]['link'],$services)) {
           $vars['breadcrumb'][$index-1]['label'] = Lang::trans('navservices');    
       }
       elseif (in_array($vars['breadcrumb'][$index]['link'],$tickets)) {
           $vars['breadcrumb'][$index-1]['label'] = Lang::trans('navsupport');    
       } 
       elseif (in_array($vars['breadcrumb'][$index]['link'],$myaccount)) {
           $vars['breadcrumb'][$index-1]['label'] = Lang::trans('myaccount');
           break;
       } 
       elseif (in_array($vars['breadcrumb'][$index]['label'],$support)) {
           $newentry = array("link"=>"","label"=>Lang::trans('navsupport'));
           array_splice($vars['breadcrumb'],$index,0,array($newentry));
           break;            
       }          
   }

   # Return Updated Breadcrumb To Smarty
   return array("breadcrumb" => $vars['breadcrumb']);
});

that would work in the client area by renaming both the initial breadcrumb to "Customer Center", and renaming "Client Area" to the menu label (as defined in the hook).

 

where the above method doesn't quite work is on some of the support pages (kb, network status etc) because they don't include "Client Area" in the breadcrumb array, and so there is nothing to rename...

 

for these submenus, i've inserted the appropriate(?) menu ('Support') into the array and ensured that it's only added once.

 

I was working from memory on the CA links, so you should probably go through the client area as I have likely missed some out - if so, then you either need to assign them to an existing array, or create a new array and add an appropriate elseif block of code in the hook.

Edited by brian!
Link to comment
Share on other sites

Hi Brian,

 

Thanks for the script. I'd worked almost fine. But I'm still working on the fine tuning.

The name of the main menu (e.g. Domain, billing, Support and so on) links in the breadcrumb to home / custom center, but I would prefer, that the name of the menu is just displayed but without a link function.

 

Home (link) / Domain (without link) / My Domains (without link)

 

Because I'm still working on that, I haven't answered till now - I'm sorry.

Link to comment
Share on other sites

the quick solution to that would be to modify templates/six(or your custom)/includes/breadcrumb.tpl and change...

 

<ol class="breadcrumb">
   {foreach $breadcrumb as $item}
       <li{if $item@last} class="active"{/if}>
           {if !$item@last}<a href="{$item.link}">{/if}
           {$item.label}
           {if !$item@last}</a>{/if}
       </li>
   {/foreach}
</ol>

to...

 

<ol class="breadcrumb">
   {foreach $breadcrumb as $item}
       <li{if !$item@first} class="active"{/if}>
           {if $item@first}<a href="{$item.link}">{/if}
           {$item.label}
           {if $item@first}</a>{/if}
       </li>
   {/foreach}
</ol>

that should link the first breadcrumb, and not the others... :idea:

 

there will possibly be a way to do it in the hook, but i'm having a few days away with friends to celebrate my birthday this weekend, so I probably won't be back until next week.

birthday.gif

Link to comment
Share on other sites

That helped a lot :)

 

I've changed the script a little bit, because I'd liked to remove the "Support". It worked fine, but now there is a space where "Support" was before.

 

 

<ol class="breadcrumb">
   {foreach $breadcrumb[b]|replace:'Support':'' as $item[/b]}
       <li{if !$item@first} class="active"{/if}>
           {if $item@first}<a href="{$item.link}">{/if}
           {$item.label}
           {if $item@first}</a>{/if}
       </li>
   {/foreach}
</ol>

 

Breadcrumb_Navigation.png

 

Your reply doesn't rush. I don't congratulate now, because to congratulate in advanced means bad luck.

Enjoy your time and have an awesome time with your friends.

Have a great trip!

Link to comment
Share on other sites

  • 2 weeks later...

you can't throw a replace into the middle of a foreach loop - though even if you could, it would only work for English! :)

 

the solution would be to first leave the breadcrumb template changes as they were...

 

<ol class="breadcrumb">
   {foreach $breadcrumb as $item}
       <li{if !$item@first} class="active"{/if}>
           {if $item@first}<a href="{$item.link}">{/if}
           {$item.label}
           {if $item@first}</a>{/if}
       </li>
   {/foreach}
</ol>

and then in the hook, simply modify the arrays and remove any URLs that you don't want to add "Support" to...

 

    $tickets = array('supporttickets.php');
   $myaccount = array('clientarea.php?action=details','clientarea.php?action=contacts','clientarea.php?action=changepw','clientarea.php?action=security','clientarea.php?action=emails');
   $support = array(Lang::trans('knowledgebasetitle'),Lang::trans('announcementstitle'),Lang::trans('downloadstitle'),Lang::trans('serverstatustitle'));

Link to comment
Share on other sites

  • 1 year later...
On 13/06/2016 at 5:25 PM, brian! said:

I think the simplest way to do that would require you to define which submenu items belong to which "menu" - the hook won't know unless you tell it! :)

 

if your site was only using one language, then you could probably have coded this to react to label values - you still can if you use language strings in the arrays, but then you'd potentially run into issues if you had changed the labels on these submenus via hooks... therefore, it's easier to use the links which should always be the same for all languages... although weirdly, i've had to make an exception to that because some of the support pages were not responding correctly to the link values... not sure why, it's probably something obvious i'm missing, but it should work ok with labels... though you might want to test it thoroughly. :idea:

 

 


<?php

add_hook("ClientAreaPage", 1, function($vars){

   $domains = array('clientarea.php?action=domains');
   $billing = array('clientarea.php?action=invoices','clientarea.php?action=quotes','clientarea.php?action=masspay&all=true#','clientarea.php?action=addfunds');
   $services = array('clientarea.php?action=products');
   $tickets = array('supporttickets.php');
   $myaccount = array('clientarea.php?action=details','clientarea.php?action=contacts','clientarea.php?action=changepw','clientarea.php?action=security','clientarea.php?action=emails');
   $support = array(Lang::trans('knowledgebasetitle'),Lang::trans('announcementstitle'),Lang::trans('downloadstitle'),Lang::trans('serverstatustitle'));

   # Get Current Breadcrumb & Apply Changes To
   foreach ($vars['breadcrumb'] as $index => $item){

       $item['link']; // Link
       $item['label']; // Title

       # Example Change First Link Title To "Customer Center"
       if ($index==0){
           $vars['breadcrumb'][$index]['label'] = "Customer Center";
       }

       # Change Other Labels To Their Parent Menu Array Label
       if (in_array($vars['breadcrumb'][$index]['link'],$domains)) {
           $vars['breadcrumb'][$index-1]['label'] = Lang::trans('navdomains');    
       }
       elseif (in_array($vars['breadcrumb'][$index]['link'],$billing)) {
           $vars['breadcrumb'][$index-1]['label'] = Lang::trans('navbilling');    
       }
       elseif (in_array($vars['breadcrumb'][$index]['link'],$services)) {
           $vars['breadcrumb'][$index-1]['label'] = Lang::trans('navservices');    
       }
       elseif (in_array($vars['breadcrumb'][$index]['link'],$tickets)) {
           $vars['breadcrumb'][$index-1]['label'] = Lang::trans('navsupport');    
       } 
       elseif (in_array($vars['breadcrumb'][$index]['link'],$myaccount)) {
           $vars['breadcrumb'][$index-1]['label'] = Lang::trans('myaccount');
           break;
       } 
       elseif (in_array($vars['breadcrumb'][$index]['label'],$support)) {
           $newentry = array("link"=>"","label"=>Lang::trans('navsupport'));
           array_splice($vars['breadcrumb'],$index,0,array($newentry));
           break;            
       }          
   }

   # Return Updated Breadcrumb To Smarty
   return array("breadcrumb" => $vars['breadcrumb']);
});
 

 

that would work in the client area by renaming both the initial breadcrumb to "Customer Center", and renaming "Client Area" to the menu label (as defined in the hook).

 

where the above method doesn't quite work is on some of the support pages (kb, network status etc) because they don't include "Client Area" in the breadcrumb array, and so there is nothing to rename...

 

for these submenus, i've inserted the appropriate(?) menu ('Support') into the array and ensured that it's only added once.

 

I was working from memory on the CA links, so you should probably go through the client area as I have likely missed some out - if so, then you either need to assign them to an existing array, or create a new array and add an appropriate elseif block of code in the hook.

Hello,

I saw your publication and tested for a  similar problem.

But that does not change my breadcrumb, does it still work on the latest version of WHMCS?

 

Thank you in advance

Cordially

Link to comment
Share on other sites

52 minutes ago, sentq said:

dans quelle (s) page (s) vous essayez de changer exactement la miette de pain?

Hello,

I try in several pages:
- knowledge bases
- server states
- network problem
- downloads
- contact
- support request
- open a request

For example for knowledge base I have:
Home (index.php)> KnowledgeBase (Knowledgebase.php)

I would like to replace for all these pages the links present in the breadcrumbs because I have done rewriting for French people. 

And I would like change :
Home (index.php) to Aide (/aide/)

I hope I have been accurate
thank you in advance
cordially

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • 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