[development] implementing "plugins"

Morbus Iff morbus at disobey.com
Fri May 5 19:44:28 UTC 2006


> 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"?

Sorry - I don't have a huge amount of time to talk about it, but check 
out my game.module. It does what you're asking, using a hook based 
system, but with .inc files. It's probably more complicated than what 
you need, but look for the following in the CVS [1]:

   The following routines duplicate the internal nodeapi
   and module loading of Drupal core, but with a focus on
   .inc files and as-needed loading.

And specifically these functions:

  game_system_list
  game_include_list
  game_include_invoke
  game_include_invoke_all
  game_include_hook

And for example:

  // load in all race includes
  $includes = game_system_list('races');

  // for each one loaded...
  foreach ($includes as $include) {

     // call the 'info' hook and store results in $shelf_item.
     $shelf_item = game_include_invoke($include->name, 'info');
  }

I'll try to answer any questions a bit later.

[1] http://cvs.drupal.org/viewcvs/drupal/contributions/modules/game/

-- 
Morbus Iff ( IGNORANCE IS BLISS, AND WE ARE BLISSED OFF )
Technical: http://www.oreillynet.com/pub/au/779
Culture: http://www.disobey.com/ and http://www.gamegrene.com/
icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus


More information about the development mailing list