You are here

function ctools_plugin_process in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 includes/plugins.inc \ctools_plugin_process()

Process a single hook implementation of a ctools plugin.

Parameters

array $info: The $info array about the plugin as returned by ctools_plugin_get_info()

string $module: The module that implements the plugin being processed.

string|array $identifier: Used to create the base setting of return value. If:

  • $identifier is a string, a hook name is created from this and the 'hook' key of the $info array, and the return value of that hook function is used. The hook is called like this: $identifier_$hook($info);
  • $identifier is an array, this array is used directly.

string $path: The path where files utilized by this plugin will be found.

string $file: The file that was loaded for this plugin, if it exists.

string $base: The base plugin name to use. If a file was loaded for the plugin, this is the plugin to assume must be present. This is used to automatically translate the array to make the syntax more friendly to plugin implementors.

Return value

null|array NULL on failure, otherwise an array containing the results keyed by name.

2 calls to ctools_plugin_process()
ctools_plugin_load_hooks in includes/plugins.inc
Load plugin info for the provided hook; this is handled separately from plugins from files.
ctools_plugin_load_includes in includes/plugins.inc
Load plugins from a directory.

File

includes/plugins.inc, line 681
Contains routines to organize and load plugins. It allows a special variation of the hook system so that plugins can be kept in separate .inc files, and can be either loaded all at once or loaded only when necessary.

Code

function ctools_plugin_process($info, $module, $identifier, $path, $file = NULL, $base = NULL) {
  if (is_array($identifier)) {
    $result = $identifier;
  }
  else {
    $function = $identifier . '_' . $info['hook'];
    if (!function_exists($function)) {
      return NULL;
    }
    $result = $function($info);
    if (!isset($result) || !is_array($result)) {
      return NULL;
    }
  }

  // Automatically convert to the proper format that lets plugin implementations
  // not nest arrays as deeply as they used to, but still support the older
  // format where they do:
  if ($base && (!isset($result[$base]) || !is_array($result[$base]))) {
    $result = array(
      $base => $result,
    );
  }
  return _ctools_process_data($result, $info, $module, $path, $file);
}