devel:action_plugins
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
devel:action_plugins [2014-05-06 20:11] – [Working principle] Klap-in | devel:action_plugins [2023-09-01 17:10] – Klap-in | ||
---|---|---|---|
Line 12: | Line 12: | ||
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 18: | ||
* 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 33: | Line 34: | ||
<code php> | <code php> | ||
/** | /** | ||
- | * plugin should use this method to register its handlers with the DokuWiki' | + | * plugin should use this method to register its handlers with the DokuWiki' |
+ | | ||
* | * | ||
- | * @param | + | * @param |
+ | | ||
* | * | ||
* @return not required | * @return not required | ||
*/ | */ | ||
- | public function register(Doku_Event_Handler | + | public function register(EventHandler |
- | $controller-> | + | $controller-> |
} | } | ||
</ | </ | ||
Line 49: | Line 52: | ||
- '' | - '' | ||
- ''< | - ''< | ||
- | - ''< | + | - ''< |
- | - ''< | + | - ''< |
+ | |||
+ | | -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" | | ||
===== <event handler> | ===== <event handler> | ||
Line 64: | Line 77: | ||
* custom event handler | * custom event handler | ||
* | * | ||
- | * @param | + | * @param |
- | * @param mixed $param | + | * @param mixed $param the parameters passed to register_hook when this |
- | | + | |
* | * | ||
* @return | * @return | ||
*/ | */ | ||
- | public function < | + | public function < |
// custom script statements ... | // custom script statements ... | ||
} | } | ||
Line 107: | Line 120: | ||
* 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' | ||
*/ | */ | ||
- | public function register(Doku_Event_Handler | + | public function register(EventHandler |
$controller-> | $controller-> | ||
' | ' | ||
Line 133: | Line 148: | ||
* @author Samuele Tognini < | * @author Samuele Tognini < | ||
*/ | */ | ||
- | public function _hookjs(&$event, $param) { | + | public function _hookjs(Event $event) { |
- | $event-> | + | $event-> |
- | ' | + | ' |
- | ' | + | ' |
- | ' | + | ' |
- | ' | + | ' |
+ | ]; | ||
} | } | ||
- | }</ | + | } |
+ | </ | ||
==== Sample: add toolbar button ==== | ==== Sample: add toolbar button ==== | ||
Line 149: | Line 166: | ||
* adds a button definition to the event' | * adds a button definition to the event' | ||
- | <code php addbuton.php> | + | <code php lib/ |
<?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 157: | Line 179: | ||
*/ | */ | ||
- | if (!defined(' | + | class action_plugin_example |
- | + | ||
- | class action_plugin_actionexample | + | |
/** | /** | ||
* Register the eventhandlers | * Register the eventhandlers | ||
*/ | */ | ||
- | public function register(Doku_Event_Handler | + | public function register(EventHandler |
- | $controller-> | + | $controller-> |
} | } | ||
Line 171: | Line 191: | ||
* Inserts the toolbar button | * Inserts the toolbar button | ||
*/ | */ | ||
- | public function insert_button(& $event, $param) { | + | public function insert_button(Event $event, $param) { |
- | $event-> | + | $event-> |
' | ' | ||
' | ' | ||
Line 178: | Line 198: | ||
' | ' | ||
' | ' | ||
- | | + | |
} | } | ||
devel/action_plugins.txt · Last modified: 2023-09-01 23:52 by Klap-in