Jump to content

Problem Creating child under new NavBar in Six Theme


Recommended Posts

Hello:

I am using the code below to create a new Primary NavBar with 3 child links beneath it. However, only the main NavBar and one of the child links (the one labeled "custom_clouddetails_3") appear -- it seems like the 2 child links in the middle are hidden. Can you pls check my syntax below and tell me where I made a mistake?

 

Thank you so much~

 

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $primaryNavbar->addChild(Lang::trans('custom_clouddetails'))
       ->setUri('http://www.mydomain.com/custom-clouddetails.php')
       ->setOrder(70);
});


add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild(Lang::trans('custom_clouddetails')))) {
       $primaryNavbar->getChild(Lang::trans('custom_clouddetails'))
           ->addChild(Lang::trans('custom_clouddetails_1'), array(
               'label' => Lang::trans('custom_clouddetails_1'),
               'uri' => 'cloud_1.php',
               'order' => '10',
           ));
   }
});

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild(Lang::trans('custom_clouddetails')))) {
       $primaryNavbar->getChild(Lang::trans('custom_clouddetails'))
           ->addChild(Lang::trans('custom_clouddetails_2'), array(
               'label' => Lang::trans('custom_clouddetails_2'),
               'uri' => 'custom_clouddetails_2.php',
               'order' => '20',
           ));

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild(Lang::trans('custom_clouddetails')))) {
       $primaryNavbar->getChild(Lang::trans('custom_clouddetails'))
           ->addChild(Lang::trans('custom_clouddetails_3'), array(
               'label' => Lang::trans('custom_clouddetails_3'),
               'uri' => 'custom_clouddetails_3.php',
               'order' => '30',
           ));

 

- - - Updated - - -

 

Sorry, I solved it. I put them all together and then it works

Edited by paperweight
added some more info
Link to comment
Share on other sites

Sorry, I solved it. I put them all together and then it works

i'm glad you solved it! :)

 

when I saw your code I initially had two thoughts...

 

1. why are they 4 separate hooks! :?:

2. why are you using language translations in the names (get and add) of the children (or parent)?

 

addChild(Lang::trans('custom_clouddetails'))

I suppose it would work, but child names are for internal use only - yes, they'd be used externally as a label if you weren't defining one, but you are... so seems like an unnecessary complication to me.

 

it's possible that if the client was using a language where these translations did not exist, the hooks could cause an error - personally, i'd just give them defined names in English (or any other language) so they would be easier to reference... :idea:

 

getChild('Cloud Details'))

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