yggdrasil Posted April 1, 2021 Share Posted April 1, 2021 If you check the examples code from WHMCS, example here: sample-provisioning-module/hooks.php at master · WHMCS/sample-provisioning-module · GitHub Aren't those example incomplete? Example: * Render a custom sidebar panel in the secondary sidebar. That seems a bit useless in a real world setup because your custom menu will always show, even if the product is cancelled, pending, or terminated. I have actually searched and while there are plenty of examples here posted by Brian how to add hooks to sidebars, I could not find a complete one that actually will only show this when the product is active. Example, just like you get the Login to cPanel and similar menus on a cPanel hosting product, those options will not show once the product is terminate or cancelled. If memory serves me right it should be completed with the Menu::context("service"); And since you get the ID for the product on the GET request, just check if its active or not. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 1, 2021 Share Posted April 1, 2021 2 hours ago, yggdrasil said: I have actually searched and while there are plenty of examples here posted by Brian how to add hooks to sidebars, I could not find a complete one that actually will only show this when the product is active. tempted to post this, but it's not what directly you're looking for.... ... though it is modifying a sidebar's content based on a ticket class... the principle would work on product details too if it had to determine to do something (add/edit/remove a sidebar/child) based on the service's status (but there are other ways). 2 hours ago, yggdrasil said: Example, just like you get the Login to cPanel and similar menus on a cPanel hosting product, those options will not show once the product is terminate or cancelled. for a terminated/cancelled product, those links would be shown, but disabled - do you want to change that and not show them at all under those circumstances ? <?php # Remove Disabled Children From Sidebar Hook # Written by brian! use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar) { $SDA = $primarySidebar->getChild("Service Details Actions"); if (!is_null($SDA)) { $SDAChildren = $SDA->getChildren(); foreach($SDAChildren as $key => $child) { $disabled = $SDA->getChild($key)->isDisabled(); if ($disabled) { $SDA->removeChild($key); } } } }); => if WHMCS wasn't disabling these links, then you could do that manually with a hook, or remove them individually or collectively if you had to... i'm just taking a shortcut based on WHMCS already disabling the links. 1 Quote Link to comment Share on other sites More sharing options...
yggdrasil Posted April 2, 2021 Author Share Posted April 2, 2021 10 hours ago, brian! said: tempted to post this, but it's not what directly you're looking for.... ... though it is modifying a sidebar's content based on a ticket class... the principle would work on product details too if it had to determine to do something (add/edit/remove a sidebar/child) based on the service's status (but there are other ways). for a terminated/cancelled product, those links would be shown, but disabled - do you want to change that and not show them at all under those circumstances ? <?php # Remove Disabled Children From Sidebar Hook # Written by brian! use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar) { $SDA = $primarySidebar->getChild("Service Details Actions"); if (!is_null($SDA)) { $SDAChildren = $SDA->getChildren(); foreach($SDAChildren as $key => $child) { $disabled = $SDA->getChild($key)->isDisabled(); if ($disabled) { $SDA->removeChild($key); } } } }); => if WHMCS wasn't disabling these links, then you could do that manually with a hook, or remove them individually or collectively if you had to... i'm just taking a shortcut based on WHMCS already disabling the links. The logic tells me most people probably want to have consistency in the menu and have them like your screenshot. In your screenshot all links are disabled by WHMCS which means Manage which is your custom link here should also be disabled. Now, I understand maybe some people might want a persistent link in that menu, but most probably don't and want to follow the same state as the other links. Example: You add a link to that product or a domain that is related to that product or service. That feature only works if the domain or hosting account is active, otherwise it should be disabled. The WHMCS examples just hardcodes the link into the menu without taking the product state into account. The easiest state is just to detect if its active and only show it under that state. To reply to your question, disabling is fine since that is what WHMCS does for products and domains that are not active and that would make it consistency in terms of user interface and looks. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 2, 2021 Share Posted April 2, 2021 7 hours ago, yggdrasil said: In your screenshot all links are disabled by WHMCS which means Manage which is your custom link here should also be disabled. it's not a custom link, it's a default link that WHMCS isn't disabling - it's a cPanel product... and the Manage SSO link doesn't work anyway... possibly you could argue that it's a bug it isn't disabled, but if I needed to disable it with a hook, it would be simple to do. 7 hours ago, yggdrasil said: You add a link to that product or a domain that is related to that product or service. That feature only works if the domain or hosting account is active, otherwise it should be disabled. The WHMCS examples just hardcodes the link into the menu without taking the product state into account. The easiest state is just to detect if its active and only show it under that state. the examples given in the help docs are just how to do the basics - I tend to disregard them anyway as I still recall the examples first posted when Six was released were buggy and used to crash WHMCS... the class docs can be a useful resource - though there are errors and missing details in there to make life exciting. 🙄 a conditional sidebar hook based on a service's status is simple to do.... <?php # Status Conditional Sidebar Hook # Written by brian! use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar) { $service = Menu::context('service'); $status = $service->status; if ($status == "Active" && !is_null($primarySidebar->getChild('Service Details Actions'))) { $primarySidebar->getChild('Service Details Actions')->addChild('Service Status')->setLabel($status)->setOrder(100); } }); to save time, i'm just adding a child to an existing sidebar if the current service status is Active - if it's not, the hook does nothing... if the status were cancelled/terminated, then it could return a disabled link.... and it could be tweaked to create a new sidebar if necessary and use that instead. 0 Quote Link to comment Share on other sites More sharing options...
yggdrasil Posted April 2, 2021 Author Share Posted April 2, 2021 44 minutes ago, brian! said: it's not a custom link, it's a default link that WHMCS isn't disabling - it's a cPanel product... and the Manage SSO link doesn't work anyway... possibly you could argue that it's a bug it isn't disabled, but if I needed to disable it with a hook, it would be simple to do. the examples given in the help docs are just how to do the basics - I tend to disregard them anyway as I still recall the examples first posted when Six was released were buggy and used to crash WHMCS... the class docs can be a useful resource - though there are errors and missing details in there to make life exciting. 🙄 a conditional sidebar hook based on a service's status is simple to do.... <?php # Status Conditional Sidebar Hook # Written by brian! use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar) { $service = Menu::context('service'); $status = $service->status; if ($status == "Active" && !is_null($primarySidebar->getChild('Service Details Actions'))) { $primarySidebar->getChild('Service Details Actions')->addChild('Service Status')->setLabel($status)->setOrder(100); } }); to save time, i'm just adding a child to an existing sidebar if the current service status is Active - if it's not, the hook does nothing... if the status were cancelled/terminated, then it could return a disabled link.... and it could be tweaked to create a new sidebar if necessary and use that instead. Your first example actually works great, but I guess the second one is better as it allows more granular control based on the status (assuming someone wants different code that depends on the status) over just checking the disabled child item. What do you mean the SSO link does not work? I'm not using it but just curious. The cPanel links do work on my installation. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 2, 2021 Share Posted April 2, 2021 11 minutes ago, yggdrasil said: What do you mean the SSO link does not work? I'm not using it but just curious. The cPanel links do work on my installation. the issue is related to SiteLock - not overly bothered about fixing it as the account doesn't actually use SiteLock in reality (it's only a setting in the dev) - the cPanel links all work fine. 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.