Question
As mentioned in
BulletListNotRenderedOnOutputOfPlugin, I have a plugin that extracts form data and displays it. I now came across a bug in my plugin when rendering a preview page: Within the plugin, I use
TWiki::Func::readTopic() to extract the meta data and read form fields from that. The problem is that when rendering the preview page, my plugin still uses the data stored on disk to render the field's value instead of the data entered on the edit page.
Is there a way to get the topic's data (text and meta) from within a plugin when previewing a topic?
Environment
--
ThomasJachmann - 02 Oct 2003
Answer
I hacked a solution myself now, unfortunately having to change TWiki core code:
-
preview script
$text = $meta->write( $text ); # add meta data for Plugin callback
TWiki::Plugins::afterEditHandler( $text, $topic, $webName );
$meta = TWiki::Meta->remove(); # remove all meta data
$text = $meta->read( $text ); # restore meta data
instead of just
TWiki::Plugins::afterEditHandler( $text, $topic, $webName );
This code is taken from TWiki::Store::saveTopic
- TWiki::Plugins::KnowledgeBasePlugin::afterEditHandler
This method now takes the meta data from the $text variable and extracts the meta data which will be used in subsequent calls to the plugin during preview
BTW: Is there a reason why meta data is contained within $text for say beforeSaveHandler but not for afterEditHandler?
Maybe someone can approve/disapprove my approach.
--
ThomasJachmann - 10 Oct 2003
What you describe seems very convoluted.
TWiki::Form::fieldVars2Meta( $webName, $query, $meta ) is available to convert query parameters to $meta; you should probably use this instead of touching the core code.
The various handler APIs are not well specced; the asymmetry in the calls is probably just due to the way the handler calls were added and the needs at the time of the person who added them. I suspect there is no "plan" behind the difference.
--
CrawfordCurrie - 02 Jun 2004