3

I have a module which defines a plugin. Using this code, I can easily load the plugin:

ctools_include('plugins');
ctools_get_plugins('mymodule','myplugin');

That works great, but I would like my module to use plugins from other modules of type 'myplugin'.

I can only seem to get it to load plugins defined by the module provided in the first argument whereas I want to get all modules that provide plugin "myplugin", is there any way to do this?

2

With the code you shown, you get all the plugins of that type implemented by any module, not just from one module. In fact, when I execute the following code, I get the plugins implemented also from the Views UI module.

ctools_include('plugins');
dpm(ctools_get_plugins('ctools', 'export_ui'));

screenshot

The module name passed as first argument to ctools_get_plugins() is used to namespace the plugin type: There can be other modules that implement a "export_ui" plugin type, and that is the reason why the function requires the name of the module defining the plugin type.

See also the description given for hook_ctools_plugin_directory():

This hook is used to inform the CTools plugin system about the location of a directory that should be searched for files containing plugins of a particular type. CTools invokes this same hook for all plugins, using the two passed parameters to indicate the specific type of plugin for which it is searching.

  • Thanks for this. I realised that the issue I was having was that my plugin filenames were the same and so were getting merged. I still must be thinking of plugins in the wrong way though because I would have thought that I could have had plugins from multiple modules using the same filename but everytime I do they arent returned. – Tim Nov 27 '12 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.