Creating a new custom dashboard widget in PHP

Hi

I’d like to add my own custom dashboard widget in FreePBX. I can code PHP.

Can anybody point me to some resources for this? Is there, perhaps, even a working example that any of you can share?

I did try Googling and Grokking, but all my attempts have failed…

Thanks

look in /var/www/html/admin to find all the PHP, and just have a dig around :slight_smile: It’s all fairly well written and not hard to follow.

Thanks for the quick answer… but it’s not that simple. Seeing how the default stuff is done is not the same thing as installing a custom module in a way that can be distributed, etc.

With Grok instructions, I was able to create a custom module, get it loaded, but it would not show at all. That’s why this time I would like to try starting with something custom that somebody else did, even if very simple, as long as it is working. And then do my changes from there.

Nothing? No example of a custom widget?

I can find stuff online about creating and registering a module, but they all seem to be using UIs based on adding a menu option.

If somebody can point me to the slightest documentation on hooking into the dashboard, I would really appreciate it…

“It’s all fairly well written and not hard to follow.” lol, lmao, etc.

There is no ability to “hook in” to the dashboard unfortunately. You could try writing your own code and dumping it into /var/www/html/admin/modules/dashboard/sections. I wrote that little “notepad” panel a few years back and it was fairly straightforward. A very simple class that just pulls in a view and loads its info from the kv store. dashboard/sections/Notepad.class.php at release/17.0 · FreePBX/dashboard · GitHub

1 Like

Thanks @miken32 ! I’m actually a fan of your Notepad widget!

Maybe I’ll start by cloning that widget and changing it. Maybe this weekend I’ll give it a try.

Do you know if there’s any “registry” for these dashboard widgets? Or is it enough to create new content in modules/dashboard/sections and it will get picked up?

Looks like it just scans the directory: dashboard/classes/DashboardHooks.class.php at release/17.0 · FreePBX/dashboard · GitHub

1 Like

Ok, so I’ve cloned the notepad dashboard widget, I edited the files to change all strings containing ‘Notepad’ to ‘PgrDashlet’, and now… I have an empty area:

I click on it, nothing happens.

So, it’s getting recognized, but something is still broken and I need to fix it. The problem is that I’ve spent a long time looking for any messages in any logs and I don’t see anything. I would expect a PHP error, do you know where these are logged to in FreePBX? Or do I need to activate the logs somewhere? Thanks for your help

They do their best to hide all the error messages, likely because there are so many warnings in their codebase lol. There are some Advanced Settings that can help. Depending on your setup they may end up in the web server log, PHP log, PHP FPM log, or FreePBX log.

Thanks - turning on debug log in Advanced Settings was enough to get me going. I got a message saying “failed to load the view” and it was enough to spot some case-sensitivity issues in the file names.

Now I have a working dashlet, yay :rocket:

I am just starting, but my goal here is to provide an up-front list of links to menu options, with a paragraph for each to document it. This is to guide half-technical users (the guy at the company that is allowed to change settings in the UI) to the relevant menu options and what he can configure in each, instead of getting lost in over-crowded menus.

Thanks for getting me unstuck :tada:

I’ve been playing with some bits of graphics (font awesome icons), buttons, tables, etc.

I’ve also added some dynamic information - which IP’s are currently banned.

There’s a lot of nice stuff that can be done here with great ease :flexed_biceps:

1 Like

It looks nice!

To the :waxing_crescent_moon:

You might consider the userman module as well for this purpose:

1 Like

Thanks @penguinpbx I didn’t know about that (never noticed the options there to configure access to modules etc), and it does look useful! I will keep developing my dashboard widget, but I will surely also explore those options. :+1: