devel:action_plugins
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devel:action_plugins [2013-01-26 03:56] – [Examples] Klap-in | devel:action_plugins [2023-09-01 23:52] (current) – Klap-in | ||
---|---|---|---|
Line 6: | Line 6: | ||
===== Working principle ===== | ===== Working principle ===== | ||
- | Action plugins are loaded before any significant DokuWiki processing takes place. Immediately after loading, each plugin is called by its '' | + | Action plugins are loaded before any significant DokuWiki processing takes place. Immediately after loading, each plugin is called by its '' |
+ | |||
+ | For more details of how the events system works and lists of events refer to the [[devel: | ||
===== Synopsis ===== | ===== Synopsis ===== | ||
Line 12: | Line 14: | ||
An Action Plugin //Example// needs: | An Action Plugin //Example// needs: | ||
* class name '' | * class name '' | ||
- | * which extends [[xref>DokuWiki_Action_Plugin]]((defined in '' | + | * which extends [[xref>ActionPlugin]]((defined in '' |
* to be stored in a file '' | * to be stored in a file '' | ||
Moreover, a [[plugin_info|plugin.info.txt]] file is needed. For full details of plugins and their files and how to create more action components refer to [[plugin file structure]]. | Moreover, a [[plugin_info|plugin.info.txt]] file is needed. For full details of plugins and their files and how to create more action components refer to [[plugin file structure]]. | ||
Line 18: | Line 20: | ||
* The plugin must declare one method '' | * The plugin must declare one method '' | ||
* External libs must be loaded at the time the plugin needs them or in the constructor and not at the top of the file | * External libs must be loaded at the time the plugin needs them or in the constructor and not at the top of the file | ||
+ | |||
==== Required methods ==== | ==== Required methods ==== | ||
An action plugin requires at least two methods: | An action plugin requires at least two methods: | ||
- | * **'' | + | * **'' |
- | * **''< | + | * **''< |
You can register multiple events in a single action plugin. When doing this you may need multiple ''< | You can register multiple events in a single action plugin. When doing this you may need multiple ''< | ||
Line 30: | Line 33: | ||
===== register() method===== | ===== register() method===== | ||
- | The '' | + | The '' |
<code php> | <code php> | ||
- | | + | /** |
- | | + | * plugin should use this method to register its handlers with the DokuWiki' |
- | | + | |
- | | + | * |
- | * | + | * @param |
- | * @return not required | + | |
- | | + | * @return |
- | function register(Doku_Event_Handler &$controller) { | + | */ |
- | $controller-> | + | public |
- | } | + | $controller-> |
+ | <event handler function>, | ||
+ | <parameter | ||
+ | < | ||
+ | } | ||
</ | </ | ||
Line 49: | Line 56: | ||
- '' | - '' | ||
- ''< | - ''< | ||
- | - ''< | + | - ''< |
- | ===== <event handler> | + | - '' |
- | Have as many as necessary, can be given any name not already in use in this plugin or its ancestor classes. This function must be public. It will be called by DokuWikis event controller. | + | | -3999 - -3000 | for "very early" | |
+ | | -2999 - -2000 | for " | ||
+ | | -1999 - -1000 | for " | ||
+ | | -999 - -1 | for " | ||
+ | | 0 | default | | ||
+ | | 1 - 999 | for "later than default" | ||
+ | | 1000 - 1999 | for " | ||
+ | | 2000 - 2999 | for " | ||
+ | | 3000 - 3999 | for "very late" | | ||
- | The passed arguments are: | + | ===== <event handler> |
- | - '' | + | |
- | - '' | + | Have as many as necessary, |
<code php> | <code php> | ||
- | | + | /** |
- | | + | * custom event handler |
- | | + | * |
- | | + | * @param |
- | | + | * @param mixed $param |
- | | + | |
- | | + | * |
- | | + | * @return |
- | | + | */ |
- | public function < | + | public function < |
- | // custom script statements ... | + | |
- | } | + | } |
</ | </ | ||
+ | The passed arguments are: | ||
+ | - '' | ||
+ | - '' | ||
===== Further reading ===== | ===== Further reading ===== | ||
Line 80: | Line 98: | ||
* [[plugintype> | * [[plugintype> | ||
* [[Plugin programming tips]] | * [[Plugin programming tips]] | ||
+ | * [[plugins|Plugin Development]] | ||
Line 85: | Line 104: | ||
Here some examples: | Here some examples: | ||
- | * Below: [[# | + | * Below: [[#Sample: Add always a JavaScript file |Sample Action Plugin]] -- include javascript file in all pages |
- | * Below: [[# | + | * Below: [[#Sample: Add toolbar button|Sample Action Plugin]] -- insert button in toolbar |
* Examples of [[Event handlers code]] | * Examples of [[Event handlers code]] | ||
* [[event_handlers_code# | * [[event_handlers_code# | ||
Line 94: | Line 113: | ||
* Dumps of [[Event Objects]] -- examples of event objects for some events | * Dumps of [[Event Objects]] -- examples of event objects for some events | ||
* Implementation of a custom [[Section Editor]] | * Implementation of a custom [[Section Editor]] | ||
+ | * [[devel: | ||
- | ==== Sample | + | ==== Sample: add always a JavaScript file ==== |
Insert a javascript script link in all pages. | Insert a javascript script link in all pages. | ||
Line 103: | Line 123: | ||
* Add javascript information to " | * Add javascript information to " | ||
- | <code php action.php> | + | <code php lib/ |
<?php | <?php | ||
+ | |||
+ | use dokuwiki\Extension\ActionPlugin; | ||
+ | use dokuwiki\Extension\EventHandler; | ||
+ | use dokuwiki\Extension\Event; | ||
+ | |||
/** | /** | ||
- | * Example Action Plugin: | + | * Example Action Plugin: Example Component. |
* | * | ||
- | * @author | + | * @author Samuele Tognini < |
*/ | */ | ||
- | if(!defined(' | + | class action_plugin_example extends |
- | + | ||
- | + | ||
- | class action_plugin_example extends | + | |
/** | /** | ||
* Register its handlers with the DokuWiki' | * Register its handlers with the DokuWiki' | ||
+ | | ||
+ | * @param EventHandler $controller event controller object | ||
*/ | */ | ||
- | function register(&$controller) { | + | |
- | $controller-> | + | $controller-> |
- | '_hookjs'); | + | $this, 'hookJsScript'); |
} | } | ||
/** | /** | ||
* Hook js script into page headers. | * Hook js script into page headers. | ||
- | * | + | * |
+ | * @param Event $event event object | ||
+ | * | ||
* @author Samuele Tognini < | * @author Samuele Tognini < | ||
*/ | */ | ||
- | function | + | |
- | $event-> | + | $event-> |
- | ' | + | ' |
- | ' | + | ' |
- | ' | + | ' |
- | ' | + | ' |
+ | ]; | ||
} | } | ||
- | }</ | + | } |
+ | </ | ||
- | ==== Sample | + | ==== Sample: add toolbar button ==== |
Inserts a button into the editor toolbar: | Inserts a button into the editor toolbar: | ||
Line 145: | Line 174: | ||
* adds a button definition to the event' | * adds a button definition to the event' | ||
- | <code php> | + | < |
<?php | <?php | ||
+ | |||
+ | use dokuwiki\Extension\ActionPlugin; | ||
+ | use dokuwiki\Extension\EventHandler; | ||
+ | use dokuwiki\Extension\Event; | ||
+ | |||
/** | /** | ||
* Example Action Plugin: Inserts a button into the toolbar | * Example Action Plugin: Inserts a button into the toolbar | ||
Line 153: | Line 187: | ||
*/ | */ | ||
- | if (!defined(' | + | class action_plugin_example |
- | + | ||
- | class action_plugin_actionexample | + | |
/** | /** | ||
- | * Register the eventhandlers | + | * Register the event handlers |
+ | * | ||
+ | * @param EventHandler $controller DokuWiki' | ||
*/ | */ | ||
- | function register(&$controller) { | + | |
- | $controller-> | + | $controller-> |
+ | $this, ' | ||
} | } | ||
/** | /** | ||
* Inserts the toolbar button | * Inserts the toolbar button | ||
+ | | ||
+ | * @param Event $event event object | ||
+ | * @param mixed $param [the parameters passed as fifth argument to | ||
+ | | ||
+ | | ||
*/ | */ | ||
- | function insert_button(& $event, $param) { | + | |
- | $event-> | + | $event-> |
' | ' | ||
' | ' | ||
Line 174: | Line 214: | ||
' | ' | ||
' | ' | ||
- | | + | |
} | } | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ==== Sample: handle ajax requests ==== | ||
+ | See [[devel: |
devel/action_plugins.1359169003.txt.gz · Last modified: 2013-01-26 03:56 by Klap-in