diff --git a/delegator/plugins/tasks/node_view.inc b/delegator/plugins/tasks/node_view.inc index 827a2cc785cd160e8496a7feb840fcb61068e17e..a02cb0ef25c32c9a7c79e33880c3ab2358bdd30f 100644 --- a/delegator/plugins/tasks/node_view.inc +++ b/delegator/plugins/tasks/node_view.inc @@ -1,6 +1,15 @@ <?php // $Id$ +/** + * @file + * Handle the 'node view' override task. + * + * This plugin overrides node/%node and reroutes it to the delegator, where + * a list of tasks can be used to service this request based upon criteria + * supplied by access plugins. + */ + /** * Specialized implementation of hook_delegator_tasks(). See api-task.html for * more information. diff --git a/help/plugins-api.html b/help/plugins-api.html new file mode 100644 index 0000000000000000000000000000000000000000..24a69e80b1c0a02b9be69b1d9da587b662cc72d6 --- /dev/null +++ b/help/plugins-api.html @@ -0,0 +1,46 @@ +<!-- $Id$ --> + +APIs are a form of plugins that are tightly associated with a module. Instead of a module providing any number of plugins, each module provides only one file for an API and this file can contain hooks that the module should invoke. + +Modules support this API by implementing hook_ctools_plugin_api($module, $api). If they support the API, they return a packet of data: + +function mymodule_ctools_plugin_api($module, $api) { + if ($module == 'some module' && $api = 'some api') { + return array( + 'version' => The minimum API version this system supports. If this API version is incompatible then the .inc file will not be loaded. + 'path' => Where to find the file. Optional; if not specified it will be the module's directory. + 'file' => an alternative version of the filename. If not specified it will be $module.$api.inc + ); + } +} + +This implementation must be in the .module file. + +Modules utilizing this can invole ctools_plugin_api_include() in order to ensure all modules that support the API will have their files loaded as necessary. It's usually easiest to create a small helper function like this: + +define('MYMODULE_MINIMUM_VERSION', 1); +define('MYMODULE_VERSION', 1); + +function mymodule_include_api() { + ctools_include('plugins'); + return ctools_plugin_api_include('mymodule', 'myapi', MYMODULE_MINIMUM_VERSION, MYMODULE_VERSION); +} + +Using a define will ensure your use of version numbers is consistent and easy to update when you make API changes. You can then use the usual module_invoke type commands: + +mymodule_include_api(); +module_invoke('myhook', $data); + +If you need to pass references, this construct is standard: + +foreach (mymodule_include_api() as $module => $info) { + $function = $module . '_hookname'; + // Just because they implement the API and include a file does not guarantee they implemented + // a hook function! + if (!function_exists($function)) { + continue; + } + + // Typically array_merge() is used below if data is returned. + $result = $function($data1, $data2, $data3); +} \ No newline at end of file diff --git a/help/plugins-creating.html b/help/plugins-creating.html index ca0204421aed89654709d6fe751c13d8239690d8..54c11c145930f3dcfeb1bad7ef050c2f25c64983 100644 --- a/help/plugins-creating.html +++ b/help/plugins-creating.html @@ -44,4 +44,5 @@ General feature for callbacks: 'function' => 'function_name' ), - Using ctools_plugin_get_function() or ctools_plugin_load_function() will take advantage. \ No newline at end of file + Using ctools_plugin_get_function() or ctools_plugin_load_function() will take advantage. + diff --git a/includes/plugins.inc b/includes/plugins.inc index 61235643f0cd21f71ecb8979ffeaef9cf64d0f07..fce5132eabd415c538a09de2e757d3188b5c88d8 100644 --- a/includes/plugins.inc +++ b/includes/plugins.inc @@ -9,6 +9,70 @@ * necessary. */ +/** + * Load a group of API files. + * + * This will ask each module if they support the given API, and if they do + * it will load the specified file name. The API and the file name + * coincide by design. + * + * This function invokes hook_ctools_api. This invokation is statically + * cached, so feel free to call it as often per page run as you like, it + * will cost very little. + * + * @param $owner + * The name of the module that controls the API. + * @param $api + * The name of the api. The api name forms the file name: + * $module.$api.inc + * @param $minimum_version + * The lowest version API that is compatible with this one. If a module + * reports its API as older than this, its files will not be loaded. This + * should never change during operation. + * @param $current_version + * The current version of the api. If a module reports its minimum API as + * higher than this, its files will not be loaded. This should never change + * during operation. + * + * @return + * The API information, in case you need it. + */ +function ctools_plugin_api_include($owner, $api, $minimum_version, $current_version) { + static $cache = array(); + if (!isset($cache[$owner][$api])) { + $cache[$owner][$api] = array(); + foreach (module_implements('ctools_plugin_api') as $module) { + $function = $module . '_ctools_plugin_api'; + $info = $function(); + if (!isset($info['version'])) { + continue; + } + + // Only process if version is between minimum and current, inclusive. + if ($info['version'] >= $minimum_version && $info_version <= $current_version) { + if (!isset($info['path'])) { + $info['path'] = drupal_get_path('module', $module); + } + if (!isset($info['file'])) { + $info['file'] = "$module.$api.inc"; + } + $cache[$owner][$api][$module] = $info; + } + } + + // Now that we have a list, do our includes. + foreach ($cache[$owner][$api] as $module => $info) { + if (file_exists("./$info[path]/$info[file]")) { + $cache[$owner][$api][$module]['included'] = TRUE; + require_once "./$info[path]/$info[file]"; + } + } + + } + + return $cache[$module][$api]; +} + /** * Fetch a group of plugins by name. * diff --git a/plugins/access/node_access.inc b/plugins/access/node_access.inc index 55a9cc62b4315f3bebe43e21d0ea4393a24878a7..bf5393cee309f2b6ee7e05b08ac004b4e132af80 100644 --- a/plugins/access/node_access.inc +++ b/plugins/access/node_access.inc @@ -11,7 +11,7 @@ */ function ctools_node_access_ctools_access() { $args['node_access'] = array( - 'title' => t("Node access"), + 'title' => t("Operation"), 'description' => t('Control access with built in Drupal node access test.'), 'callback' => 'ctools_node_access_ctools_access_check', 'default' => array('type' => 'view'),