Projet

Général

Profil

Paste
Télécharger (2,99 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / includes / registry.inc @ 7e72b748

1
<?php
2

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

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

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

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

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

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

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