Index: API.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ctools/API.txt,v retrieving revision 1.5.2.14 diff -u -p -r1.5.2.14 API.txt --- API.txt 23 Feb 2010 23:14:53 -0000 1.5.2.14 +++ API.txt 17 Mar 2010 16:42:01 -0000 @@ -5,13 +5,15 @@ API version 1.4: Allow themes to provide APIs which includes default pages of all types. Intorduce ctools_css_add_css() to allow private file systems to have generated CSS. Introduce initial build of stylizer.inc to allow UI configurable styles. - Introduce 'cache warming' feature. Use 'ctools-use-ajax-cache' or + Introduce 'cache warming' feature. Use 'ctools-use-ajax-cache' or 'ctools-use-modal-cache'. Doing so will cause content to be fetched via AJAX on page load and kept warm in a cache for instant responses to clicks. Generalized ctools_add_css(). Generalized ctools_add_js(). Generalized ctools_image_path(). + Make global hooks for plugin definition optional through a 'use hooks' + plugin option. API version 1.3.2: Introduce 'export callback' to individual fields in export.inc @@ -40,13 +42,13 @@ API version 1.1.1: Introduce ctools_set_page_token(). API version 1.1.0: - delegator module destroyed, replaced by page manager. All 'task' and 'task_handler' plugins + delegator module destroyed, replaced by page manager. All 'task' and 'task_handler' plugins now owned by page_manager. Update plugin hooks accordingly. The filename for defaults for pages and handlers should now be MODULE.pages_default.inc The task_type plugin has been removed. - Task handlers no longer have a separate UI. While task handlers can still + Task handlers no longer have a separate UI. While task handlers can still be separated from pages for other purposes, they will probably need to implement their own UI to do it. Index: help/plugins-creating.html =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ctools/help/plugins-creating.html,v retrieving revision 1.9 diff -u -p -r1.9 plugins-creating.html --- help/plugins-creating.html 22 Jun 2009 02:27:19 -0000 1.9 +++ help/plugins-creating.html 17 Mar 2010 16:42:01 -0000 @@ -69,6 +69,8 @@ The following information can be specifi
$plugin = array(
Index: includes/plugins.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ctools/includes/plugins.inc,v
retrieving revision 1.18.2.14
diff -u -p -r1.18.2.14 plugins.inc
--- includes/plugins.inc 17 Mar 2010 13:26:27 -0000 1.18.2.14
+++ includes/plugins.inc 17 Mar 2010 16:42:01 -0000
@@ -163,63 +163,60 @@ function ctools_plugin_api_include($owne
* of the array are specific to the plugin.
*/
function ctools_get_plugins($module, $type, $id = NULL) {
- static $plugins = array();
- static $all_hooks = array();
- static $all_files = array();
+ // Store local caches of plugins and plugin info so we don't have to do full
+ // lookups everytime.
static $info = array();
+ static $plugins = array();
- if (!isset($plugins[$module])) {
- $plugins[$module] = array();
- }
+ // Store the status of plugin loading. If a module plugin type pair is true,
+ // then it is fully loaded and no searching or setup needs to be done.
+ static $setup = array();
// Request metadata/defaults for this plugin from the declaring module. This
// is done once per page request, upon a request being made for that plugin.
- if (!isset($plugins[$module][$type])) {
- $plugins[$module][$type] = array();
- }
-
if (!isset($info[$module][$type])) {
$info[$module][$type] = ctools_plugin_get_info($module, $type);
+ // Also, initialize the local plugin cache.
+ $plugins[$module][$type] = array();
}
+ // We assume we don't need to build a cache.
+ $build_cache = FALSE;
// If the plugin info says this can be cached, check cache first.
- if ($info[$module][$type]['cache'] && !isset($plugins['cache'])) {
+ if ($info[$module][$type]['cache'] && empty($setup[$module][$type])) {
// @todo Maybe this should use our own table but free wiping
// with content updates is convenient.
$cache = cache_get("plugins:$module:$type", $info[$module][$type]['cache table']);
- // if cache load successful, set $all_hooks and $all_files to true.
if (!empty($cache->data)) {
+ // Cache load succeeded so use the cached plugin list.
$plugins[$module][$type] = $cache->data;
- $all_hooks[$module][$type] = TRUE;
- $all_files[$module][$type] = TRUE;
+ // Set $setup to true so we know things where loaded.
+ $setup[$module][$type] = TRUE;
}
else {
- $write_cache = TRUE;
+ // Cache load failed so store that we need to build and write the cache.
+ $build_cache = TRUE;
}
}
- // Always load all hooks if we need them.
- if (!isset($all_hooks[$module][$type])) {
- $all_hooks[$module][$type] = TRUE;
+ // Always load all hooks if we need them. Note we only need them now if the
+ // plugin asks for them. We can assume that if we have plugins we've already
+ // called the global hook.
+ if (!empty($info[$module][$type]['use hooks']) && empty($plugins[$module][$type])) {
$plugins[$module][$type] = ctools_plugin_load_hooks($info[$module][$type]);
}
- // First, see if it's in our hooks before we even bother.
- if ($id && array_key_exists($id, $plugins[$module][$type])) {
- return $plugins[$module][$type][$id];
- }
-
// Then see if we should load all files. We only do this if we
- // want a list of all plugins.
- if ((!$id || $info[$module][$type]['cache']) && empty($all_files[$module][$type])) {
- $all_files[$module][$type] = TRUE;
+ // want a list of all plugins or there was a cache miss.
+ if (empty($setup[$module][$type]) && ($build_cache || !$id)) {
+ $setup[$module][$type] = TRUE;
$plugins[$module][$type] = array_merge($plugins[$module][$type], ctools_plugin_load_includes($info[$module][$type]));
}
// If we were told earlier that this is cacheable and the cache was
// empty, give something back.
- if (!empty($write_cache)) {
+ if ($build_cache) {
cache_set("plugins:$module:$type", $plugins[$module][$type], $info[$module][$type]['cache table']);
}
@@ -559,6 +556,7 @@ function ctools_plugin_get_info($module,
'type' => $type,
'cache' => FALSE,
'cache table' => 'cache',
+ 'use hooks' => FALSE,
'defaults' => array(),
'hook' => $module . '_' . $type,
'load themes' => FALSE,