PHP Class
It is possible to implement a new API event (or plugin) by creating an apposite PHP file, containing a new class that inherits the methods defined by VAPApiEvent
.
The class name of a plugin/event varies according to the name used for the PHP file, which has to be concatenated to VikApiEvent
.
Therefore, if we have a file named as "foo.php", the related class name will be built as: VikApiEventFoo
. Each underscore that may be contained in the name must be removed and the subsequent letter should be capitalized. In example, "foo_bar_baz.php" will contain a class named as: VikApiEventFooBarBaz
.
Here's the shell of the class to develop, by assuming a file named as "my_api_plugin.php".
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
class VAPApiEventMyApiPlugin extends VAPApiEvent
{
/**
* The custom action that the event have to perform.
* This method should not contain any exit or die function,
* otherwise the event won't be properly terminated.
*
* @param array $args The provided arguments for the event.
* @param VAPApiResponse $response The response object for admin.
*
* @return mixed The response to output or the error message (VAPApiError).
*/
protected function doAction(array $args, VAPApiResponse $response)
{
/**
* @todo mandatory
*/
}
/**
* Returns true if the plugin is always authorised, otherwise false.
* When this value is false, the system will need to authorise the plugin
* through the ACL of the user.
*
* @return boolean
*/
public function alwaysAllowed()
{
/**
* @todo optional
*/
}
/**
* Returns the description of the plugin.
*
* @return string
*/
public function getDescription()
{
/**
* @todo optional
*/
}
}
Where should I place that file?
You should refer to the vikappointments_init_application_framework
hook to understand how to support third-party API plugins/events.