function ctools_plugin_get_class

Get a class from a plugin, if it exists. If the plugin is not already loaded, try ctools_plugin_load_class() instead.

Parameters

$plugin_definition: The loaded plugin type.

$class_name: The identifier of the class. For example, 'handler'.

Return value

string The actual name of the class to call, or NULL if the class does not exist.

2 calls to ctools_plugin_get_class()
ctools_export_ui_get_handler in includes/export-ui.inc
Get the class to handle creating a list of exportable items.
ctools_plugin_load_class in includes/plugins.inc
Load a plugin and get a class name from it, returning success only if the class exists.

File

includes/plugins.inc, line 859

Code

function ctools_plugin_get_class($plugin_definition, $class_name) {
  // 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_definition['file'])) {
    // Plugins that are loaded from info files have the info file as
    // $plugin['file'].  Don't try to run those.
    $info = ctools_plugin_get_info($plugin_definition['plugin module'], $plugin_definition['plugin type']);
    if (empty($info['info file'])) {
      require_once DRUPAL_ROOT . '/' . $plugin_definition['path'] . '/' . $plugin_definition['file'];
    }
  }
  $return = FALSE;
  if (!isset($plugin_definition[$class_name])) {
    return;
  }
  elseif (is_string($plugin_definition[$class_name])) {
    // Plugin uses the string form shorthand.
    $return = $plugin_definition[$class_name];
  }
  elseif (isset($plugin_definition[$class_name]['class'])) {
    // Plugin uses the verbose array form.
    $return = $plugin_definition[$class_name]['class'];
  }
  // @todo consider adding an else {watchdog(...)} here
  return $return && class_exists($return) ? $return : NULL;
}