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 [2017-08-18 17:47] – Correct misspelling 'class action_plugin_actionexample' 50.226.69.58 | 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 33: | Line 36: | ||
<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 |
*/ | */ | ||
- | public function register(Doku_Event_Handler | + | public function register(EventHandler |
- | $controller-> | + | $controller-> |
+ | <event handler function>, | ||
+ | < | ||
+ | < | ||
} | } | ||
</ | </ | ||
Line 49: | Line 56: | ||
- '' | - '' | ||
- ''< | - ''< | ||
- | - ''< | + | - ''< |
- ''< | - ''< | ||
Line 65: | Line 72: | ||
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 DokuWiki' | 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 DokuWiki' | ||
- | |||
- | The passed arguments are: | ||
- | - '' | ||
- | - '' | ||
<code php> | <code php> | ||
Line 74: | Line 77: | ||
* custom event handler | * custom event handler | ||
* | * | ||
- | * @param | + | * @param |
- | * @param mixed $param | + | * @param mixed $param |
- | | + | |
* | * | ||
- | * @return | + | * @return |
*/ | */ | ||
- | public function < | + | public function < |
// custom script statements ... | // custom script statements ... | ||
} | } | ||
</ | </ | ||
+ | The passed arguments are: | ||
+ | - '' | ||
+ | - '' | ||
===== Further reading ===== | ===== Further reading ===== | ||
Line 117: | 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 | ||
*/ | */ | ||
- | public function register(Doku_Event_Handler | + | public function register(EventHandler |
- | $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 < | ||
*/ | */ | ||
- | public function | + | public function |
- | $event-> | + | $event-> |
- | ' | + | ' |
- | ' | + | ' |
- | ' | + | ' |
- | ' | + | ' |
+ | ]; | ||
} | } | ||
- | }</ | + | } |
+ | </ | ||
==== Sample: add toolbar button ==== | ==== Sample: add toolbar button ==== | ||
Line 159: | Line 174: | ||
* 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 167: | Line 187: | ||
*/ | */ | ||
- | if (!defined(' | + | class action_plugin_example extends |
- | + | ||
- | class action_plugin_example extends | + | |
/** | /** | ||
- | * Register the eventhandlers | + | * Register the event handlers |
+ | * | ||
+ | * @param EventHandler $controller DokuWiki' | ||
*/ | */ | ||
- | public function register(Doku_Event_Handler | + | public function register(EventHandler |
- | $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 | ||
+ | | ||
+ | | ||
*/ | */ | ||
- | public function insert_button(Doku_Event | + | public function insert_button(Event $event, $param) { |
- | $event-> | + | $event-> |
' | ' | ||
' | ' | ||
Line 188: | Line 214: | ||
' | ' | ||
' | ' | ||
- | | + | |
} | } | ||
devel/action_plugins.1503071276.txt.gz · Last modified: 2017-08-18 17:47 by 50.226.69.58