devel:events
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devel:events [2013-11-05 23:48] – [Registering to Receive an Event] Klap-in | devel:events [2023-09-02 13:58] (current) – [On Wiki page save] Klap-in | ||
---|---|---|---|
Line 14: | Line 14: | ||
===== Event Object ===== | ===== Event Object ===== | ||
- | **class name '' | + | **Class name [[xref> |
An event object consists of: | An event object consists of: | ||
- | * **PUBLIC** properties | + | * **Public** properties |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * **PRIVATE** properties | + | * **Protected** properties |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * **PUBLIC** methods | + | * **Public** methods |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
+ | * '' | ||
+ | * '' | ||
* '' | * '' | ||
- | * '' | + | * '' |
- | * '' | + | * '' |
===== Registering to Receive an Event ===== | ===== Registering to Receive an Event ===== | ||
Line 38: | Line 41: | ||
To register a hook to receive an event, call the '' | To register a hook to receive an event, call the '' | ||
- | | + | <code php> |
- | $EVENT_HANDLER-> | + | global $EVENT_HANDLER; |
+ | $EVENT_HANDLER-> | ||
+ | </ | ||
- | For up-to-date details of the [[xref> | + | For up-to-date details of the [[xref> |
+ | Use '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
- | |||
- | <code php> | ||
- | /** | ||
- | * register_hook | ||
- | * | ||
- | * register a hook for an event | ||
- | * | ||
- | * @param string | ||
- | * @param string | ||
- | * @param obj $obj object in whose scope method is to be executed, | ||
- | | ||
- | * @param function $method event handler function | ||
- | * @param mixed $param | ||
- | | ||
- | function register_hook($event, | ||
- | |||
- | </ | ||
===== Signalling an Event ===== | ===== Signalling an Event ===== | ||
An event can be signalled in three ways. | An event can be signalled in three ways. | ||
- | | + | |
- | /** | + | |
- | | + | |
- | * | + | |
- | | + | |
- | * | + | |
- | | + | |
- | | + | Event:: |
- | | + | <action |
- | | + | |
- | * | + | |
- | | + | |
- | | + | |
- | | + | |
- | */ | + | |
- | function trigger_event($name, &$data, $action=NULL, $canPreventDefault=true) | + | |
</ | </ | ||
- | - using the trigger method. | + | - using the [[xref>trigger()]] method. |
- | $evt = new Doku_Event(<event_name>,< | + | $event = new dokuwiki\Extension\Event(<EVENT_NAME>,< |
- | $evt-> | + | $event-> |
- | unset($evt); | + | unset($event); |
</ | </ | ||
- | - managing the whole event signalling process. | + | - managing the whole event signalling process |
- | $evt = new Doku_Event(<event name>, <event data> | + | $event = new dokuwiki\Extension\Event(<EVENT_NAME>, <event data> |
- | if ($evt-> | + | if ($event-> |
- | // default action code block | + | // default action code block |
- | } | + | } |
- | $evt-> | + | $event-> |
- | unset($evt); | + | unset($event); |
</ | </ | ||
+ | |||
===== Examples ===== | ===== Examples ===== | ||
- | (these are examples only and may not exist in DokuWiki) | + | (These are examples only and may not exist in DokuWiki.) |
- | ** On Wiki page save ** | + | ==== On Wiki page save ==== |
<code php> | <code php> | ||
+ | use dokuwiki\Extension\Event; | ||
+ | |||
// event: | // event: | ||
// data: | // data: | ||
// action: save the raw wiki page to file name | // action: save the raw wiki page to file name | ||
// return: bool, page saved | // return: bool, page saved | ||
- | $data = array($id, | + | $data = [$id, $wikitext]; |
- | $ok = trigger_event(' | + | $ok = Event:: |
</ | </ | ||
- | possible | + | Possible |
- | ---- | + | |
- | ** Additional/ | + | |
+ | ==== Additional/ | ||
<code php> | <code php> | ||
- | | + | // events: |
- | // data: $ACT (value of the '' | + | // data: $ACT (value of the '' |
- | // action: | + | // action: |
- | + | ||
- | // in '' | + | // in '' |
- | $evt = new Doku_Event(' | + | $event = new dokuwiki\Extension\Event(' |
- | if ($evt-> | + | if ($event-> |
- | | + | /* process $ACT normally */ |
- | } | + | } |
- | $evt-> | + | $event-> |
- | unset($evt); | + | unset($event); |
- | + | ||
- | // in '' | + | // in '' |
- | default: | + | // default: unrecognised $ACT value |
- | $evt = new Doku_Event(' | + | $event = new dokuwiki\Extension\Event(' |
- | if ($evt-> | + | if ($event-> |
- | | + | print " |
- | } | + | } |
- | $evt-> | + | $event-> |
- | unset($evt); | + | unset($event); |
</ | </ | ||
- | possible | + | Possible |
- | ---- | + | |
- | ** On handler instruction list completion | + | |
+ | ==== On handler instruction list completion | ||
<code php> | <code php> | ||
- | | + | use dokuwiki\Extension\Event; |
- | // data: the handler, including the completed instruction list | + | |
- | // action: none | + | // event: |
+ | // data: the handler, including the completed instruction list | ||
+ | // action: none | ||
| | ||
- | | + | // in '' |
- | | + | Event:: |
</ | </ | ||
possible handlers, footnote replacement plugins, enhanced TOC handlers | possible handlers, footnote replacement plugins, enhanced TOC handlers | ||
- | ---- | + | |
+ | =====See also===== | ||
+ | * [[Events List]] with existing events. | ||
+ | * Use [[devel: | ||
+ | * More about [[Event handlers]] | ||
+ | * Examples of [[event handlers code]] |
devel/events.1383691683.txt.gz · Last modified: 2013-11-05 23:48 by Klap-in