mantisbt:plugins_overview
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
mantisbt:plugins_overview [2008/02/08 11:15] – jreese | mantisbt:plugins_overview [2011/12/30 10:35] (current) – tandler | ||
---|---|---|---|
Line 91: | Line 91: | ||
* '' | * '' | ||
* '' | * '' | ||
+ | * '' | ||
* '' | * '' | ||
* '' | * '' | ||
Line 98: | Line 99: | ||
Overriding this function allows your plugin to set itself up, include any necessary API's, declare or hook events, etc. Alternatively, | Overriding this function allows your plugin to set itself up, include any necessary API's, declare or hook events, etc. Alternatively, | ||
+ | |||
==== Using the Event System ==== | ==== Using the Event System ==== | ||
Line 103: | Line 105: | ||
The event system is what makes Mantis plugins flexible and extensible. | The event system is what makes Mantis plugins flexible and extensible. | ||
- | === Basic Structure === | + | For more detailed information on the event system, see the [[event_system]]. |
- | To conform to the recommended event usage patterns, there should be a file in in your plugin' | + | === Hooking Events === |
- | Building from the example above, your plugin | + | There are two ways to hook events in your plugins. |
- | < | + | |
- | plugins/ | + | == hook() == |
- | | + | |
- | | + | The first way is with ' |
- | | + | |
+ | < | ||
+ | <?php | ||
+ | |||
+ | class ... { | ||
+ | | ||
+ | |||
+ | function hook() { | ||
+ | | ||
+ | // single callback per event | ||
+ | ' | ||
+ | |||
+ | // multiple callbacks per event | ||
+ | ' | ||
+ | | ||
+ | } | ||
+ | |||
+ | // Callback function | ||
+ | function test( $p_event, $p_params ) {} | ||
+ | } | ||
</ | </ | ||
- | === events.php === | + | == plugin_event_hook() |
- | This file will be included automatically by Mantis at runtime, but only when an event hooked | + | However, the simplest way for a plugin to hook a individual function to an event is by calling |
- | == plugin_event_<basename>_<function> | + | <code php> |
+ | <?php | ||
- | This is the generic format for hooked event functions. The '' | + | class ... { |
+ | ... | ||
- | === Hooking Events === | + | function hook() { |
+ | return array( | ||
+ | ' | ||
+ | ); | ||
+ | } | ||
- | The simplest way for a plugin to hook a function | + | |
+ | plugin_event_hook( | ||
+ | } | ||
+ | |||
+ | | ||
+ | } | ||
+ | </ | ||
=== Declaring Events === | === Declaring Events === | ||
Line 134: | Line 167: | ||
This function will declare a single event with a given name and type. The only types currently allowed are: | This function will declare a single event with a given name and type. The only types currently allowed are: | ||
- | * EVENT_TYPE_EXECUTE | + | * '' |
- | * EVENT_TYPE_OUTPUT | + | * '' |
- | * EVENT_TYPE_CHAIN | + | * '' |
- | * EVENT_TYPE_DEFAULT | + | * '' |
For example: | For example: | ||
- | < | + | < |
<?php | <?php | ||
event_declare( ' | event_declare( ' | ||
Line 147: | Line 180: | ||
== event_declare_many( events ) == | == event_declare_many( events ) == | ||
- | This function will declare multiple events at once, taking | + | This function will declare multiple events at once, taking |
- | < | + | < |
<?php | <?php | ||
event_declare_many( array( | event_declare_many( array( | ||
Line 349: | Line 382: | ||
This callback is executed after the normal uninstallation process, and should handle such operations as reverting database schemas, removing unnecessary data, etc. This callback should be used only if Mantis would break when this plugin is uninstalled without any other actions taken, as users may not want to lose data, or be able to re-install the plugin later. | This callback is executed after the normal uninstallation process, and should handle such operations as reverting database schemas, removing unnecessary data, etc. This callback should be used only if Mantis would break when this plugin is uninstalled without any other actions taken, as users may not want to lose data, or be able to re-install the plugin later. | ||
+ |
mantisbt/plugins_overview.1202487316.txt.gz · Last modified: 2008/10/29 04:31 (external edit)