mustardman Posted October 22, 2015 Share Posted October 22, 2015 (edited) I am trying to add a hook that inserts font awesome icons for the primary navbar on six template for whmcs v6.1. So far I only have 1 line working. <?php use WHMCS\View\Menu\Item; add_hook('ClientAreaPrimaryNavbar', 1, function (Item $primaryNavbar){ $primaryNavbar->getChild('Home')->setExtras(['myIcon' => 'fa fa-home fa-fw']); }); The above code works. What I want to do is add icons for all the other primaryNavbar items in addition to 'Home'. So 'Services, 'Billing', 'Support', etc. If I just keep adding lines as follows: $primaryNavbar->getChild('Service')->setExtras(['myIcon' => 'fa fa-bars fa-fw']); $primaryNavbar->getChild('Billing')->setExtras(['myIcon' => 'fa fa-usd fa-fw']); }); I end up getting a blank screen with server error code on the html page. So WHMCS is not happy about what I am doing. What am I doing wrong? Are there any meaningful errors logged anywhere? Apache logs don't show anything. Edited October 22, 2015 by mustardman 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 22, 2015 Share Posted October 22, 2015 I end up getting a blank screen with server error code on the html page. So WHMCS is not happy about what I am doing. What am I doing wrong? you have to love WHMCS using a new navigation system, but then releasing documentation that is so thin on detail, it's close to being useless. however, the solution finally clicked into place... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function(MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Home'))) { $primaryNavbar->getChild('Home') ->setIcon('fa-home'); } if (!is_null($primaryNavbar->getChild('Services'))) { $primaryNavbar->getChild('Services') ->setIcon('fa-bars'); } if (!is_null($primaryNavbar->getChild('Domains'))) { $primaryNavbar->getChild('Domains') ->setIcon('fa-globe'); } if (!is_null($primaryNavbar->getChild('Billing'))) { $primaryNavbar->getChild('Billing') ->setIcon('fa-usd'); } if (!is_null($primaryNavbar->getChild('Support'))) { $primaryNavbar->getChild('Support') ->setIcon('fa-support'); } }); the thing to always remember is that if you are modifying or removing an existing child, you *must* first check that it exists and then only if it does, can you modify it - if you try to modify something that doesn't exist, that's when you run into issues. btw - your code didn't work for me at all. 1 Quote Link to comment Share on other sites More sharing options...
mustardman Posted October 22, 2015 Author Share Posted October 22, 2015 (edited) Works great. Thanks a lot. I believe the problem was that I was not doing the check for existing child. Turns out 'Account' is on SecondaryNav so it didn't exist when trying to do it on PrimaryNav. I was using setExtras() because that is what WHMCS support told me to do. I couldn't even find any documentation on the existence of setExtras() as well as getExtra(). I was aware of setIcon() but for some reason I thought it would be better to create my own separate entry. Thinking about it now that seems kind of pointless. Another tricky thing about this is that setIcon() appears to be adding in the "fa". So if I setIcon('fa fa-user fa-fw') it would fail with a blank screen again. This is my first time working with hooks and so far I am not too crazy about how tricky this is to avoid killing the whole site at the slightest little syntax problem with no error logging anywhere to tell you what is going on. Also yea, WHMCS documentation is quite thin on this even though it is the way they want people to do their customizations. Edited October 22, 2015 by mustardman 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 23, 2015 Share Posted October 23, 2015 I was using setExtras() because that is what WHMCS support told me to do. I couldn't even find any documentation on the existence of setExtras() as well as getExtra(). that did throw me a little when I saw your code! it is a valid command, but as you say it's not documented and using setIcon sounded more logical to me... the trick was trying to figure out how to specify the icon. i've privately heard numerous times of Support providing bad information when it comes to these navbar hooks - for the basic stuff, they're probably up to the task; anything a little more advanced and they're often wrong... frankly, i'd always suggest coming to the forum for these navigation hooks - chances are that either sentq or myself will have posted similar hooks... and they'll be far more likely to work that any in the documentation or from Support! I was aware of setIcon() but for some reason I thought it would be better to create my own separate entry. Thinking about it now that seems kind of pointless. the alternatives you try always seem pointless until you finally see how it's done... we've all been there with these hooks! This is my first time working with hooks and so far I am not too crazy about how tricky this is to avoid killing the whole site at the slightest little syntax problem with no error logging anywhere to tell you what is going on. the easiest way to see any error is to enable "Display Errors" in setup -> general settings -> other, that should at least give you some sort of clue as to where to look in the code... though don't forget to disable it again when you've finished. Also yea, WHMCS documentation is quite thin on this even though it is the way they want people to do their customizations. that's what I found surprising when the launched v6 - either make the documentation so thorough that even the most basic users could follow it, or design a menu manager in the admin area to control the menus... it's hardly rocket science to realise that! there's a third-party addon that can do that, so it shouldn't have been beyond the wits of the WHMCS developers to do it themselves. 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.