Projet

Général

Profil

Paste
Télécharger (9,04 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / ctools.api.php @ 1e39edcb

1
<?php
2

    
3
/**
4
 * @file
5
 * Hooks provided by the Chaos Tool Suite.
6
 *
7
 * This file is divided into static hooks (hooks with string literal names) and
8
 * dynamic hooks (hooks with pattern-derived string names).
9
 */
10

    
11
/**
12
 * @addtogroup hooks
13
 * @{
14
 */
15

    
16
/**
17
 * Inform CTools about plugin types.
18
 *
19
 * @return array
20
 *  An array of plugin types, keyed by the type name.
21
 *  See the advanced help topic 'plugins-creating' for details of the array
22
 *  properties.
23
 */
24
function hook_ctools_plugin_type() {
25
  $plugins['my_type'] = array(
26
    'load themes' => TRUE,
27
  );
28

    
29
  return $plugins;
30
}
31

    
32
/**
33
 * This hook is used to inform the CTools plugin system about the location of a
34
 * directory that should be searched for files containing plugins of a
35
 * particular type. CTools invokes this same hook for all plugins, using the
36
 * two passed parameters to indicate the specific type of plugin for which it
37
 * is searching.
38
 *
39
 * The $plugin_type parameter is self-explanatory - it is the string name of the
40
 * plugin type (e.g., Panels' 'layouts' or 'styles'). The $owner parameter is
41
 * necessary because CTools internally namespaces plugins by the module that
42
 * owns them. This is an extension of Drupal best practices on avoiding global
43
 * namespace pollution by prepending your module name to all its functions.
44
 * Consequently, it is possible for two different modules to create a plugin
45
 * type with exactly the same name and have them operate in harmony. In fact,
46
 * this system renders it impossible for modules to encroach on other modules'
47
 * plugin namespaces.
48
 *
49
 * Given this namespacing, it is important that implementations of this hook
50
 * check BOTH the $owner and $plugin_type parameters before returning a path.
51
 * If your module does not implement plugins for the requested module/plugin
52
 * combination, it is safe to return nothing at all (or NULL). As a convenience,
53
 * it is also safe to return a path that does not exist for plugins your module
54
 * does not implement - see form 2 for a use case.
55
 *
56
 * Note that modules implementing a plugin also must implement this hook to
57
 * instruct CTools as to the location of the plugins. See form 3 for a use case.
58
 *
59
 * The conventional structure to return is "plugins/$plugin_type" - that is, a
60
 * 'plugins' subdirectory in your main module directory, with individual
61
 * directories contained therein named for the plugin type they contain.
62
 *
63
 * @param string $owner
64
 *   The system name of the module owning the plugin type for which a base
65
 *   directory location is being requested.
66
 * @param string $plugin_type
67
 *   The name of the plugin type for which a base directory is being requested.
68
 * @return string
69
 *   The path where CTools' plugin system should search for plugin files,
70
 *   relative to your module's root. Omit leading and trailing slashes.
71
 */
72
function hook_ctools_plugin_directory($owner, $plugin_type) {
73
  // Form 1 - for a module implementing only the 'content_types' plugin owned
74
  // by CTools, this would cause the plugin system to search the
75
  // <moduleroot>/plugins/content_types directory for .inc plugin files.
76
  if ($owner == 'ctools' && $plugin_type == 'content_types') {
77
    return 'plugins/content_types';
78
  }
79

    
80
  // Form 2 - if your module implements only Panels plugins, and has 'layouts'
81
  // and 'styles' plugins but no 'cache' or 'display_renderers', it is OK to be
82
  // lazy and return a directory for a plugin you don't actually implement (so
83
  // long as that directory doesn't exist). This lets you avoid ugly in_array()
84
  // logic in your conditional, and also makes it easy to add plugins of those
85
  // types later without having to change this hook implementation.
86
  if ($owner == 'panels') {
87
    return "plugins/$plugin_type";
88
  }
89

    
90
  // Form 3 - CTools makes no assumptions about where your plugins are located,
91
  // so you still have to implement this hook even for plugins created by your
92
  // own module.
93
  if ($owner == 'mymodule') {
94
    // Yes, this is exactly like Form 2 - just a different reasoning for it.
95
    return "plugins/$plugin_type";
96
  }
97
  // Finally, if nothing matches, it's safe to return nothing at all (or NULL).
98
}
99

    
100
/**
101
 * Alter a plugin before it has been processed.
102
 *
103
 * This hook is useful for altering flags or other information that will be
104
 * used or possibly overriden by the process hook if defined.
105
 *
106
 * @param $plugin
107
 *   An associative array defining a plugin.
108
 * @param $info
109
 *   An associative array of plugin type info.
110
 */
111
function hook_ctools_plugin_pre_alter(&$plugin, &$info) {
112
  // Override a function defined by the plugin.
113
  if ($info['type'] == 'my_type') {
114
    $plugin['my_flag'] = 'new_value';
115
  }
116
}
117

    
118
/**
119
 * Alter a plugin after it has been processed.
120
 *
121
 * This hook is useful for overriding the final values for a plugin after it
122
 * has been processed.
123
 *
124
 * @param $plugin
125
 *   An associative array defining a plugin.
126
 * @param $info
127
 *   An associative array of plugin type info.
128
 */
129
function hook_ctools_plugin_post_alter(&$plugin, &$info) {
130
  // Override a function defined by the plugin.
131
  if ($info['type'] == 'my_type') {
132
    $plugin['my_function'] = 'new_function';
133
  }
134
}
135

    
136
/**
137
 * Alter the list of modules/themes which implement a certain api.
138
 *
139
 * The hook named here is just an example, as the real existing hooks are named
140
 * for example 'hook_views_api_alter'.
141
 *
142
 * @param array $list
143
 *   An array of informations about the implementors of a certain api.
144
 *   The key of this array are the module names/theme names.
145
 */
146
function hook_ctools_api_hook_alter(&$list) {
147
  // Alter the path of the node implementation.
148
  $list['node']['path'] = drupal_get_path('module', 'node');
149
}
150

    
151
/**
152
 * Alter the available functions to be used in ctools math expression api.
153
 *
154
 * One usecase would be to create your own function in your module and
155
 * allow to use it in the math expression api.
156
 *
157
 * @param $functions
158
 *    An array which has the functions as value.
159
 */
160
function hook_ctools_math_expression_functions_alter(&$functions) {
161
  // Allow to convert from degrees to radiant.
162
  $functions[] = 'deg2rad';
163
}
164

    
165
/**
166
 * Alter everything.
167
 *
168
 * @param $info
169
 *   An associative array containing the following keys:
170
 *   - content: The rendered content.
171
 *   - title: The content's title.
172
 *   - no_blocks: A boolean to decide if blocks should be displayed.
173
 * @param $page
174
 *   If TRUE then this renderer owns the page and can use theme('page')
175
 *   for no blocks; if false, output is returned regardless of any no
176
 *   blocks settings.
177
 * @param $context
178
 *   An associative array containing the following keys:
179
 *   - args: The raw arguments behind the contexts.
180
 *   - contexts: The context objects in use.
181
 *   - task: The task object in use.
182
 *   - subtask: The subtask object in use.
183
 *   - handler: The handler object in use.
184
 */
185
function hook_ctools_render_alter(&$info, &$page, &$context) {
186
  if ($context['handler']->name == 'my_handler') {
187
    ctools_add_css('my_module.theme', 'my_module');
188
  }
189
}
190

    
191
/**
192
 * Alter a content plugin subtype.
193
 *
194
 * While content types can be altered via hook_ctools_plugin_pre_alter() or
195
 * hook_ctools_plugin_post_alter(), the subtypes that content types rely on
196
 * are special and require their own hook.
197
 *
198
 * This hook can be used to add things like 'render last' or change icons
199
 * or categories or to rename content on specific sites.
200
 */
201
function hook_ctools_content_subtype_alter($subtype, $plugin) {
202
  // Force a particular subtype of a particular plugin to render last.
203
  if ($plugin['module'] == 'some_plugin_module' && $plugin['name'] == 'some_plugin_name' && $subtype['subtype_id'] == 'my_subtype_id') {
204
    $subtype['render last'] = TRUE;
205
  }
206
}
207

    
208
/**
209
 * Alter the definition of an entity context plugin.
210
 *
211
 * @param array $plugin
212
 *   An associative array defining a plugin.
213
 * @param array $entity
214
 *   The entity info array of a specific entity type.
215
 * @param string $plugin_id
216
 *   The plugin ID, in the format NAME:KEY.
217
 */
218
function hook_ctools_entity_context_alter(&$plugin, &$entity, $plugin_id) {
219
  ctools_include('context');
220
  switch ($plugin_id) {
221
    case 'entity_id:taxonomy_term':
222
      $plugin['no ui'] = TRUE;
223
    case 'entity:user':
224
      $plugin = ctools_get_context('user');
225
      unset($plugin['no ui']);
226
      unset($plugin['no required context ui']);
227
      break;
228
  }
229
}
230

    
231
/**
232
 * Alter the definition of entity context plugins.
233
 *
234
 * @param array $plugins
235
 *   An associative array of plugin definitions, keyed by plugin ID.
236
 *
237
 * @see hook_ctools_entity_context_alter()
238
 */
239
function hook_ctools_entity_contexts_alter(&$plugins) {
240
  $plugins['entity_id:taxonomy_term']['no ui'] = TRUE;
241
}
242

    
243
/**
244
 * Change cleanstring settings.
245
 *
246
 * @param array $settings
247
 *   An associative array of cleanstring settings.
248
 *
249
 * @see ctools_cleanstring()
250
 */
251
function hook_ctools_cleanstring_alter(&$settings) {
252
  // Convert all strings to lower case.
253
  $settings['lower case'] = TRUE;
254
}
255

    
256
/**
257
 * Change cleanstring settings for a specific clean ID.
258
 *
259
 * @param array $settings
260
 *   An associative array of cleanstring settings.
261
 *
262
 * @see ctools_cleanstring()
263
 */
264
function hook_ctools_cleanstring_CLEAN_ID_alter(&$settings) {
265
  // Convert all strings to lower case.
266
  $settings['lower case'] = TRUE;
267
}
268

    
269
/**
270
 * @} End of "addtogroup hooks".
271
 */