diff --git includes/plugins.inc includes/plugins.inc index 751fd75..b57767e 100644 --- includes/plugins.inc +++ includes/plugins.inc @@ -128,14 +128,18 @@ function ctools_plugin_api_include($owner, $api, $minimum_version, $current_vers static $already_done = array(); $info = ctools_plugin_api_info($owner, $api, $minimum_version, $current_version); - foreach ($info as $module => $plugin_info) { - if (!isset($already_done[$owner][$api][$module])) { - $file = isset($plugin_info['file']) ? $plugin_info['file'] : "$module.$api.inc"; - if (file_exists("./$plugin_info[path]/$file")) { - require_once "./$plugin_info[path]/$file"; + if (!isset($already_done[$owner][$api])) { + foreach ($info as $module => $plugin_info) { + if (!isset($plugin_info['file'])) { + $plugin_info['file'] = "$module.$api.inc"; } - $already_done[$owner][$api][$module] = TRUE; + if (file_exists("./$plugin_info[path]/$plugin_info[file]")) { + $plugin_info[$module]['included'] = TRUE; + require_once "./$plugin_info[path]/$plugin_info[file]"; + } + $info[$module] = $plugin_info; } + $already_done[$owner][$api] = TRUE; } return $info; @@ -293,6 +297,9 @@ function ctools_plugin_load_includes($info, $filename = NULL) { // Keep a static array so we don't hit drupal_system_listing more than necessary. $all_files = &ctools_static(__FUNCTION__, array()); + // store static of plugin arrays for reference because they can't be reincluded. + static $plugin_arrays = array(); + // If we're being asked for all plugins of a type, skip any caching // we may have done because this is an admin task and it's ok to // spend the extra time. @@ -341,16 +348,29 @@ function ctools_plugin_load_includes($info, $filename = NULL) { else { // Parse a hook. $plugin = NULL; // ensure that we don't have something leftover from earlier. - include_once './' . $file->filename; - // .inc files have a special format for the hook identifier. - // For example, 'foo.inc' in the module 'mogul' using the plugin - // whose hook is named 'borg_type' should have a function named (deep breath) - // mogul_foo_borg_type() - - // If, however, the .inc file set the quasi-global $plugin array, we - // can use that and not even call a function. Set the $identifier - // appropriately and ctools_plugin_process() will handle it. - $identifier = isset($plugin) ? $plugin : $module . '_' . $file->name; + + if (isset($plugin_arrays[$file->filename])) { + $identifier = $plugin_arrays[$file->filename]; + } + else { + + require_once './' . $file->filename; + // .inc files have a special format for the hook identifier. + // For example, 'foo.inc' in the module 'mogul' using the plugin + // whose hook is named 'borg_type' should have a function named (deep breath) + // mogul_foo_borg_type() + + // If, however, the .inc file set the quasi-global $plugin array, we + // can use that and not even call a function. Set the $identifier + // appropriately and ctools_plugin_process() will handle it. + if (isset($plugin)) { + $plugin_arrays[$file->filename] = $plugin; + $identifier = $plugin; + } + else { + $identifier = $module . '_' . $file->name; + } + } $result = ctools_plugin_process($info, $module, $identifier, dirname($file->filename), basename($file->filename), $file->name); } if (is_array($result)) {