Projet

Général

Profil

Paste
Télécharger (3 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / ctools / includes / registry.inc @ a5572547

1
<?php
2

    
3
/**
4
 * @file
5
 *
6
 * Registry magic. In a separate file to minimize unnecessary code loading.
7
 */
8

    
9
/**
10
 * Implements (via delegation) hook_registry_files_alter().
11
 *
12
 * Alter the registry of files to automagically include all classes in
13
 * class-based plugins.
14
 */
15
function _ctools_registry_files_alter(&$files, $indexed_modules) {
16
  ctools_include('plugins');
17

    
18
  // Remap the passed indexed modules into a useful format.
19
  $modules = array();
20
  foreach ($indexed_modules as $module_object) {
21
    $modules[$module_object->name] = $module_object;
22
  }
23

    
24
  $all_type_info = ctools_plugin_get_plugin_type_info(TRUE);
25
  foreach ($all_type_info as $module => $plugin_types) {
26
    foreach ($plugin_types as $plugin_type_name => $plugin_type_info) {
27
      if (empty($plugin_type_info['classes'])) {
28
        // This plugin type does not use classes, so skip it.
29
        continue;
30
      }
31

    
32
      // Retrieve the full list of plugins of this type.
33
      $plugins = ctools_get_plugins($module, $plugin_type_name);
34
      foreach ($plugins as $plugin_name => $plugin_definition) {
35
        foreach ($plugin_type_info['classes'] as $class_key) {
36
          if (empty($plugin_definition[$class_key])) {
37
            // Plugin doesn't provide a class for this class key, so skip it.
38
            continue;
39
          }
40

    
41
          if (is_string($plugin_definition[$class_key])) {
42
            // Plugin definition uses the shorthand for defining a class name
43
            // and location; look for the containing file by following naming
44
            // convention.
45
            $path = $plugin_definition['path'] . '/' . $plugin_definition[$class_key] . '.class.php';
46
          }
47
          else {
48
            // Plugin uses the verbose definition to indicate where its class
49
            // files are.
50
            $class = $plugin_definition[$class_key]['class'];
51
            // Use the filename if it's explicitly set, else follow the naming
52
            // conventions.
53
            $filename = isset($plugin_definition[$class_key]['file']) ? $plugin_definition[$class_key]['file'] : $class . '.class.php';
54
            $base_path = isset($plugin_definition[$class_key]['path']) ? $plugin_definition[$class_key]['path'] : $plugin_definition['path'];
55
            $path = "$base_path/$filename";
56
          }
57

    
58
          if (file_exists($path)) {
59
            // If the file exists, add it to the files for registry building.
60
            $files[$path] = array('module' => $plugin_definition['module'], 'weight' => $modules[$plugin_definition['module']]->weight);
61
          }
62
          else {
63
            // Else, watchdog that we've got some erroneous plugin info.
64
            $args = array(
65
              '@plugin' => $plugin_definition['name'],
66
              '@owner' => $module,
67
              '@type' => $plugin_type_name,
68
              '@file' => $path,
69
              '@class' => $class_key,
70
            );
71
            watchdog('ctools', 'Plugin @plugin of plugin type @owner:@type points to nonexistent file @file for class handler @class.', $args);
72
          }
73
        }
74
      }
75
    }
76
  }
77
}