Accessing one plugin’s methods from within another plugin
Posted: 11 November 2007 09:41 PM   [ Ignore ]  
Lab Assistant
RankRank
Total Posts:  107
Joined  11-17-2005

Hi all,

Is it possible to access one plugin from within another? I don’t mean by nesting plugins within a template, but instead doing the work within the plugin code itself. It seems like the parse_type method of the typography class might do the job.

On a separate note, does anyone have any good advice on when a development situation calls for a module vs a plugin? It seems like this would be a good addition to the documentation.

Many thanks, as ever,
Rob

Profile
 
 
Posted: 12 November 2007 06:09 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  404
Joined  02-14-2007

You should be able to use one plugin inside another—depending on many things, of course.  One, whether that plugin requires use of the TMPL or Template class.  If so, you are likely out of luck—while you can access it, the other plugin will break. 

But yes, since a plugin is a class, just test for like the Typography class.  Assign a variable to represent the plugin, and then create the plugin class… and access it just like any other php class would, outside of EE.

Profile
 
 
Posted: 12 November 2007 07:02 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1330
Joined  02-12-2003

RobJ25,

Definately possible.  Though how useful it will be to you depends greatly on how the plugin’s functions are written.  If the plugin functionality is abstracted from the main function that interfaces wtih the TMPL class then it will work out fairly well.  If not then it may not be of much use to you.

I outlined how you would call a Plugin class within a function in another thread

If you have any questions or need details feel free to ask.

Jamie

Profile
 
 
Posted: 12 November 2007 07:04 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1330
Joined  02-12-2003

And to add to this.  If you want the Typography class specifically you don’t need to call that from the Typography plugin.  Call it straight from the source like the plugin itself does.

Jamie

Profile
 
 
Posted: 12 November 2007 07:54 PM   [ Ignore ]   [ # 4 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15861
Joined  06-03-2002
Vanceone - 12 November 2007 06:09 PM

One, whether that plugin requires use of the TMPL or Template class.  If so, you are likely out of luck—while you can access it, the other plugin will break

You’re going to need to elaborate on that Vanceone, as I’ve done that on a number of occasions.

 Signature 
Profile
MSG
 
 
Posted: 12 November 2007 08:01 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  404
Joined  02-14-2007

Well, I’ll defer to you, of course, Derek.  But my thinking was that if the plugin you are including is expecting to get data from the template class directly, and such data is not available, then it would return errors or nonsense.

Example: my custom member data plugin.  It expects any number of parameters, which it gets from the TMPL class.  I never provided a way to pass in parameters to the methods.  So, to call my plugin directly from another plugin, module, etc just wouldn’t work, unless there is inside the TMPL class some parameters that can be passed to my plugin.  I.e. I expect a “data” parameter—and if I don’t get one, my plugin just returns an empty string.  I get my “data” parameter straight from the TMPL class.  How would another module supply that parameter to my plugin?

Now, other plugins, etc. may not have that issue, and indeed, I can see a plugin that gets tag data from the TMPL class working anyway, as it just would get the same data as the calling class (I think), and go from there.

Or have I missed some fundamental concept?  I think Jamie is talking about the same thing I am in this thread.

With my plugin, though, it wouldn’t be too hard to adjust so it would play nice with others.

Profile
 
 
Posted: 12 November 2007 08:28 PM   [ Ignore ]   [ # 6 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15861
Joined  06-03-2002

Well your plugin methods can easily be modified to accept parameters.  Just provide defaults when nothing is passed directly to the methods, which will be the case when it’s called from a tag.

function foo($bar = '', $bat = '')

But if you are referencing the global $TMPL object, it will not have changed from merely calling another class in another file.

pi.foo.php:

class Foo {
    
    
function Foo()
    
{
        
if (! class_exists('Bar'))
        
{
            
require PATH_PI.'pi.bar'.EXT;
            
            
$bar = new Bar;            
        
}
    }
}

pi.bar.php:

class Bar {
    
    
function Bar()
    
{
        
global $TMPL;
        
        
print_r($TMPL);
    
}
}

Tag in the template:

{exp:foo param_1="value_1" param_2="value_2"}
This is the tagdata
.
{/exp:foo}

 Signature 
Profile
MSG
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65063 Total Logged-in Users: 49
Total Topics: 82196 Total Anonymous Users: 25
Total Replies: 441740 Total Guests: 241
Total Posts: 523936    
Members ( View Memberlist )
Newest Members:  1nvidiousjaris1skinnygirlaexermk1979Andrew_IDmdutahDanielJ8Forward GearCBlalock