Jump to content

What's wrong with this code?


DCTHost

Recommended Posts

Hi all,

 

 

I'm trying to make a dropdown menu on my Navbar called "Legal" which displays "Privacy Policy" and "ToS". Currently, this is only displaying the "Legal" dropdown menu and then only the "Privacy Policy".

 

<?php
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $primaryNavbar->addChild('Legal')
       ->setOrder(70);
});

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild('Legal'))) {
       $primaryNavbar->getChild('Legal')
           ->addChild('Emergency Contacts', array(
               'label' => 'ToS',
               'uri' => 'http://dct.host/index.php?m=TermsOfService',
               'order' => '100',
           ));
   }
});
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild('Legal'))) {
       $primaryNavbar->getChild('Legal')
           ->addChild('Emergency Contacts', array(
               'label' => 'Privacy Policy',
               'uri' => 'http://dct.host/index.php?m=PrivacyPolicy',
               'order' => '100',
           ));
   }
});

 

Any ideas?

 

- - - Updated - - -

 

PLEASE NOTE

 

I fixed this as soon as I had posted it! ;) Have requested for the topic to be removed.

Link to comment
Share on other sites

assuming the thread doesn't get deleted, for others reading it, there are a few things wrong with the above hook...

 

1. if the hook is creating the children, you don't need to check that they exist - they will, because you're creating them! :)

2, children can't have the same name - so you can't have two children called 'Emergency Contacts'.

3. having two children with the same order value is pointless - they'd be shown in alphabetical order.

4. if you name the child what you want it's label to be, you don't need to set a separate label in the hook.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $primaryNavbar->addChild('Legal')
                   ->setOrder(70);
   $primaryNavbar->getChild('Legal')
                   ->addChild('ToS', array(
                   'uri' => 'index.php?m=TermsOfService',
                   'order' => '10',
                   ));
   $primaryNavbar->getChild('Legal')
                   ->addChild('Privacy Policy', array(
                   'uri' => 'index.php?m=PrivacyPolicy',
                   'order' => '20',
                   ));
});

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