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.
Comment | File | Size | Author |
---|---|---|---|
#5 | ctools.class_.patch | 809 bytes | zroger |
Comments
Comment #1
zroger CreditAttribution: zroger commentedLooks like the info file issue could be a problem with
ctools_plugin_get_function()
as well since it has the same block of code.Comment #2
zroger CreditAttribution: zroger commentedTo provide some more context, here is the example implementation.
mymodule/plugins/plugintype/myplugin.inc
then my class is in:
mymodule/plugins/plugintype/myplugin_class.inc
Comment #3
zroger CreditAttribution: zroger commentedI 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?
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedHmm. I'd be ok with .class.php or even just .php
Comment #5
zroger CreditAttribution: zroger commentedpatch using .class.php
Comment #6
merlinofchaos CreditAttribution: merlinofchaos commentedCommitted!