Jump to content

Module Client Area Sidebar


dorzki

Recommended Posts

  • 1 month later...

Hi,

i had the same question and also didn't find an accurate answer to my question. So, I did some hacking and have managed to find a solution:

function addClientAreaSidebarForCustomAddonModule($vars)
{
    $client = Menu::context('client');
    if(!empty($client)){
        if(isset($vars['modulelink'])){
            if(strpos($vars['modulelink'],'m=customAddonModule')){
                $primarySidebar = Menu::primarySidebar();
                $newMenu = $primarySidebar->addChild(
                    'CustomAddonModule ClientArea Sidebar',
                    array(
                        'name' => 'My CustomAddonModule ClientArea Sidebar',
                        'label' => 'My CustomAddonModule ClientArea Sidebar',
                        'uri' => 'index.php?m=customAddonModule',
                        'order' => 100,
                        'icon' => 'fas fa-magic',
                    )
                );
                if(!is_null($primarySidebar->getChild('My CustomAddonModule ClientArea Sidebar'))){
                    $primarySidebar->getChild('My CustomAddonModule ClientArea Sidebar')
                        ->addChild('Sidebar MenuItem 1')
                        ->setLabel('Sidebar MenuItem 1')
                        ->setUri('index.php?m=customAddonModule')
                        ->setOrder(10);
                    $primarySidebar->getChild('My CustomAddonModule ClientArea Sidebar')
                        ->addChild('Sidebar MenuItem 2')
                        ->setLabel('Sidebar MenuItem 2')
                        ->setUri('index.php?m=customAddonModule&p=manage_2')
                        ->setOrder(10);
                }
                $newMenu->moveToFront();
            }
        }
    }
}

add_hook('ClientAreaPage', 1, 'addClientAreaSidebarForCustomAddonModule');

references:

https://docs.whmcs.com/Working_With_Client_Area_Home_Page_Panels#Add_a_local_temperature_panel_to_the_homepage

https://developers.whmcs.com/hooks-reference/client-area-interface/#clientareapage

 

Link to comment
Share on other sites

  • 1 year later...

The sidebars are directly available in the ClientAreaPrimaryarySidebar and  ClientAreaSecondarySidebar hooks.
To add a sidebar to your addon module, either add the hooks in hooks.php in your module root, or add a php file in the whmcs/includes/hooks directory and deal with your menus there (I prefer this approach - keeping menu organisation and configuration separate from the module).

<?php
use WHMCS\View\Menu\Item as MenuItem;

if (!defined("WHMCS")) {
    die("This file cannot be accessed directly");
}

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar){   
   
	$module = $_GET['m'];	
	switch ($module) {
		case 'customAddonModule':
		
			//Add new group to empty sidebar
			$panel = $secondarySidebar->addChild(
				'Quick Links',
				[
					'label' => 'Quick Links',
					'order' => 1,
					'icon' => 'fas fa-shopping-cart',
				]
			);		
						
			// Add individual links to group	   
			$panel->addChild('customAddonModule')
				->setLabel('This Module')
				->setIcon('fas fa-ticket')
				->setUri('/index.php?m=customAddonModule')				
				->setClass('active')
				->setOrder(1);	

			$panel->addChild('things')
				->setLabel('Buy Things')
				->setIcon('fas fa-rabbit-in-headlights')
				->setUri('/cart.php?gid=1')
				->setOrder(2);	
				
			$panel->addChild('stuff')
				->setLabel('Configure Stuff')
				->setIcon('fas fa-drunk-man-looking-for-keys')
				->setUri('index.php?m=anotherModule')
				->setOrder(3);
			break;
			
		case 'anotherModule' :
			//add another menu for another module
	}	
});

 

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