[dokuwiki] Re: events

  • From: "Martin Tschofen" <martin.tschofen@xxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Sat, 22 Apr 2006 21:47:37 -0500

That makes things clearer. In addition to these events we have at the
beginning DOKUWIKI_START, at the end DOKUWIKI_END and right after
ACTION_DISPATCH is SEND_HEADERS. I'm not sure where HANDLER_FINALISE
fits though.

In order to make this clearer I did some testing and here's what I
understand is happening.
With a new command. You have to at least register for two events.
1. ACTION_DISPATCH to register the command e.g. do=collect
2. Execution of the command via either ACTION_TEMPLATE or TPL_ACTION_HTML
Example:
  function register(&$controller) {
    $controller->register_hook('ACTION_DISPATCH', $this, 'collect', NULL);
  }

  function collect($param, &$event){
 //Skip this event if the command is not collect
   if ($event->data != 'collect') return;
        $event->preventDefault();
  //register what to do in such a case
        global $EVENT_HANDLER;
    $EVENT_HANDLER->register_hook('TPL_ACTION_HTML', $this, 'tpl_action', null);
        $event->stopPropagation();
  }

It's not possible to work with any of the later events without first
registering with ACTION_DISPATCH. That makes sense (now).

For overriding an existing one, in that case you don't need an
ACTION_DISPATCH. Just a TPL_ACTION_HTML is enough or what you
indicated with the ACTION_TEMPLATE.

I think I also figured out how to use $param. In the above example I
could create an array and pass it in as $param. I can then access it
within the function assigned to the event.
In order to pass information from one event to other events (with
potential changes to $param), the only way I can see is passing $param
into the first event, then in that event register the next event and
passing the new data in as $param.

I'm a little confused though yet how to add content within these
events and consume the output.
Let's assume I've registered function collect() with a command 'collect'
  function collect($param, &$event){
    if ($event->data != 'collect') return;
        $event->preventDefault();
        global $EVENT_HANDLER;
    $EVENT_HANDLER->register_hook('TPL_ACTION_HTML', $this, 'tpl_action', null);
        
$EVENT_HANDLER->register_hook('TPL_DISPLAY_HTML',$this,'tpl_display',null);
        $event->stopPropagation();
  }

  function tpl_action($param, &$event){
    print "Collect print<br>";
        $event->preventDefault();
        $event->stopPropagation();
  }

  function tpl_display($param, &$event){
    print $event->data;
    print "TPL_Display_HTML output<br>";
  }

I would expect the output to be:
  Collect print
  TPL_Display_HTML output

But I get instead:
Collect print
TPL_Display_HTML output
Collect print

It looks like tpl_action spits out it's content into the buffer and
then writes it out after tpl_display. That doesn't make sense.

If I then register TPL_DISPLAY_HTML_AFTER with the following function:

  function tpl_display_after($param, &$event){
    print $event->data;
    print "TPL_Display_HTML_AFTER output<br>";
  }

That info doesn't come through at all. So how can I in that case
access the buffered html and process it before outputting it?

Even though I haven't quite figured it out...this is cool...martin
--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: