How To Create A Widget In Help Desk

With the introduction of widgets in Help Desk, we intend to promote the simplicity of integrating widgets within your own help desk. We also want to illustrate how simple it is to create new widgets.

If you’re a developer interested in creating custom widgets for your own installation of Help Desk, feel free to read through our introductory guide as a starting point.

In this post I’ll highlight some key aspects of creating a widget, while demonstrating how to create an example widget for displaying user information for the user currently logged in.

Here are some key facts about widgets:

A widget is a folder uploaded to your web server that contains a PHP file, which designates how the widget operates.

You can create as many PHP files (within the folder) as you need to organize your widget application code.

Your widget configuration settings are automatically saved to the local database, but if you need additional database tables, you are able to add as many as you need (just make sure a same-named database table does not already exist).

The basic structure of a widget configuration file is depicted below:

Notice the name of the class is AC_Widget_userinfo – we use our custom widget name here, which should match both the folder and PHP filename (put your widget folder in the public /widgets/ directory of your Help Desk installation).

The form() function is used to display a portion of the HTML configuration form in the admin section after enabling a widget:

Put the actual HTML within the form() function – above provides an example of the “Username” HTML, but include all form fields in there as well.

Our custom widget will display some of the users’ information – we’ll keep it simple for now and just allow these three:

Username

Full Name

Default Editor

When the configuration settings are saved, the save() function is called:

Here we obtain the values from $_POST variables (along with a global variable that holds the current user ID) and prepare the $options array, which is saved to the hd_widget database table as a serialized value in the config field:

Include as many configuration options as you need.

All that’s left is to display the actual widget for users logged in!

The show() function renders the actual widget itself.

Just return the data you want displayed.

Additional Tips

If you need to create new database tables to organize your widget data, feel free to utilize the install() and uninstall() functions: