1

Perhaps, the question should be how do I implement ctools plugins using classes to extend different types of an object? I can't find a simple explanation.

6

mymodule.module:

<?php
/**
 * Implements hook_ctools_plugin_api().
 */
function mymodule_ctools_plugin_api() {
    list($module, $api) = func_get_args();

    if ($module == 'mymodule' && ($api == 'plugins')) {
        return array('version' => 1.0);
    }
}

/**
 * Implements hook_ctools_plugin_type().
 */
function mymodule_ctools_plugin_type() {
    return array(
        'plugin_type' => array(
            'classes' => array('handler'),
        ),
    );
}

/**
 * Implements hook_ctools_plugin_directory().
 */
function mymodule_ctools_plugin_directory($owner, $plugin_type) {
    if ($owner == 'mymodule') {
        return "plugins/$plugin_type";
    }
}

plugins/plugin_type/example.inc:

<?php
$plugin = array(
    'title' => t('Example'),
    'handler' => array(
        'class' => 'ExamplePlugin',
    ),
);

plugins/plugin_type/ExamplePlugin.class.inc:

<?php
class ExamplePlugin {
function __construct($plugin){

}
}

Anywhere:

<?php
// Get all available plugins
$plugins = ctools_get_plugins('mymodule', 'plugin_type');

// Load a specific plugin
ctools_include('plugins');
$plugin = ctools_get_plugins('mymodule', 'plugin_type', 'example');
$class_name = ctools_plugin_get_class($plugin, 'handler');
$example = new ExamplePlugin($plugin);

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