DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:common_plugin_functions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
devel:common_plugin_functions [2023-08-08 14:42] 130.112.1.3devel:common_plugin_functions [2023-09-01 13:56] (current) – refactor examples Klap-in
Line 72: Line 72:
  
 ===== Instantiating ===== ===== Instantiating =====
-Default DokuWiki reuses instances of plugins. This can be prevented by adding the function ''[[xref>isSingleton()]]'' that returns false, so ''plugin_load('<plugin type> '<plugin name>')'' and ''loadHelper('<plugin name>, true)'' will return an new plugin object on each call.+Default DokuWiki reuses instances of plugins. This can be prevented by adding the function [[xref>isSingleton()]] that returns false, so [[xref>plugin_load('<plugin type>', '<plugin name>')]] and [[xref>loadHelper('<plugin name>', true)]] will return an new plugin object on each call.
 <code php> <code php>
 /** /**
Line 86: Line 86:
  
 =====Load Helper plugins===== =====Load Helper plugins=====
-In all plugins Helper plugins can be loaded by $this->''[[xref>loadHelper('tag', true)]]''. First argument is helper plugin name, second argument if English error message should be displayed (cannot be localized). It will reuses the instance of the requested plugin, so it will return always the same plugin object. To prevent this behaviour see [[#instantiating]] above.+In all plugins Helper plugins can be loaded by ''%%$this->%%''[[xref>loadHelper('tag', true)]]. First argument is helper plugin name, second argument if English error message should be displayed (cannot be localized). It will reuses the instance of the requested plugin, so it will return always the same plugin object. To prevent this behaviour see [[#instantiating]] above.
  
 It loads a given helper plugin if the plugin is enabled. Details and examples in [[helper plugins]].  It loads a given helper plugin if the plugin is enabled. Details and examples in [[helper plugins]]. 
Line 96: Line 96:
 $tag = $this->loadHelper('tag', true); $tag = $this->loadHelper('tag', true);
    
-if($tag) {+if($tag instanceof PluginInterface) {
     $entries = $tag->tagRefine($entries, $refine);     $entries = $tag->tagRefine($entries, $refine);
 } }
Line 112: Line 112:
 <code php> <code php>
 if(!plugin_isdisabled('tag')) { if(!plugin_isdisabled('tag')) {
-    $tag =plugin_load('helper', 'tag'); +    $tag = plugin_load('helper', 'tag'); 
-    if($tag) {+    if($tag instanceof PluginInterface) {
         $entries = $tag->tagRefine($entries, $refine);         $entries = $tag->tagRefine($entries, $refine);
     }     }
Line 122: Line 122:
 <code php> <code php>
 if(!plugin_isdisabled('data')) { if(!plugin_isdisabled('data')) {
-    $table =plugin_load('syntax', 'data_table'); +    $table = plugin_load('syntax', 'data_table'); 
-    if($table) {+    if($table instanceof PluginInterface) {
         $hasfilter = $table->hasRequestFilter();         $hasfilter = $table->hasRequestFilter();
     }     }
devel/common_plugin_functions.txt · Last modified: 2023-09-01 13:56 by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki