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.

image

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:

image

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).

image

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

image

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:

image

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:

image

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.

image

Just return the data you want displayed.

image

Additional Tips

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

image

See our complete documentation for more information.

As you can see, it’s quite simple to write custom widgets for Help Desk. Get started and let us know if you have any questions, or notice any areas that could be improved!

A trial is worth a thousand words.
Get started today, no credit card required.