Breadcrumbs in WHM interface

jimlongo

Well-Known Member
Mar 20, 2008
288
24
68
I've gone around in circles for a while with the documentation.

I have a PHP app starting with

Code:
<?php
require_once('/usr/local/cpanel/php/WHM.php');
WHM::header('Topline Cloud Services', 0, 0);
?>
and ending with

Code:
<?php
    WHM::footer();
?>

I would like to add the standard breadcrumbs at the top.
It seems like they would be a standard item in the header ...

If the answer is that I need a .tmpl file ... it's not clear to me where that goes and how I use it in my ui.

What do i need to do to get breadcrumbs?

Thanks.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,235
2,422
363
cPanel Access Level
Root Administrator
Hey there! I reached out to the UI team about this one, and confirmed that you can't perform any work with the breadcrumbs in PHP. However, you can do this with the Template Toolkit details here:


While I don't have the exact details for the breadcrumb system, I was provided a basic example:

Code:
WRAPPER 'master_templates/master.tmpl'
    header = locale.maketext("PostgreSQL Upgrade"),
    stylesheets = styleSheets,
    theme='bootstrap',
    breadcrumbdata= {
        previous = [
            {
                name = "Home",
                url  = "/scripts/command?PFILE=main",
            },
            {
                name = "Plugins",
                url  = "/scripts/command?PFILE=Plugins",
            },
        ],
        name = 'PostgreSQL Upgrade',
        url = '/cgi/troglodyne/pgupgrade.cgi',
        help_url = 'https://troglodyne.net/better-postgres-for-cpanel',
    },
    icon='/addon_plugins/troglophant.png';
%]
which was pulled from this git here: better-postgres4cP/pgupgrade.tmpl at master · Troglodyne-Internet-Widgets/better-postgres4cP

Let me know if that helps!
 

jimlongo

Well-Known Member
Mar 20, 2008
288
24
68
Thanks, that does help, it's where I was thinking I had to go ... but as I askekd earlier,
if I'm producing a plugin,

"what is this file called, and where does it go so that it's included when the page is rendered?"
 

cPanelThomas

Member
Feb 16, 2023
13
7
78
cPanel
cPanel Access Level
Root Administrator
Howdy, I'm Thomas A. Baugh, developer at cPanel (and the author of the example used above by Rex). While this information is correct, I thought I'd provide a little bit more information in case you do wish to implement this yourself (I have not tested the following).

Try to subclass WHM.php. The function `processHeaderStrings` is where we're doing alterations on the header cache which it normally spits out. It is likely "just" a matter of grabbing the output from `parent::processHeaderStrings` in the subclass' version of `processHeaderStrings` and run `str_replace` of your own on the output to insert breadcrumbdata HTML which "looks right" for your plugin in place of `<!-- Breadcrumbs Section -->`.

Of course, cPanel could be doing this in the parent class; we simply do not do so currently. I can't give you a reason why we don't already do this, as I did not write this part of the product. Presumably so long as the right args for breadcrumbdata is passed in we could construct this fairly straightforwardly. If a case is forthcoming for it, I'll see if I can take a stab at it.
 

jimlongo

Well-Known Member
Mar 20, 2008
288
24
68
Howdy, I'm Thomas A. Baugh, developer at cPanel (and the author of the example used above by Rex). While this information is correct, I thought I'd provide a little bit more information in case you do wish to implement this yourself (I have not tested the following).

Try to subclass WHM.php. The function `processHeaderStrings` is where we're doing alterations on the header cache which it normally spits out. It is likely "just" a matter of grabbing the output from `parent::processHeaderStrings` in the subclass' version of `processHeaderStrings` and run `str_replace` of your own on the output to insert breadcrumbdata HTML which "looks right" for your plugin in place of `<!-- Breadcrumbs Section -->`.

Of course, cPanel could be doing this in the parent class; we simply do not do so currently. I can't give you a reason why we don't already do this, as I did not write this part of the product. Presumably so long as the right args for breadcrumbdata is passed in we could construct this fairly straightforwardly. If a case is forthcoming for it, I'll see if I can take a stab at it.
Thanks for your instructions.

We got this approach to work, but not without a little difficulty, in that most of the methods in WHM.php are private (like `processHeaderStrings()`) so cannot be called from this new class. And since we cribbed the breadcrumb code from another of your plugins, I have concerns about the maintenance of that section.

I guess I feel like this should be included as part of the standard header so there is uniformity amongst plugins.

WHM::header('Plugin Name', 0, 0, 1); with one of the parameters "show/hide Breadcrumbs"
 

cPanelThomas

Member
Feb 16, 2023
13
7
78
cPanel
cPanel Access Level
Root Administrator
> I guess I feel like this should be included as part of the standard header so there is uniformity amongst plugins.

I definitely agree on that point. I filed CPANEL-42488 internally to track this so that I don't forget about this. Not sure when I'll get it merged, etc., as I'll need to beg/borrow/steal a QA & docs person to go over the changes, but hopefully I can get it into v112
 
  • Like
Reactions: cPRex and jimlongo