registry.inc 3.0 KB

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