Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Plugins are "plug-and-play" applications that extend the functionality of Blesta. This section document explains how to design and develop plugins, and highlights the roles plugins may assume when rendering data.

Getting Started with Plugins

Plugins follow the same MVC design pattern that Blesta adheres to. The plugin system in Blesta is provided as a feature of the minPHP. Blesta simply defines the naming convention. For the purpose of this manual, the plugin name we'll refer to is my_plugin. Your plugin name will, of course, differ.

File Structure

Plugins are fully contained within their named plugin directory and placed in the /plugins/ directory. Below is the minimum required file structure for a plugin:

  • /plugins/
    • my_plugin/
      • controllers/
      • models/
      • views/
      • language/
      • my_plugin_controller.php
      • my_plugin_model.php
      • my_plugin_plugin.php

my_plugin_controller.php is the plugin's parent controller. This controller can be used to add supporting methods for the other controllers to inherit. Similarly, my_plugin_model.php is the plugin's parent model and can be used to add supporting methods for the other models to inherit.

Because plugins inherit from the application stack their views default to the view directory defined for application. For this reason, you should always declare the view directory for the views within your plugin. The example below requires that you place all views (.pdt files) into /plugins/my_plugin/views/default/.

Code Block
languagephp
title/plugins/my_plugin/my_plugin_controller.php
firstline1
linenumberstrue
<?php
class MyPluginController extends AppController {
    public function preAction() {
        parent::preAction();
 
        // Override default view directory
        $this->view->view = "default";
        $this->structure->view = "default";
    }
}
?>

Finally, my_plugin_plugin.php is a special class that must extend the Plugin class of /components/plugins/lib/plugin.php. This class is used for installing, upgrading, uninstalling, and branding the plugin.

  • The Creating a Plugin section explains the basic requirements and structure for any plugin.
  • The Plugin Actions shows how to have your plugin register actions, which is primarily how plugins are displayed in the interface.
  • The Plugin Cards shows informational cards on the client profile.
  • The Widgets section explains how to have your render widgets, which goes hand in hand with Plugin Actions.
  • The Service Management Tabs section describes how to setup your plugin to render tabs when managing a service.
  • The Plugin Cron Tasks sections shows how to create custom cron tasks which can execute at set intervals or specific times.
  • The Plugin Events section describes how to trigger a plugin to execute during special events.
  • The Extending the API section explains how to use plugins to add additional functionality to the Blesta API.
  • The ACL section describes how to integrate a plugin into Blesta's Access Control List.
  • The Email section explains how to manage and send email through a plugin.
  • The Database Access section explains how to build and execute queries on the database.

...