Jump to content

Client Area Menu edit internal 500 error


kacm

Recommended Posts

Hi I got this code from http://docs.whmcs.com/Editing_Client_Area_Menus and i put this into hook file. Everything works fine while I am not logged in. When I log in into customer account i got 500 internal error.

Anny issues?

 

<?php

add_hook('ClientAreaNavbars', 1, function ()
{
   // Get the current navigation bars.
   $primaryNavbar = Menu::primaryNavbar();
   $secondaryNavbar = Menu::secondaryNavbar();

   // Save the "Contact Us" link and remove it from the primary navigation bar.
   $contactUsLink = $primaryNavbar->getChild('Contact Us');
   $primaryNavbar->removeChild('Contact Us');

   // Add the email sales link to the link's drop-down menu.
   $contactUsLink->addChild('email-sales', array(
       'label' => 'Email our sales team',
       'uri' => 'sales@my-awesome-company.com',
       'order' => 1,
       'icon' => 'fa-diamond',
   ));

   // Add the call us link to the link's drop-down menu.
   $contactUsLink->addChild('call-us', array(
       'label' => 'Call us',
       'uri' => 'tel:+18005551212',
       'order' => 2,
       'icon' => 'fa-mobile',
   ));

   // Add the map to the company to the link's drop-down menu.
   $contactUsLink->addChild('map', array(
       'label' => '123 Main St. AnyTown, TX 11223, USA',
       'uri' => 'https:\/\/maps.google.com/maps/place/some-map-data',
       'order' => 3,
       'icon' => 'fa-map-marker',
   ));

   // Add the link and its drop-down children to the secondary navigation bar.
   $secondaryNavbar->addChild($contactUsLink);

   // Make sure the contact us link appears as the first item in the
   // secondary navigation bar.
   $contactUsLink->moveToFront();
});

Link to comment
Share on other sites

the incorrect assumption is that the example hook codes in the documentation work... they partially do, but not 100% :roll:

 

the important point to always remember with these navbar hooks is that you shouldn't add/remove/modify an existing element, unless you have first checked to see that it exists... if it exists, the above hook will work; if it doesn't (e.g you're logged in a client and there is no existing "Contact Us" button), the hook will fail.

 

an alternative way to do this would be to use both primary and secondary navbar hooks in the same file - firstly removing the contact us link from the primary navbar (after checking it exists); and then adding the contact us link to the secondary navbar and adding the child links beneath it.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild('Contact Us'))) {
       $primaryNavbar->removeChild('Contact Us');
   }
});

add_hook('ClientAreaSecondaryNavbar', 1, function (MenuItem $secondaryNavbar)
{
   // Add Contact Us to the secondary navbar.
   $secondaryNavbar->addChild('Contact Us');

   // Add the email sales link to the link's drop-down menu.
   $secondaryNavbar->getChild('Contact Us')
                   ->addChild('email-sales', array(
                   'label' => 'Email our sales team',
                   'uri' => 'sales@my-awesome-company.com',
                   'order' => 1,
                   'icon' => 'fa-envelope-o',
   ));

   // Add the call us link to the link's drop-down menu.
   $secondaryNavbar->getChild('Contact Us')
                   ->addChild('call-us', array(
                   'label' => 'Call us',
                   'uri' => 'tel:+18005551212',
                   'order' => 2,
                   'icon' => 'fa-mobile',
   ));

   // Add the map to the company to the link's drop-down menu.
   $secondaryNavbar->getChild('Contact Us')
                   ->addChild('map', array(
                   'label' => '123 Main St. AnyTown, TX 11223, USA',
                   'uri' => 'https:\/\/maps.google.com/maps/place/some-map-data',
                   'order' => 3,
                   'icon' => 'fa-map-marker',
   ));
});

I suppose to be strictly safe, you should check before adding each child that its parent exists, but in the above hook that shouldn't really be necessary as the hook creates the parent.

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