registry.inc 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @file
  4. * Registry magic. In a separate file to minimize unnecessary code loading.
  5. */
  6. /**
  7. * Implements (via delegation) hook_registry_files_alter().
  8. *
  9. * Alter the registry of files to automagically include all classes in
  10. * class-based plugins.
  11. */
  12. function _ctools_registry_files_alter(&$files, $indexed_modules) {
  13. ctools_include('plugins');
  14. // Remap the passed indexed modules into a useful format.
  15. $modules = array();
  16. foreach ($indexed_modules as $module_object) {
  17. $modules[$module_object->name] = $module_object;
  18. }
  19. $all_type_info = ctools_plugin_get_plugin_type_info(TRUE);
  20. foreach ($all_type_info as $module => $plugin_types) {
  21. foreach ($plugin_types as $plugin_type_name => $plugin_type_info) {
  22. if (empty($plugin_type_info['classes'])) {
  23. // This plugin type does not use classes, so skip it.
  24. continue;
  25. }
  26. // Retrieve the full list of plugins of this type.
  27. $plugins = ctools_get_plugins($module, $plugin_type_name);
  28. foreach ($plugins as $plugin_name => $plugin_definition) {
  29. foreach ($plugin_type_info['classes'] as $class_key) {
  30. if (empty($plugin_definition[$class_key])) {
  31. // Plugin doesn't provide a class for this class key, so skip it.
  32. continue;
  33. }
  34. if (is_string($plugin_definition[$class_key])) {
  35. // Plugin definition uses the shorthand for defining a class name
  36. // and location; look for the containing file by following naming
  37. // convention.
  38. $path = $plugin_definition['path'] . '/' . $plugin_definition[$class_key] . '.class.php';
  39. }
  40. else {
  41. // Plugin uses the verbose definition to indicate where its class
  42. // files are.
  43. $class = $plugin_definition[$class_key]['class'];
  44. // Use the filename if it's explicitly set, else follow the naming
  45. // conventions.
  46. $filename = isset($plugin_definition[$class_key]['file']) ? $plugin_definition[$class_key]['file'] : $class . '.class.php';
  47. $base_path = isset($plugin_definition[$class_key]['path']) ? $plugin_definition[$class_key]['path'] : $plugin_definition['path'];
  48. $path = "$base_path/$filename";
  49. }
  50. if (file_exists($path)) {
  51. // If the file exists, add it to the files for registry building.
  52. $files[$path] = array('module' => $plugin_definition['module'], 'weight' => $modules[$plugin_definition['module']]->weight);
  53. }
  54. else {
  55. // Else, watchdog that we've got some erroneous plugin info.
  56. $args = array(
  57. '@plugin' => $plugin_definition['name'],
  58. '@owner' => $module,
  59. '@type' => $plugin_type_name,
  60. '@file' => $path,
  61. '@class' => $class_key,
  62. );
  63. watchdog('ctools', 'Plugin @plugin of plugin type @owner:@type points to nonexistent file @file for class handler @class.', $args);
  64. }
  65. }
  66. }
  67. }
  68. }
  69. }