utility.inc 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * @file
  4. * Contains general utility functions for CTools that do not need to be
  5. * in the module file.
  6. *
  7. * In particular, things that are only needed during hook_menu() and
  8. * hook_theme() are placed here.
  9. */
  10. /**
  11. * Provide a hook passthrough to included files.
  12. *
  13. * To organize things neatly, each CTools tool gets its own toolname.$type.inc
  14. * file. If it exists, it's loaded and ctools_$tool_$type() is executed.
  15. * To save time we pass the $items array in so we don't need to do array
  16. * addition. It modifies the array by reference and doesn't need to return it.
  17. */
  18. function ctools_passthrough($module, $type, &$items) {
  19. $files = file_scan_directory(drupal_get_path('module', $module) . '/includes', '/\.' . $type . '\.inc$/', array('key' => 'name'));
  20. foreach ($files as $file) {
  21. require_once DRUPAL_ROOT . '/' . $file->uri;
  22. list($tool) = explode('.', $file->name, 2);
  23. $function = $module . '_' . str_replace ('-', '_', $tool) . '_' . str_replace('-', '_', $type);
  24. if (function_exists($function)) {
  25. $function($items);
  26. }
  27. }
  28. }