Most plugins need to be displayed somewhere in the interface. Either through a link somewhere in the navigation, or as a widget on a certain page. This is accomplished by having the plugin register actions.
Registering Actions
Actions allow plugins to make themselves available throughout Blesta. In some areas Blesta will simply render a link to the provided URI. In other area Blesta will attempt to render a widget. Let's look at an example.
Code Block |
---|
language | php |
---|
title | /plugins/my_plugin/my_plugin_plugin.php |
---|
linenumbers | true |
---|
|
<?php
class MyPluginPlugin extends Plugin {
...
public function getActions() {
return array(
array(
'action' => "nav_primary_client", // The action to tie into
'uri' => "plugin/my_plugin/client_main/index/", // The URI to fetch when the action is needed
'name' => "Foo Bar", // The name used by Blesta to display for the action (e.g. The name of the link),
'options' => null // Options required for this action if any (e.g. array('key' => "value"))
)
);
}
}
?> |
The above example would register the link "Foo Bar" in the client interface's primary navigation. The link would point to /plugin/my_plugin/client_main/index/. The URI resolves to the ClientMain controller and index method. Here's what that might look like:
Code Block |
---|
language | php |
---|
title | /plugins/my_plugin/controllers/client_main.php |
---|
linenumbers | true |
---|
|
<?php
class ClientMain extends MyPluginController
public function index() {
// Set some variables to the view
$this->set("var1", "value1");
// Set variables all at once
$var2 = "hello";
$var3 = "world";
$this->set(compact("var2", "var3"));
// Automatically renders the view in /plugins/my_plugin/views/default/client_main.pdt
}
}
?> |
Note |
---|
|
All Client controllers must start with client_ in their file name. The same is true for admins as well. All Admin controllers must start with admin_ in their file name. This tells Blesta which portal to render. Generic controllers (those not associated with a particular portal don't need any prefix. |
Info |
---|
title | Registering an action is not necessary |
---|
|
All plugins are accessible via their URI directly (i.e. http://mydomain/installpath/plugin/my_plugin/controller/action/). So you don't have to register an action to make your plugin accessible. |
Available Actions
Below is a list of all actions available.
Action | Type | Description | Options |
---|
nav_primary_client | Link | Renders a link in the primary nav of the client interface | - sub - A numerical array of sub nav elements, each containing an array of:
- uri - The URI to link to
- name - The name of the link
- icon - The icon to display (optional)
- secondary - A numerical array of secondary nav elements, each containing an array of:
- uri - The URI to link to
- name - The name of the link
- icon - The icon to display (optional)
|
nav_primary_staff | Link | Renders a link in the primary nav of the admin interface | - sub - A numerical array of sub nav elements, each containing an array of:
- uri - The URI to link to
- name - The name of the link
|
nav_secondary_staff | Link | Renders a link in the secondary nav of the admin interface under the given parent | - parent - The portion of the URI that identifies the primary nav element to place this under (e.g. "packages/" = Packages tab)
|
widget_client_home | Widget | Renders a widget on the client home page | N/A |
widget_staff_home | Widget | Renders a widget on the staff home page | N/A |
widget_staff_client | Widget | Renders a widget on the staff client profile page | N/A |
widget_staff_billing | Widget | Renders a widget on the staff billing page | N/A |
action_staff_client | Link | Renders a link in the "Account Actions" section of the staff client profile page | - class - The CSS class name to use to style the link
|