[development] implementing "plugins"

Dan Robinson dan at civicactions.com
Fri May 5 18:44:16 UTC 2006


thanks for jumping in :)
> There's a bunch of ways to do plugins in PHP, some OO some not.  In the CMS I 
> use at work, I think I have 2 or 3 different methods in use in various 
> places. :-)
>
> If this is for Drupal specifically, then there's really just two ways to 
> reasonably consider:
>
> 1) Do you want other modules to be able to define these plugins?  If so, then 
> the Drupal Way(tm) is to define a hook.  You would call something like:
>
> module_invoke_all('mymoduleapi', 'anoperation', $someparameter);
>
> And other modules can simply declare a function:
>
> function othermodule_mymoduleapi($op, $stuff) {
> ...
> }
>
> And do whatever.  Hooking those together is handled magically by Drupal.  See 
> hook_block(), hook_nodeapi(), etc. for examples.
>   
perfect - that's what I need.  I have a question about what if there are
multiple modules that are getting called back - but I'll look through
the doco and see what is what.   I'll come back if I have any questions
> 2) Do you want people to just drop .inc files into a plugins directory inside 
> your module?  For that, look at the flexinode module, which does exactly 
> that.  (There are lots of others, but that's the first one that comes to 
> mind.)  I've not looked at its guts in detail, but that's the direction you'd 
> want to go.
>   
yeah - i started here - but I like the hook idea much better.
> As for what gets included, If you're module is enabled then Drupal will 
> automatically include your mymodule.module file on every page load, but 
> that's it.  You can include/require whatever else you need/want.  Note that 
> it is NOT included into the global namespace, so if you put stuff outside of 
> a function (which you shouldn't do), it won't be happening globally.
>   
that's what I thought (that .module) are always included - thanks for
confirming.
> http://api.drupal.org/ - Your new best friend. :-)
>   
oh yeah - I'm all over it - just wasnt' sure the best place to begin -
thanks!
>
>   
>> Hi,
>>
>> I want to introduce a concept of "plugins" to my module.  In this case
>> the plugin merely needs to supply a single function that returns data.
>> Is the best way to do this to have the plugin call a register function
>> with the name of a function (and then call "eval"?).  This is probably
>> more of a PHP question than a Drupal question.  Oh yes and is there
>> documentation somewhere on what code Drupal automatically "includes"?
>>
>> Thanks,
>>
>> Dan
>>     
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20060505/176253e7/attachment.htm


More information about the development mailing list