Plugins can do just about anything. Create custom cron jobstasks, listen for events, create pages, create widgets, extend the API, etc., etc. If it's not a Module or a Payment Gateway, it's a plugin. So let's dig in.
...
Info | ||
---|---|---|
| ||
Data validation is an important part of logic, and user friendly application design. Be sure to check out the Error Checking section of this manual for a full explanation on error handling. |
...
Info | ||
---|---|---|
| ||
Use the Language library to help internationalize your plugin. Just create a language directory in your plugin, then a directory for each language (i.e. /plugins/my_plugin/language/en_us/) and place your language files in there. See Translating Blesta for how to load, format, and use language definitions. |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php
class MyPluginPlugin extends Plugin {
...
public function getLogo() {
return "views" . DS . "default" . DS . "images" . DS . "some_other_logo.png";
}
}
?> |
Managing a Plugin
If your plugin requires certain configurable options, you can create a management link viewable to staff members that have access to installed plugins. To do so, all you need to do is create an AdminManagePlugin controller. This is a special controller that is initialized by Blesta internally, so all views must be returned (as strings) from the requested action methods.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php class AdminManagePlugin extends AppController { public function index() { $var1 = "hello"; $var2 = "world"; return $this->partial("admin_manage_plugin", compact("var1", "var2")); } public function foo() { return $this->partial("admin_manage_plugin_foo"); } } ?> |
By default the index() method is called. You can link to other controller and actions from your views using the following URL format:
Code Block | ||||
---|---|---|---|---|
| ||||
<a href="<?php echo $this->Html->safe($this->base_uri . "settings/company/plugins/manage/" . $this->Html->_($plugin_id, true) . "/?controller=admin_manage_plugin&action=foo");?>">Link to other action</a> |
The above link would render the AdminManagePlugin::foo() method.
Interactive Plugins
So far all we've see is how to build a plugin that can be installed, uninstalled, upgraded, and managed, but that's the just tip of the iceberg. As we discussed earlier, plugins can do so much more.
Actions
By register actions, a plugin makes itself available in the interface in certain areas. See Plugin Actions for how to register actions.
Events
Some plugins need to be executed when certain events occur outside of the plugin's control. This is accomplished by registering events. See Plugin Events for how to register events.
Cron Jobs
Plugins that need to perform certain tasks automatically at either set intervals are certain times of the day can register cron tasks. See Plugin Cron Tasks for how to register cron tasks.