annotate sites/all/modules/ctools/ctools.api.php @ 0:ff03f76ab3fe

initial version
author danieleb <danielebarchiesi@me.com>
date Wed, 21 Aug 2013 18:51:11 +0100
parents
children
rev   line source
danielebarchiesi@0 1 <?php
danielebarchiesi@0 2
danielebarchiesi@0 3 /**
danielebarchiesi@0 4 * @file
danielebarchiesi@0 5 * Hooks provided by the Chaos Tool Suite.
danielebarchiesi@0 6 *
danielebarchiesi@0 7 * This file is divided into static hooks (hooks with string literal names) and
danielebarchiesi@0 8 * dynamic hooks (hooks with pattern-derived string names).
danielebarchiesi@0 9 */
danielebarchiesi@0 10
danielebarchiesi@0 11 /**
danielebarchiesi@0 12 * @addtogroup hooks
danielebarchiesi@0 13 * @{
danielebarchiesi@0 14 */
danielebarchiesi@0 15
danielebarchiesi@0 16 /**
danielebarchiesi@0 17 * Inform CTools about plugin types.
danielebarchiesi@0 18 *
danielebarchiesi@0 19 * @return array
danielebarchiesi@0 20 * An array of plugin types, keyed by the type name.
danielebarchiesi@0 21 * See the advanced help topic 'plugins-creating' for details of the array
danielebarchiesi@0 22 * properties.
danielebarchiesi@0 23 */
danielebarchiesi@0 24 function hook_ctools_plugin_type() {
danielebarchiesi@0 25 $plugins['my_type'] = array(
danielebarchiesi@0 26 'load themes' => TRUE,
danielebarchiesi@0 27 );
danielebarchiesi@0 28
danielebarchiesi@0 29 return $plugins;
danielebarchiesi@0 30 }
danielebarchiesi@0 31
danielebarchiesi@0 32 /**
danielebarchiesi@0 33 * This hook is used to inform the CTools plugin system about the location of a
danielebarchiesi@0 34 * directory that should be searched for files containing plugins of a
danielebarchiesi@0 35 * particular type. CTools invokes this same hook for all plugins, using the
danielebarchiesi@0 36 * two passed parameters to indicate the specific type of plugin for which it
danielebarchiesi@0 37 * is searching.
danielebarchiesi@0 38 *
danielebarchiesi@0 39 * The $plugin_type parameter is self-explanatory - it is the string name of the
danielebarchiesi@0 40 * plugin type (e.g., Panels' 'layouts' or 'styles'). The $owner parameter is
danielebarchiesi@0 41 * necessary because CTools internally namespaces plugins by the module that
danielebarchiesi@0 42 * owns them. This is an extension of Drupal best practices on avoiding global
danielebarchiesi@0 43 * namespace pollution by prepending your module name to all its functions.
danielebarchiesi@0 44 * Consequently, it is possible for two different modules to create a plugin
danielebarchiesi@0 45 * type with exactly the same name and have them operate in harmony. In fact,
danielebarchiesi@0 46 * this system renders it impossible for modules to encroach on other modules'
danielebarchiesi@0 47 * plugin namespaces.
danielebarchiesi@0 48 *
danielebarchiesi@0 49 * Given this namespacing, it is important that implementations of this hook
danielebarchiesi@0 50 * check BOTH the $owner and $plugin_type parameters before returning a path.
danielebarchiesi@0 51 * If your module does not implement plugins for the requested module/plugin
danielebarchiesi@0 52 * combination, it is safe to return nothing at all (or NULL). As a convenience,
danielebarchiesi@0 53 * it is also safe to return a path that does not exist for plugins your module
danielebarchiesi@0 54 * does not implement - see form 2 for a use case.
danielebarchiesi@0 55 *
danielebarchiesi@0 56 * Note that modules implementing a plugin also must implement this hook to
danielebarchiesi@0 57 * instruct CTools as to the location of the plugins. See form 3 for a use case.
danielebarchiesi@0 58 *
danielebarchiesi@0 59 * The conventional structure to return is "plugins/$plugin_type" - that is, a
danielebarchiesi@0 60 * 'plugins' subdirectory in your main module directory, with individual
danielebarchiesi@0 61 * directories contained therein named for the plugin type they contain.
danielebarchiesi@0 62 *
danielebarchiesi@0 63 * @param string $owner
danielebarchiesi@0 64 * The system name of the module owning the plugin type for which a base
danielebarchiesi@0 65 * directory location is being requested.
danielebarchiesi@0 66 * @param string $plugin_type
danielebarchiesi@0 67 * The name of the plugin type for which a base directory is being requested.
danielebarchiesi@0 68 * @return string
danielebarchiesi@0 69 * The path where CTools' plugin system should search for plugin files,
danielebarchiesi@0 70 * relative to your module's root. Omit leading and trailing slashes.
danielebarchiesi@0 71 */
danielebarchiesi@0 72 function hook_ctools_plugin_directory($owner, $plugin_type) {
danielebarchiesi@0 73 // Form 1 - for a module implementing only the 'content_types' plugin owned
danielebarchiesi@0 74 // by CTools, this would cause the plugin system to search the
danielebarchiesi@0 75 // <moduleroot>/plugins/content_types directory for .inc plugin files.
danielebarchiesi@0 76 if ($owner == 'ctools' && $plugin_type == 'content_types') {
danielebarchiesi@0 77 return 'plugins/content_types';
danielebarchiesi@0 78 }
danielebarchiesi@0 79
danielebarchiesi@0 80 // Form 2 - if your module implements only Panels plugins, and has 'layouts'
danielebarchiesi@0 81 // and 'styles' plugins but no 'cache' or 'display_renderers', it is OK to be
danielebarchiesi@0 82 // lazy and return a directory for a plugin you don't actually implement (so
danielebarchiesi@0 83 // long as that directory doesn't exist). This lets you avoid ugly in_array()
danielebarchiesi@0 84 // logic in your conditional, and also makes it easy to add plugins of those
danielebarchiesi@0 85 // types later without having to change this hook implementation.
danielebarchiesi@0 86 if ($owner == 'panels') {
danielebarchiesi@0 87 return "plugins/$plugin_type";
danielebarchiesi@0 88 }
danielebarchiesi@0 89
danielebarchiesi@0 90 // Form 3 - CTools makes no assumptions about where your plugins are located,
danielebarchiesi@0 91 // so you still have to implement this hook even for plugins created by your
danielebarchiesi@0 92 // own module.
danielebarchiesi@0 93 if ($owner == 'mymodule') {
danielebarchiesi@0 94 // Yes, this is exactly like Form 2 - just a different reasoning for it.
danielebarchiesi@0 95 return "plugins/$plugin_type";
danielebarchiesi@0 96 }
danielebarchiesi@0 97 // Finally, if nothing matches, it's safe to return nothing at all (or NULL).
danielebarchiesi@0 98 }
danielebarchiesi@0 99
danielebarchiesi@0 100 /**
danielebarchiesi@0 101 * Alter a plugin before it has been processed.
danielebarchiesi@0 102 *
danielebarchiesi@0 103 * This hook is useful for altering flags or other information that will be
danielebarchiesi@0 104 * used or possibly overriden by the process hook if defined.
danielebarchiesi@0 105 *
danielebarchiesi@0 106 * @param $plugin
danielebarchiesi@0 107 * An associative array defining a plugin.
danielebarchiesi@0 108 * @param $info
danielebarchiesi@0 109 * An associative array of plugin type info.
danielebarchiesi@0 110 */
danielebarchiesi@0 111 function hook_ctools_plugin_pre_alter(&$plugin, &$info) {
danielebarchiesi@0 112 // Override a function defined by the plugin.
danielebarchiesi@0 113 if ($info['type'] == 'my_type') {
danielebarchiesi@0 114 $plugin['my_flag'] = 'new_value';
danielebarchiesi@0 115 }
danielebarchiesi@0 116 }
danielebarchiesi@0 117
danielebarchiesi@0 118 /**
danielebarchiesi@0 119 * Alter a plugin after it has been processed.
danielebarchiesi@0 120 *
danielebarchiesi@0 121 * This hook is useful for overriding the final values for a plugin after it
danielebarchiesi@0 122 * has been processed.
danielebarchiesi@0 123 *
danielebarchiesi@0 124 * @param $plugin
danielebarchiesi@0 125 * An associative array defining a plugin.
danielebarchiesi@0 126 * @param $info
danielebarchiesi@0 127 * An associative array of plugin type info.
danielebarchiesi@0 128 */
danielebarchiesi@0 129 function hook_ctools_plugin_post_alter(&$plugin, &$info) {
danielebarchiesi@0 130 // Override a function defined by the plugin.
danielebarchiesi@0 131 if ($info['type'] == 'my_type') {
danielebarchiesi@0 132 $plugin['my_function'] = 'new_function';
danielebarchiesi@0 133 }
danielebarchiesi@0 134 }
danielebarchiesi@0 135
danielebarchiesi@0 136 /**
danielebarchiesi@0 137 * Alter the list of modules/themes which implement a certain api.
danielebarchiesi@0 138 *
danielebarchiesi@0 139 * The hook named here is just an example, as the real existing hooks are named
danielebarchiesi@0 140 * for example 'hook_views_api_alter'.
danielebarchiesi@0 141 *
danielebarchiesi@0 142 * @param array $list
danielebarchiesi@0 143 * An array of informations about the implementors of a certain api.
danielebarchiesi@0 144 * The key of this array are the module names/theme names.
danielebarchiesi@0 145 */
danielebarchiesi@0 146 function hook_ctools_api_hook_alter(&$list) {
danielebarchiesi@0 147 // Alter the path of the node implementation.
danielebarchiesi@0 148 $list['node']['path'] = drupal_get_path('module', 'node');
danielebarchiesi@0 149 }
danielebarchiesi@0 150
danielebarchiesi@0 151 /**
danielebarchiesi@0 152 * Alter the available functions to be used in ctools math expression api.
danielebarchiesi@0 153 *
danielebarchiesi@0 154 * One usecase would be to create your own function in your module and
danielebarchiesi@0 155 * allow to use it in the math expression api.
danielebarchiesi@0 156 *
danielebarchiesi@0 157 * @param $functions
danielebarchiesi@0 158 * An array which has the functions as value.
danielebarchiesi@0 159 */
danielebarchiesi@0 160 function hook_ctools_math_expression_functions_alter(&$functions) {
danielebarchiesi@0 161 // Allow to convert from degrees to radiant.
danielebarchiesi@0 162 $functions[] = 'deg2rad';
danielebarchiesi@0 163 }
danielebarchiesi@0 164
danielebarchiesi@0 165 /**
danielebarchiesi@0 166 * Alter everything.
danielebarchiesi@0 167 *
danielebarchiesi@0 168 * @param $info
danielebarchiesi@0 169 * An associative array containing the following keys:
danielebarchiesi@0 170 * - content: The rendered content.
danielebarchiesi@0 171 * - title: The content's title.
danielebarchiesi@0 172 * - no_blocks: A boolean to decide if blocks should be displayed.
danielebarchiesi@0 173 * @param $page
danielebarchiesi@0 174 * If TRUE then this renderer owns the page and can use theme('page')
danielebarchiesi@0 175 * for no blocks; if false, output is returned regardless of any no
danielebarchiesi@0 176 * blocks settings.
danielebarchiesi@0 177 * @param $context
danielebarchiesi@0 178 * An associative array containing the following keys:
danielebarchiesi@0 179 * - args: The raw arguments behind the contexts.
danielebarchiesi@0 180 * - contexts: The context objects in use.
danielebarchiesi@0 181 * - task: The task object in use.
danielebarchiesi@0 182 * - subtask: The subtask object in use.
danielebarchiesi@0 183 * - handler: The handler object in use.
danielebarchiesi@0 184 */
danielebarchiesi@0 185 function hook_ctools_render_alter(&$info, &$page, &$context) {
danielebarchiesi@0 186 if ($context['handler']->name == 'my_handler') {
danielebarchiesi@0 187 ctools_add_css('my_module.theme', 'my_module');
danielebarchiesi@0 188 }
danielebarchiesi@0 189 }
danielebarchiesi@0 190
danielebarchiesi@0 191 /**
danielebarchiesi@0 192 * Alter a content plugin subtype.
danielebarchiesi@0 193 *
danielebarchiesi@0 194 * While content types can be altered via hook_ctools_plugin_pre_alter() or
danielebarchiesi@0 195 * hook_ctools_plugin_post_alter(), the subtypes that content types rely on
danielebarchiesi@0 196 * are special and require their own hook.
danielebarchiesi@0 197 *
danielebarchiesi@0 198 * This hook can be used to add things like 'render last' or change icons
danielebarchiesi@0 199 * or categories or to rename content on specific sites.
danielebarchiesi@0 200 */
danielebarchiesi@0 201 function hook_ctools_content_subtype_alter($subtype, $plugin) {
danielebarchiesi@0 202 $subtype['render last'] = TRUE;
danielebarchiesi@0 203 }
danielebarchiesi@0 204
danielebarchiesi@0 205 /**
danielebarchiesi@0 206 * Alter the definition of an entity context plugin.
danielebarchiesi@0 207 *
danielebarchiesi@0 208 * @param array $plugin
danielebarchiesi@0 209 * An associative array defining a plugin.
danielebarchiesi@0 210 * @param array $entity
danielebarchiesi@0 211 * The entity info array of a specific entity type.
danielebarchiesi@0 212 * @param string $plugin_id
danielebarchiesi@0 213 * The plugin ID, in the format NAME:KEY.
danielebarchiesi@0 214 */
danielebarchiesi@0 215 function hook_ctools_entity_context_alter(&$plugin, &$entity, $plugin_id) {
danielebarchiesi@0 216 ctools_include('context');
danielebarchiesi@0 217 switch ($plugin_id) {
danielebarchiesi@0 218 case 'entity_id:taxonomy_term':
danielebarchiesi@0 219 $plugin['no ui'] = TRUE;
danielebarchiesi@0 220 case 'entity:user':
danielebarchiesi@0 221 $plugin = ctools_get_context('user');
danielebarchiesi@0 222 unset($plugin['no ui']);
danielebarchiesi@0 223 unset($plugin['no required context ui']);
danielebarchiesi@0 224 break;
danielebarchiesi@0 225 }
danielebarchiesi@0 226 }
danielebarchiesi@0 227
danielebarchiesi@0 228 /**
danielebarchiesi@0 229 * Alter the definition of entity context plugins.
danielebarchiesi@0 230 *
danielebarchiesi@0 231 * @param array $plugins
danielebarchiesi@0 232 * An associative array of plugin definitions, keyed by plugin ID.
danielebarchiesi@0 233 *
danielebarchiesi@0 234 * @see hook_ctools_entity_context_alter()
danielebarchiesi@0 235 */
danielebarchiesi@0 236 function hook_ctools_entity_contexts_alter(&$plugins) {
danielebarchiesi@0 237 $plugins['entity_id:taxonomy_term']['no ui'] = TRUE;
danielebarchiesi@0 238 }
danielebarchiesi@0 239
danielebarchiesi@0 240 /**
danielebarchiesi@0 241 * Change cleanstring settings.
danielebarchiesi@0 242 *
danielebarchiesi@0 243 * @param array $settings
danielebarchiesi@0 244 * An associative array of cleanstring settings.
danielebarchiesi@0 245 *
danielebarchiesi@0 246 * @see ctools_cleanstring()
danielebarchiesi@0 247 */
danielebarchiesi@0 248 function hook_ctools_cleanstring_alter(&$settings) {
danielebarchiesi@0 249 // Convert all strings to lower case.
danielebarchiesi@0 250 $settings['lower case'] = TRUE;
danielebarchiesi@0 251 }
danielebarchiesi@0 252
danielebarchiesi@0 253 /**
danielebarchiesi@0 254 * Change cleanstring settings for a specific clean ID.
danielebarchiesi@0 255 *
danielebarchiesi@0 256 * @param array $settings
danielebarchiesi@0 257 * An associative array of cleanstring settings.
danielebarchiesi@0 258 *
danielebarchiesi@0 259 * @see ctools_cleanstring()
danielebarchiesi@0 260 */
danielebarchiesi@0 261 function hook_ctools_cleanstring_CLEAN_ID_alter(&$settings) {
danielebarchiesi@0 262 // Convert all strings to lower case.
danielebarchiesi@0 263 $settings['lower case'] = TRUE;
danielebarchiesi@0 264 }
danielebarchiesi@0 265
danielebarchiesi@0 266 /**
danielebarchiesi@0 267 * @} End of "addtogroup hooks".
danielebarchiesi@0 268 */