You are here: Foswiki>Tasks Web>Item9188 (22 Sep 2010, MichaelDaum)Edit Attach

Item9188: can't call createPlugin from within initPlugin

pencil
Priority: Normal
Current State: No Action Required
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: JQueryPlugin, ZonePlugin
Branches:
Reported By: MichaelDaum
Waiting For:
Last Change By: MichaelDaum
During initPlugin, a perl plugin might loading a specific jquery module by calling Foswiki::Plugins::JQueryPlugin::createPlugin(...). However, JQueryPlugin's own initPlugin will nuke this info during its own initialization phase.

Solutions:

  1. place JQueryPlugin early enough in {PluginsOrder}
  2. move some of JQueryPlugin's initialization into an earlyInitPlugin handler
  3. add a lateInitPlugin handler to the foswiki core, similar to the already existing earlyInitPlugin
  4. implement a lazy-init strategy in the plugin where handling a %MACRO will create the jquery module on demand. this doesn't cover all use cases but a lot. Skelleton:
    sub initPlugin {
       Foswiki::Func::registerTagHandler('MACRO', \&handleMACRO);
    }
    
    sub init {
      Foswiki::Plugins::JQueryPlugin::createPlugin("ui");
    }
    
    sub handleMACRO {
      init();
      ...
    }
    

... going with (2) for now.

Hotfix for Foswiki-1.1:

--- lib/Foswiki/Plugins/JQueryPlugin.pm (revision 7865)                           
+++ lib/Foswiki/Plugins/JQueryPlugin.pm (working copy)                            
@@ -57,14 +57,24 @@                                                               
     Foswiki::Func::registerTagHandler( 'BUTTON', \&handleButton );               
     Foswiki::Func::registerTagHandler( 'CLEAR',  \&handleClear );                
                                                                                  
-    # nukem                                                                      
-    Foswiki::Plugins::JQueryPlugin::Plugins::init();                             
-                                                                                 
     return 1;                                                                    
 }                                                                                
                                                                                  
 =begin TML                                                                       
                                                                                  
+---+++ earlyInitPlugin()                                                         
+                                                                                 
+initialize the plugins module early enough so that other perl plugins can call createPlugin() during
+their initPlugin handler                                                                            
+                                                                                                    
+=cut                                                                                                
+                                                                                                    
+sub earlyInitPlugin {                                                                               
+    Foswiki::Plugins::JQueryPlugin::Plugins::init();                                                
+}                                                                                                   
+ 
+=begin TML
+

-- MichaelDaum - 23 Jun 2010

This causes an uncaught error because addToZone is called before it has been defined.

-- DavidPatterson - 23 Jun 2010

The above fix only works on Foswiki-1.1 (trunk) which is not yet released. I will not commit this patch to the current JQueryPlugin to keep compatibility. So the only way to fix this short term is to go with Solution (1) or (4) as described above.

-- MichaelDaum - 23 Jun 2010

I got the same initialization error. In the warn log, I can read :
2010-07-30T05:28:30Z warning Foswiki::Plugins::JQueryPlugin ZonePlugin not installed/enabled...disabling JQueryPlugin
2010-07-30T05:28:30Z warning Foswiki::Plugins::JQueryPlugin::initPlugin did not return true (0)

Seems that ZonePlugin is a dependency of JQueryPlugin : I've got it installed and everything works ...

-- EricLepicier - 30 Jul 2010

ZonePlugin does its monkey patching in an earlyInitPlugin handler. So this should be fixed by now.

-- MichaelDaum - 22 Sep 2010
 

ItemTemplate edit

Summary can't call createPlugin from within initPlugin
ReportedBy MichaelDaum
Codebase
SVN Range
AppliesTo Extension
Component JQueryPlugin, ZonePlugin
Priority Normal
CurrentState No Action Required
WaitingFor
Checkins
TargetRelease n/a
ReleasedIn n/a
Topic revision: r5 - 22 Sep 2010, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy