I am trying to implement plugins as classes using the new functionality introduced in #348323: Class dependency aware plugin loading but have run into some problems if the definition of the plugins are not done in a hook function.

- If i define the plugin in a plugin_name.inc file in the specified plugins directory, the default class file is expected to be plugin_class_name.inc. Since the plugin discovery mechanism will by default look for *.inc files, the plugin_class_name.inc file will be loaded and interpreted as a plugin.

- If I define the plugin in a .info file, the class file is loaded at the proper time, but a new bug pops up. This code:

  // If cached the .inc file may not have been loaded. require_once is quite safe
  // and fast so it's okay to keep calling it.
  if (isset($plugin['file'])) {
    require_once './' . $plugin['path'] . '/' . $plugin['file'];
  }

from ctools_plugin_get_class() tries to include $plugin['file'], which in this case is a .info file. This results in the contents of the info file being output to the browser.

CommentFileSizeAuthor
#5 ctools.class_.patch809 byteszroger
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zroger’s picture

Looks like the info file issue could be a problem with ctools_plugin_get_function() as well since it has the same block of code.

zroger’s picture

To provide some more context, here is the example implementation.

mymodule/plugins/plugintype/myplugin.inc

function mymodule_myplugin_pluginmodule_plugintype() {
  return array(
    'title' => t('My custom plugin'),
    'custom class' => 'myplugin_class',
  );
}

then my class is in:
mymodule/plugins/plugintype/myplugin_class.inc

zroger’s picture

I created a new issue for the info file incompatibilty at #564522: .info files for plugins get required()'ed.

Lets concentrate on the class loading here. Since by default, the plugin auto-discovery will load all *.inc files in the plugins directory and expect it to be a plugin, I think we need to change the default pattern for a class include file to something besides [classname].inc.

Maybe [classname].class.php?

merlinofchaos’s picture

Hmm. I'd be ok with .class.php or even just .php

zroger’s picture

Status: Active » Needs review
FileSize
809 bytes

patch using .class.php

merlinofchaos’s picture

Status: Needs review » Fixed

Committed!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.