annotate modules/system/system.api.php @ 3:b28be78d8160

alpha1.0 version
author danieleb <danielebarchiesi@me.com>
date Thu, 19 Sep 2013 10:33:07 +0100
parents ff03f76ab3fe
children
rev   line source
danielebarchiesi@0 1 <?php
danielebarchiesi@0 2
danielebarchiesi@0 3 /**
danielebarchiesi@0 4 * @file
danielebarchiesi@0 5 * Hooks provided by Drupal core and the System module.
danielebarchiesi@0 6 */
danielebarchiesi@0 7
danielebarchiesi@0 8 /**
danielebarchiesi@0 9 * @addtogroup hooks
danielebarchiesi@0 10 * @{
danielebarchiesi@0 11 */
danielebarchiesi@0 12
danielebarchiesi@0 13 /**
danielebarchiesi@0 14 * Defines one or more hooks that are exposed by a module.
danielebarchiesi@0 15 *
danielebarchiesi@0 16 * Normally hooks do not need to be explicitly defined. However, by declaring a
danielebarchiesi@0 17 * hook explicitly, a module may define a "group" for it. Modules that implement
danielebarchiesi@0 18 * a hook may then place their implementation in either $module.module or in
danielebarchiesi@0 19 * $module.$group.inc. If the hook is located in $module.$group.inc, then that
danielebarchiesi@0 20 * file will be automatically loaded when needed.
danielebarchiesi@0 21 * In general, hooks that are rarely invoked and/or are very large should be
danielebarchiesi@0 22 * placed in a separate include file, while hooks that are very short or very
danielebarchiesi@0 23 * frequently called should be left in the main module file so that they are
danielebarchiesi@0 24 * always available.
danielebarchiesi@0 25 *
danielebarchiesi@0 26 * @return
danielebarchiesi@0 27 * An associative array whose keys are hook names and whose values are an
danielebarchiesi@0 28 * associative array containing:
danielebarchiesi@0 29 * - group: A string defining the group to which the hook belongs. The module
danielebarchiesi@0 30 * system will determine whether a file with the name $module.$group.inc
danielebarchiesi@0 31 * exists, and automatically load it when required.
danielebarchiesi@0 32 *
danielebarchiesi@0 33 * See system_hook_info() for all hook groups defined by Drupal core.
danielebarchiesi@0 34 *
danielebarchiesi@0 35 * @see hook_hook_info_alter().
danielebarchiesi@0 36 */
danielebarchiesi@0 37 function hook_hook_info() {
danielebarchiesi@0 38 $hooks['token_info'] = array(
danielebarchiesi@0 39 'group' => 'tokens',
danielebarchiesi@0 40 );
danielebarchiesi@0 41 $hooks['tokens'] = array(
danielebarchiesi@0 42 'group' => 'tokens',
danielebarchiesi@0 43 );
danielebarchiesi@0 44 return $hooks;
danielebarchiesi@0 45 }
danielebarchiesi@0 46
danielebarchiesi@0 47 /**
danielebarchiesi@0 48 * Alter information from hook_hook_info().
danielebarchiesi@0 49 *
danielebarchiesi@0 50 * @param $hooks
danielebarchiesi@0 51 * Information gathered by module_hook_info() from other modules'
danielebarchiesi@0 52 * implementations of hook_hook_info(). Alter this array directly.
danielebarchiesi@0 53 * See hook_hook_info() for information on what this may contain.
danielebarchiesi@0 54 */
danielebarchiesi@0 55 function hook_hook_info_alter(&$hooks) {
danielebarchiesi@0 56 // Our module wants to completely override the core tokens, so make
danielebarchiesi@0 57 // sure the core token hooks are not found.
danielebarchiesi@0 58 $hooks['token_info']['group'] = 'mytokens';
danielebarchiesi@0 59 $hooks['tokens']['group'] = 'mytokens';
danielebarchiesi@0 60 }
danielebarchiesi@0 61
danielebarchiesi@0 62 /**
danielebarchiesi@0 63 * Inform the base system and the Field API about one or more entity types.
danielebarchiesi@0 64 *
danielebarchiesi@0 65 * Inform the system about one or more entity types (i.e., object types that
danielebarchiesi@0 66 * can be loaded via entity_load() and, optionally, to which fields can be
danielebarchiesi@0 67 * attached).
danielebarchiesi@0 68 *
danielebarchiesi@0 69 * @return
danielebarchiesi@0 70 * An array whose keys are entity type names and whose values identify
danielebarchiesi@0 71 * properties of those types that the system needs to know about:
danielebarchiesi@0 72 * - label: The human-readable name of the type.
danielebarchiesi@0 73 * - controller class: The name of the class that is used to load the objects.
danielebarchiesi@0 74 * The class has to implement the DrupalEntityControllerInterface interface.
danielebarchiesi@0 75 * Leave blank to use the DrupalDefaultEntityController implementation.
danielebarchiesi@0 76 * - base table: (used by DrupalDefaultEntityController) The name of the
danielebarchiesi@0 77 * entity type's base table.
danielebarchiesi@0 78 * - revision table: The name of the entity type's revision table (if any).
danielebarchiesi@0 79 * - static cache: (used by DrupalDefaultEntityController) FALSE to disable
danielebarchiesi@0 80 * static caching of entities during a page request. Defaults to TRUE.
danielebarchiesi@0 81 * - field cache: (used by Field API loading and saving of field data) FALSE
danielebarchiesi@0 82 * to disable Field API's persistent cache of field data. Only recommended
danielebarchiesi@0 83 * if a higher level persistent cache is available for the entity type.
danielebarchiesi@0 84 * Defaults to TRUE.
danielebarchiesi@0 85 * - load hook: The name of the hook which should be invoked by
danielebarchiesi@0 86 * DrupalDefaultEntityController:attachLoad(), for example 'node_load'.
danielebarchiesi@0 87 * - uri callback: The name of an implementation of
danielebarchiesi@0 88 * callback_entity_info_uri().
danielebarchiesi@0 89 * - label callback: (optional) The name of an implementation of
danielebarchiesi@0 90 * callback_entity_info_label(), which returns the label of the entity. The
danielebarchiesi@0 91 * entity label is the main string associated with an entity; for example,
danielebarchiesi@0 92 * the title of a node or the subject of a comment. If there is an entity
danielebarchiesi@0 93 * object property that defines the label, then using the 'label' element of
danielebarchiesi@0 94 * the 'entity keys' return value component suffices to provide this
danielebarchiesi@0 95 * information (see below). Alternatively, specifying this callback allows
danielebarchiesi@0 96 * more complex logic to determine the label of an entity. See also the
danielebarchiesi@0 97 * entity_label() function, which implements this logic.
danielebarchiesi@0 98 * - language callback: (optional) The name of an implementation of
danielebarchiesi@0 99 * callback_entity_info_language(). In most situations, when needing to
danielebarchiesi@0 100 * determine this value, inspecting a property named after the 'language'
danielebarchiesi@0 101 * element of the 'entity keys' should be enough. The language callback is
danielebarchiesi@0 102 * meant to be used primarily for temporary alterations of the property
danielebarchiesi@0 103 * value: entity-defining modules are encouraged to always define a
danielebarchiesi@0 104 * language property, instead of using the callback as main entity language
danielebarchiesi@0 105 * source. In fact not having a language property defined is likely to
danielebarchiesi@0 106 * prevent an entity from being queried by language. Moreover, given that
danielebarchiesi@0 107 * entity_language() is not necessarily used everywhere it would be
danielebarchiesi@0 108 * appropriate, modules implementing the language callback should be aware
danielebarchiesi@0 109 * that this might not be always called.
danielebarchiesi@0 110 * - fieldable: Set to TRUE if you want your entity type to accept fields
danielebarchiesi@0 111 * being attached to it.
danielebarchiesi@0 112 * - translation: An associative array of modules registered as field
danielebarchiesi@0 113 * translation handlers. Array keys are the module names, array values
danielebarchiesi@0 114 * can be any data structure the module uses to provide field translation.
danielebarchiesi@0 115 * Any empty value disallows the module to appear as a translation handler.
danielebarchiesi@0 116 * - entity keys: An array describing how the Field API can extract the
danielebarchiesi@0 117 * information it needs from the objects of the type. Elements:
danielebarchiesi@0 118 * - id: The name of the property that contains the primary id of the
danielebarchiesi@0 119 * entity. Every entity object passed to the Field API must have this
danielebarchiesi@0 120 * property and its value must be numeric.
danielebarchiesi@0 121 * - revision: The name of the property that contains the revision id of
danielebarchiesi@0 122 * the entity. The Field API assumes that all revision ids are unique
danielebarchiesi@0 123 * across all entities of a type. This entry can be omitted if the
danielebarchiesi@0 124 * entities of this type are not versionable.
danielebarchiesi@0 125 * - bundle: The name of the property that contains the bundle name for the
danielebarchiesi@0 126 * entity. The bundle name defines which set of fields are attached to
danielebarchiesi@0 127 * the entity (e.g. what nodes call "content type"). This entry can be
danielebarchiesi@0 128 * omitted if this entity type exposes a single bundle (all entities have
danielebarchiesi@0 129 * the same collection of fields). The name of this single bundle will be
danielebarchiesi@0 130 * the same as the entity type.
danielebarchiesi@0 131 * - label: The name of the property that contains the entity label. For
danielebarchiesi@0 132 * example, if the entity's label is located in $entity->subject, then
danielebarchiesi@0 133 * 'subject' should be specified here. If complex logic is required to
danielebarchiesi@0 134 * build the label, a 'label callback' should be defined instead (see
danielebarchiesi@0 135 * the 'label callback' section above for details).
danielebarchiesi@0 136 * - language: The name of the property, typically 'language', that contains
danielebarchiesi@0 137 * the language code representing the language the entity has been created
danielebarchiesi@0 138 * in. This value may be changed when editing the entity and represents
danielebarchiesi@0 139 * the language its textual components are supposed to have. If no
danielebarchiesi@0 140 * language property is available, the 'language callback' may be used
danielebarchiesi@0 141 * instead. This entry can be omitted if the entities of this type are not
danielebarchiesi@0 142 * language-aware.
danielebarchiesi@0 143 * - bundle keys: An array describing how the Field API can extract the
danielebarchiesi@0 144 * information it needs from the bundle objects for this type. This entry
danielebarchiesi@0 145 * is required if the 'path' provided in the 'bundles'/'admin' section
danielebarchiesi@0 146 * identifies the bundle using a named menu placeholder whose loader
danielebarchiesi@0 147 * callback returns an object (e.g., $vocabulary for taxonomy terms, or
danielebarchiesi@0 148 * $node_type for nodes). If the path does not include the bundle, or the
danielebarchiesi@0 149 * bundle is just a string rather than an automatically loaded object, then
danielebarchiesi@0 150 * this can be omitted. Elements:
danielebarchiesi@0 151 * - bundle: The name of the property of the bundle object that contains
danielebarchiesi@0 152 * the name of the bundle object.
danielebarchiesi@0 153 * - bundles: An array describing all bundles for this object type. Keys are
danielebarchiesi@0 154 * bundles machine names, as found in the objects' 'bundle' property
danielebarchiesi@0 155 * (defined in the 'entity keys' entry above). This entry can be omitted if
danielebarchiesi@0 156 * this entity type exposes a single bundle (all entities have the same
danielebarchiesi@0 157 * collection of fields). The name of this single bundle will be the same as
danielebarchiesi@0 158 * the entity type. Elements:
danielebarchiesi@0 159 * - label: The human-readable name of the bundle.
danielebarchiesi@0 160 * - uri callback: Same as the 'uri callback' key documented above for the
danielebarchiesi@0 161 * entity type, but for the bundle only. When determining the URI of an
danielebarchiesi@0 162 * entity, if a 'uri callback' is defined for both the entity type and
danielebarchiesi@0 163 * the bundle, the one for the bundle is used.
danielebarchiesi@0 164 * - admin: An array of information that allows Field UI pages to attach
danielebarchiesi@0 165 * themselves to the existing administration pages for the bundle.
danielebarchiesi@0 166 * Elements:
danielebarchiesi@0 167 * - path: the path of the bundle's main administration page, as defined
danielebarchiesi@0 168 * in hook_menu(). If the path includes a placeholder for the bundle,
danielebarchiesi@0 169 * the 'bundle argument' and 'real path' keys below are required.
danielebarchiesi@0 170 * - bundle argument: The position of the bundle placeholder in 'path', if
danielebarchiesi@0 171 * any.
danielebarchiesi@0 172 * - real path: The actual path (no placeholder) of the bundle's main
danielebarchiesi@0 173 * administration page. This will be used to generate links.
danielebarchiesi@0 174 * - access callback: As in hook_menu(). 'user_access' will be assumed if
danielebarchiesi@0 175 * no value is provided.
danielebarchiesi@0 176 * - access arguments: As in hook_menu().
danielebarchiesi@0 177 * - view modes: An array describing the view modes for the entity type. View
danielebarchiesi@0 178 * modes let entities be displayed differently depending on the context.
danielebarchiesi@0 179 * For instance, a node can be displayed differently on its own page
danielebarchiesi@0 180 * ('full' mode), on the home page or taxonomy listings ('teaser' mode), or
danielebarchiesi@0 181 * in an RSS feed ('rss' mode). Modules taking part in the display of the
danielebarchiesi@0 182 * entity (notably the Field API) can adjust their behavior depending on
danielebarchiesi@0 183 * the requested view mode. An additional 'default' view mode is available
danielebarchiesi@0 184 * for all entity types. This view mode is not intended for actual entity
danielebarchiesi@0 185 * display, but holds default display settings. For each available view
danielebarchiesi@0 186 * mode, administrators can configure whether it should use its own set of
danielebarchiesi@0 187 * field display settings, or just replicate the settings of the 'default'
danielebarchiesi@0 188 * view mode, thus reducing the amount of display configurations to keep
danielebarchiesi@0 189 * track of. Keys of the array are view mode names. Each view mode is
danielebarchiesi@0 190 * described by an array with the following key/value pairs:
danielebarchiesi@0 191 * - label: The human-readable name of the view mode
danielebarchiesi@0 192 * - custom settings: A boolean specifying whether the view mode should by
danielebarchiesi@0 193 * default use its own custom field display settings. If FALSE, entities
danielebarchiesi@0 194 * displayed in this view mode will reuse the 'default' display settings
danielebarchiesi@0 195 * by default (e.g. right after the module exposing the view mode is
danielebarchiesi@0 196 * enabled), but administrators can later use the Field UI to apply custom
danielebarchiesi@0 197 * display settings specific to the view mode.
danielebarchiesi@0 198 *
danielebarchiesi@0 199 * @see entity_load()
danielebarchiesi@0 200 * @see hook_entity_info_alter()
danielebarchiesi@0 201 */
danielebarchiesi@0 202 function hook_entity_info() {
danielebarchiesi@0 203 $return = array(
danielebarchiesi@0 204 'node' => array(
danielebarchiesi@0 205 'label' => t('Node'),
danielebarchiesi@0 206 'controller class' => 'NodeController',
danielebarchiesi@0 207 'base table' => 'node',
danielebarchiesi@0 208 'revision table' => 'node_revision',
danielebarchiesi@0 209 'uri callback' => 'node_uri',
danielebarchiesi@0 210 'fieldable' => TRUE,
danielebarchiesi@0 211 'translation' => array(
danielebarchiesi@0 212 'locale' => TRUE,
danielebarchiesi@0 213 ),
danielebarchiesi@0 214 'entity keys' => array(
danielebarchiesi@0 215 'id' => 'nid',
danielebarchiesi@0 216 'revision' => 'vid',
danielebarchiesi@0 217 'bundle' => 'type',
danielebarchiesi@0 218 'language' => 'language',
danielebarchiesi@0 219 ),
danielebarchiesi@0 220 'bundle keys' => array(
danielebarchiesi@0 221 'bundle' => 'type',
danielebarchiesi@0 222 ),
danielebarchiesi@0 223 'bundles' => array(),
danielebarchiesi@0 224 'view modes' => array(
danielebarchiesi@0 225 'full' => array(
danielebarchiesi@0 226 'label' => t('Full content'),
danielebarchiesi@0 227 'custom settings' => FALSE,
danielebarchiesi@0 228 ),
danielebarchiesi@0 229 'teaser' => array(
danielebarchiesi@0 230 'label' => t('Teaser'),
danielebarchiesi@0 231 'custom settings' => TRUE,
danielebarchiesi@0 232 ),
danielebarchiesi@0 233 'rss' => array(
danielebarchiesi@0 234 'label' => t('RSS'),
danielebarchiesi@0 235 'custom settings' => FALSE,
danielebarchiesi@0 236 ),
danielebarchiesi@0 237 ),
danielebarchiesi@0 238 ),
danielebarchiesi@0 239 );
danielebarchiesi@0 240
danielebarchiesi@0 241 // Search integration is provided by node.module, so search-related
danielebarchiesi@0 242 // view modes for nodes are defined here and not in search.module.
danielebarchiesi@0 243 if (module_exists('search')) {
danielebarchiesi@0 244 $return['node']['view modes'] += array(
danielebarchiesi@0 245 'search_index' => array(
danielebarchiesi@0 246 'label' => t('Search index'),
danielebarchiesi@0 247 'custom settings' => FALSE,
danielebarchiesi@0 248 ),
danielebarchiesi@0 249 'search_result' => array(
danielebarchiesi@0 250 'label' => t('Search result'),
danielebarchiesi@0 251 'custom settings' => FALSE,
danielebarchiesi@0 252 ),
danielebarchiesi@0 253 );
danielebarchiesi@0 254 }
danielebarchiesi@0 255
danielebarchiesi@0 256 // Bundles must provide a human readable name so we can create help and error
danielebarchiesi@0 257 // messages, and the path to attach Field admin pages to.
danielebarchiesi@0 258 foreach (node_type_get_names() as $type => $name) {
danielebarchiesi@0 259 $return['node']['bundles'][$type] = array(
danielebarchiesi@0 260 'label' => $name,
danielebarchiesi@0 261 'admin' => array(
danielebarchiesi@0 262 'path' => 'admin/structure/types/manage/%node_type',
danielebarchiesi@0 263 'real path' => 'admin/structure/types/manage/' . str_replace('_', '-', $type),
danielebarchiesi@0 264 'bundle argument' => 4,
danielebarchiesi@0 265 'access arguments' => array('administer content types'),
danielebarchiesi@0 266 ),
danielebarchiesi@0 267 );
danielebarchiesi@0 268 }
danielebarchiesi@0 269
danielebarchiesi@0 270 return $return;
danielebarchiesi@0 271 }
danielebarchiesi@0 272
danielebarchiesi@0 273 /**
danielebarchiesi@0 274 * Alter the entity info.
danielebarchiesi@0 275 *
danielebarchiesi@0 276 * Modules may implement this hook to alter the information that defines an
danielebarchiesi@0 277 * entity. All properties that are available in hook_entity_info() can be
danielebarchiesi@0 278 * altered here.
danielebarchiesi@0 279 *
danielebarchiesi@0 280 * @param $entity_info
danielebarchiesi@0 281 * The entity info array, keyed by entity name.
danielebarchiesi@0 282 *
danielebarchiesi@0 283 * @see hook_entity_info()
danielebarchiesi@0 284 */
danielebarchiesi@0 285 function hook_entity_info_alter(&$entity_info) {
danielebarchiesi@0 286 // Set the controller class for nodes to an alternate implementation of the
danielebarchiesi@0 287 // DrupalEntityController interface.
danielebarchiesi@0 288 $entity_info['node']['controller class'] = 'MyCustomNodeController';
danielebarchiesi@0 289 }
danielebarchiesi@0 290
danielebarchiesi@0 291 /**
danielebarchiesi@0 292 * Act on entities when loaded.
danielebarchiesi@0 293 *
danielebarchiesi@0 294 * This is a generic load hook called for all entity types loaded via the
danielebarchiesi@0 295 * entity API.
danielebarchiesi@0 296 *
danielebarchiesi@0 297 * @param $entities
danielebarchiesi@0 298 * The entities keyed by entity ID.
danielebarchiesi@0 299 * @param $type
danielebarchiesi@0 300 * The type of entities being loaded (i.e. node, user, comment).
danielebarchiesi@0 301 */
danielebarchiesi@0 302 function hook_entity_load($entities, $type) {
danielebarchiesi@0 303 foreach ($entities as $entity) {
danielebarchiesi@0 304 $entity->foo = mymodule_add_something($entity, $type);
danielebarchiesi@0 305 }
danielebarchiesi@0 306 }
danielebarchiesi@0 307
danielebarchiesi@0 308 /**
danielebarchiesi@0 309 * Act on an entity before it is about to be created or updated.
danielebarchiesi@0 310 *
danielebarchiesi@0 311 * @param $entity
danielebarchiesi@0 312 * The entity object.
danielebarchiesi@0 313 * @param $type
danielebarchiesi@0 314 * The type of entity being saved (i.e. node, user, comment).
danielebarchiesi@0 315 */
danielebarchiesi@0 316 function hook_entity_presave($entity, $type) {
danielebarchiesi@0 317 $entity->changed = REQUEST_TIME;
danielebarchiesi@0 318 }
danielebarchiesi@0 319
danielebarchiesi@0 320 /**
danielebarchiesi@0 321 * Act on entities when inserted.
danielebarchiesi@0 322 *
danielebarchiesi@0 323 * @param $entity
danielebarchiesi@0 324 * The entity object.
danielebarchiesi@0 325 * @param $type
danielebarchiesi@0 326 * The type of entity being inserted (i.e. node, user, comment).
danielebarchiesi@0 327 */
danielebarchiesi@0 328 function hook_entity_insert($entity, $type) {
danielebarchiesi@0 329 // Insert the new entity into a fictional table of all entities.
danielebarchiesi@0 330 $info = entity_get_info($type);
danielebarchiesi@0 331 list($id) = entity_extract_ids($type, $entity);
danielebarchiesi@0 332 db_insert('example_entity')
danielebarchiesi@0 333 ->fields(array(
danielebarchiesi@0 334 'type' => $type,
danielebarchiesi@0 335 'id' => $id,
danielebarchiesi@0 336 'created' => REQUEST_TIME,
danielebarchiesi@0 337 'updated' => REQUEST_TIME,
danielebarchiesi@0 338 ))
danielebarchiesi@0 339 ->execute();
danielebarchiesi@0 340 }
danielebarchiesi@0 341
danielebarchiesi@0 342 /**
danielebarchiesi@0 343 * Act on entities when updated.
danielebarchiesi@0 344 *
danielebarchiesi@0 345 * @param $entity
danielebarchiesi@0 346 * The entity object.
danielebarchiesi@0 347 * @param $type
danielebarchiesi@0 348 * The type of entity being updated (i.e. node, user, comment).
danielebarchiesi@0 349 */
danielebarchiesi@0 350 function hook_entity_update($entity, $type) {
danielebarchiesi@0 351 // Update the entity's entry in a fictional table of all entities.
danielebarchiesi@0 352 $info = entity_get_info($type);
danielebarchiesi@0 353 list($id) = entity_extract_ids($type, $entity);
danielebarchiesi@0 354 db_update('example_entity')
danielebarchiesi@0 355 ->fields(array(
danielebarchiesi@0 356 'updated' => REQUEST_TIME,
danielebarchiesi@0 357 ))
danielebarchiesi@0 358 ->condition('type', $type)
danielebarchiesi@0 359 ->condition('id', $id)
danielebarchiesi@0 360 ->execute();
danielebarchiesi@0 361 }
danielebarchiesi@0 362
danielebarchiesi@0 363 /**
danielebarchiesi@0 364 * Act on entities when deleted.
danielebarchiesi@0 365 *
danielebarchiesi@0 366 * @param $entity
danielebarchiesi@0 367 * The entity object.
danielebarchiesi@0 368 * @param $type
danielebarchiesi@0 369 * The type of entity being deleted (i.e. node, user, comment).
danielebarchiesi@0 370 */
danielebarchiesi@0 371 function hook_entity_delete($entity, $type) {
danielebarchiesi@0 372 // Delete the entity's entry from a fictional table of all entities.
danielebarchiesi@0 373 $info = entity_get_info($type);
danielebarchiesi@0 374 list($id) = entity_extract_ids($type, $entity);
danielebarchiesi@0 375 db_delete('example_entity')
danielebarchiesi@0 376 ->condition('type', $type)
danielebarchiesi@0 377 ->condition('id', $id)
danielebarchiesi@0 378 ->execute();
danielebarchiesi@0 379 }
danielebarchiesi@0 380
danielebarchiesi@0 381 /**
danielebarchiesi@0 382 * Alter or execute an EntityFieldQuery.
danielebarchiesi@0 383 *
danielebarchiesi@0 384 * @param EntityFieldQuery $query
danielebarchiesi@0 385 * An EntityFieldQuery. One of the most important properties to be changed is
danielebarchiesi@0 386 * EntityFieldQuery::executeCallback. If this is set to an existing function,
danielebarchiesi@0 387 * this function will get the query as its single argument and its result
danielebarchiesi@0 388 * will be the returned as the result of EntityFieldQuery::execute(). This can
danielebarchiesi@0 389 * be used to change the behavior of EntityFieldQuery entirely. For example,
danielebarchiesi@0 390 * the default implementation can only deal with one field storage engine, but
danielebarchiesi@0 391 * it is possible to write a module that can query across field storage
danielebarchiesi@0 392 * engines. Also, the default implementation presumes entities are stored in
danielebarchiesi@0 393 * SQL, but the execute callback could instead query any other entity storage,
danielebarchiesi@0 394 * local or remote.
danielebarchiesi@0 395 *
danielebarchiesi@0 396 * Note the $query->altered attribute which is TRUE in case the query has
danielebarchiesi@0 397 * already been altered once. This happens with cloned queries.
danielebarchiesi@0 398 * If there is a pager, then such a cloned query will be executed to count
danielebarchiesi@0 399 * all elements. This query can be detected by checking for
danielebarchiesi@0 400 * ($query->pager && $query->count), allowing the driver to return 0 from
danielebarchiesi@0 401 * the count query and disable the pager.
danielebarchiesi@0 402 */
danielebarchiesi@0 403 function hook_entity_query_alter($query) {
danielebarchiesi@0 404 $query->executeCallback = 'my_module_query_callback';
danielebarchiesi@0 405 }
danielebarchiesi@0 406
danielebarchiesi@0 407 /**
danielebarchiesi@0 408 * Act on entities being assembled before rendering.
danielebarchiesi@0 409 *
danielebarchiesi@0 410 * @param $entity
danielebarchiesi@0 411 * The entity object.
danielebarchiesi@0 412 * @param $type
danielebarchiesi@0 413 * The type of entity being rendered (i.e. node, user, comment).
danielebarchiesi@0 414 * @param $view_mode
danielebarchiesi@0 415 * The view mode the entity is rendered in.
danielebarchiesi@0 416 * @param $langcode
danielebarchiesi@0 417 * The language code used for rendering.
danielebarchiesi@0 418 *
danielebarchiesi@0 419 * The module may add elements to $entity->content prior to rendering. The
danielebarchiesi@0 420 * structure of $entity->content is a renderable array as expected by
danielebarchiesi@0 421 * drupal_render().
danielebarchiesi@0 422 *
danielebarchiesi@0 423 * @see hook_entity_view_alter()
danielebarchiesi@0 424 * @see hook_comment_view()
danielebarchiesi@0 425 * @see hook_node_view()
danielebarchiesi@0 426 * @see hook_user_view()
danielebarchiesi@0 427 */
danielebarchiesi@0 428 function hook_entity_view($entity, $type, $view_mode, $langcode) {
danielebarchiesi@0 429 $entity->content['my_additional_field'] = array(
danielebarchiesi@0 430 '#markup' => $additional_field,
danielebarchiesi@0 431 '#weight' => 10,
danielebarchiesi@0 432 '#theme' => 'mymodule_my_additional_field',
danielebarchiesi@0 433 );
danielebarchiesi@0 434 }
danielebarchiesi@0 435
danielebarchiesi@0 436 /**
danielebarchiesi@0 437 * Alter the results of ENTITY_view().
danielebarchiesi@0 438 *
danielebarchiesi@0 439 * This hook is called after the content has been assembled in a structured
danielebarchiesi@0 440 * array and may be used for doing processing which requires that the complete
danielebarchiesi@0 441 * entity content structure has been built.
danielebarchiesi@0 442 *
danielebarchiesi@0 443 * If a module wishes to act on the rendered HTML of the entity rather than the
danielebarchiesi@0 444 * structured content array, it may use this hook to add a #post_render
danielebarchiesi@0 445 * callback. Alternatively, it could also implement hook_preprocess_ENTITY().
danielebarchiesi@0 446 * See drupal_render() and theme() for details.
danielebarchiesi@0 447 *
danielebarchiesi@0 448 * @param $build
danielebarchiesi@0 449 * A renderable array representing the entity content.
danielebarchiesi@0 450 * @param $type
danielebarchiesi@0 451 * The type of entity being rendered (i.e. node, user, comment).
danielebarchiesi@0 452 *
danielebarchiesi@0 453 * @see hook_entity_view()
danielebarchiesi@0 454 * @see hook_comment_view_alter()
danielebarchiesi@0 455 * @see hook_node_view_alter()
danielebarchiesi@0 456 * @see hook_taxonomy_term_view_alter()
danielebarchiesi@0 457 * @see hook_user_view_alter()
danielebarchiesi@0 458 */
danielebarchiesi@0 459 function hook_entity_view_alter(&$build, $type) {
danielebarchiesi@0 460 if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
danielebarchiesi@0 461 // Change its weight.
danielebarchiesi@0 462 $build['an_additional_field']['#weight'] = -10;
danielebarchiesi@0 463
danielebarchiesi@0 464 // Add a #post_render callback to act on the rendered HTML of the entity.
danielebarchiesi@0 465 $build['#post_render'][] = 'my_module_node_post_render';
danielebarchiesi@0 466 }
danielebarchiesi@0 467 }
danielebarchiesi@0 468
danielebarchiesi@0 469 /**
danielebarchiesi@0 470 * Change the view mode of an entity that is being displayed.
danielebarchiesi@0 471 *
danielebarchiesi@0 472 * @param string $view_mode
danielebarchiesi@0 473 * The view_mode that is to be used to display the entity.
danielebarchiesi@0 474 * @param array $context
danielebarchiesi@0 475 * Array with contextual information, including:
danielebarchiesi@0 476 * - entity_type: The type of the entity that is being viewed.
danielebarchiesi@0 477 * - entity: The entity object.
danielebarchiesi@0 478 * - langcode: The langcode the entity is being viewed in.
danielebarchiesi@0 479 */
danielebarchiesi@0 480 function hook_entity_view_mode_alter(&$view_mode, $context) {
danielebarchiesi@0 481 // For nodes, change the view mode when it is teaser.
danielebarchiesi@0 482 if ($context['entity_type'] == 'node' && $view_mode == 'teaser') {
danielebarchiesi@0 483 $view_mode = 'my_custom_view_mode';
danielebarchiesi@0 484 }
danielebarchiesi@0 485 }
danielebarchiesi@0 486
danielebarchiesi@0 487 /**
danielebarchiesi@0 488 * Define administrative paths.
danielebarchiesi@0 489 *
danielebarchiesi@0 490 * Modules may specify whether or not the paths they define in hook_menu() are
danielebarchiesi@0 491 * to be considered administrative. Other modules may use this information to
danielebarchiesi@0 492 * display those pages differently (e.g. in a modal overlay, or in a different
danielebarchiesi@0 493 * theme).
danielebarchiesi@0 494 *
danielebarchiesi@0 495 * To change the administrative status of menu items defined in another module's
danielebarchiesi@0 496 * hook_menu(), modules should implement hook_admin_paths_alter().
danielebarchiesi@0 497 *
danielebarchiesi@0 498 * @return
danielebarchiesi@0 499 * An associative array. For each item, the key is the path in question, in
danielebarchiesi@0 500 * a format acceptable to drupal_match_path(). The value for each item should
danielebarchiesi@0 501 * be TRUE (for paths considered administrative) or FALSE (for non-
danielebarchiesi@0 502 * administrative paths).
danielebarchiesi@0 503 *
danielebarchiesi@0 504 * @see hook_menu()
danielebarchiesi@0 505 * @see drupal_match_path()
danielebarchiesi@0 506 * @see hook_admin_paths_alter()
danielebarchiesi@0 507 */
danielebarchiesi@0 508 function hook_admin_paths() {
danielebarchiesi@0 509 $paths = array(
danielebarchiesi@0 510 'mymodule/*/add' => TRUE,
danielebarchiesi@0 511 'mymodule/*/edit' => TRUE,
danielebarchiesi@0 512 );
danielebarchiesi@0 513 return $paths;
danielebarchiesi@0 514 }
danielebarchiesi@0 515
danielebarchiesi@0 516 /**
danielebarchiesi@0 517 * Redefine administrative paths defined by other modules.
danielebarchiesi@0 518 *
danielebarchiesi@0 519 * @param $paths
danielebarchiesi@0 520 * An associative array of administrative paths, as defined by implementations
danielebarchiesi@0 521 * of hook_admin_paths().
danielebarchiesi@0 522 *
danielebarchiesi@0 523 * @see hook_admin_paths()
danielebarchiesi@0 524 */
danielebarchiesi@0 525 function hook_admin_paths_alter(&$paths) {
danielebarchiesi@0 526 // Treat all user pages as administrative.
danielebarchiesi@0 527 $paths['user'] = TRUE;
danielebarchiesi@0 528 $paths['user/*'] = TRUE;
danielebarchiesi@0 529 // Treat the forum topic node form as a non-administrative page.
danielebarchiesi@0 530 $paths['node/add/forum'] = FALSE;
danielebarchiesi@0 531 }
danielebarchiesi@0 532
danielebarchiesi@0 533 /**
danielebarchiesi@0 534 * Act on entities as they are being prepared for view.
danielebarchiesi@0 535 *
danielebarchiesi@0 536 * Allows you to operate on multiple entities as they are being prepared for
danielebarchiesi@0 537 * view. Only use this if attaching the data during the entity_load() phase
danielebarchiesi@0 538 * is not appropriate, for example when attaching other 'entity' style objects.
danielebarchiesi@0 539 *
danielebarchiesi@0 540 * @param $entities
danielebarchiesi@0 541 * The entities keyed by entity ID.
danielebarchiesi@0 542 * @param $type
danielebarchiesi@0 543 * The type of entities being loaded (i.e. node, user, comment).
danielebarchiesi@0 544 * @param $langcode
danielebarchiesi@0 545 * The language to display the entity in.
danielebarchiesi@0 546 */
danielebarchiesi@0 547 function hook_entity_prepare_view($entities, $type, $langcode) {
danielebarchiesi@0 548 // Load a specific node into the user object for later theming.
danielebarchiesi@0 549 if ($type == 'user') {
danielebarchiesi@0 550 $nodes = mymodule_get_user_nodes(array_keys($entities));
danielebarchiesi@0 551 foreach ($entities as $uid => $entity) {
danielebarchiesi@0 552 $entity->user_node = $nodes[$uid];
danielebarchiesi@0 553 }
danielebarchiesi@0 554 }
danielebarchiesi@0 555 }
danielebarchiesi@0 556
danielebarchiesi@0 557 /**
danielebarchiesi@0 558 * Perform periodic actions.
danielebarchiesi@0 559 *
danielebarchiesi@0 560 * Modules that require some commands to be executed periodically can
danielebarchiesi@0 561 * implement hook_cron(). The engine will then call the hook whenever a cron
danielebarchiesi@0 562 * run happens, as defined by the administrator. Typical tasks managed by
danielebarchiesi@0 563 * hook_cron() are database maintenance, backups, recalculation of settings
danielebarchiesi@0 564 * or parameters, automated mailing, and retrieving remote data.
danielebarchiesi@0 565 *
danielebarchiesi@0 566 * Short-running or non-resource-intensive tasks can be executed directly in
danielebarchiesi@0 567 * the hook_cron() implementation.
danielebarchiesi@0 568 *
danielebarchiesi@0 569 * Long-running tasks and tasks that could time out, such as retrieving remote
danielebarchiesi@0 570 * data, sending email, and intensive file tasks, should use the queue API
danielebarchiesi@0 571 * instead of executing the tasks directly. To do this, first define one or
danielebarchiesi@0 572 * more queues via hook_cron_queue_info(). Then, add items that need to be
danielebarchiesi@0 573 * processed to the defined queues.
danielebarchiesi@0 574 */
danielebarchiesi@0 575 function hook_cron() {
danielebarchiesi@0 576 // Short-running operation example, not using a queue:
danielebarchiesi@0 577 // Delete all expired records since the last cron run.
danielebarchiesi@0 578 $expires = variable_get('mymodule_cron_last_run', REQUEST_TIME);
danielebarchiesi@0 579 db_delete('mymodule_table')
danielebarchiesi@0 580 ->condition('expires', $expires, '>=')
danielebarchiesi@0 581 ->execute();
danielebarchiesi@0 582 variable_set('mymodule_cron_last_run', REQUEST_TIME);
danielebarchiesi@0 583
danielebarchiesi@0 584 // Long-running operation example, leveraging a queue:
danielebarchiesi@0 585 // Fetch feeds from other sites.
danielebarchiesi@0 586 $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh <> :never', array(
danielebarchiesi@0 587 ':time' => REQUEST_TIME,
danielebarchiesi@0 588 ':never' => AGGREGATOR_CLEAR_NEVER,
danielebarchiesi@0 589 ));
danielebarchiesi@0 590 $queue = DrupalQueue::get('aggregator_feeds');
danielebarchiesi@0 591 foreach ($result as $feed) {
danielebarchiesi@0 592 $queue->createItem($feed);
danielebarchiesi@0 593 }
danielebarchiesi@0 594 }
danielebarchiesi@0 595
danielebarchiesi@0 596 /**
danielebarchiesi@0 597 * Declare queues holding items that need to be run periodically.
danielebarchiesi@0 598 *
danielebarchiesi@0 599 * While there can be only one hook_cron() process running at the same time,
danielebarchiesi@0 600 * there can be any number of processes defined here running. Because of
danielebarchiesi@0 601 * this, long running tasks are much better suited for this API. Items queued
danielebarchiesi@0 602 * in hook_cron() might be processed in the same cron run if there are not many
danielebarchiesi@0 603 * items in the queue, otherwise it might take several requests, which can be
danielebarchiesi@0 604 * run in parallel.
danielebarchiesi@0 605 *
danielebarchiesi@0 606 * @return
danielebarchiesi@0 607 * An associative array where the key is the queue name and the value is
danielebarchiesi@0 608 * again an associative array. Possible keys are:
danielebarchiesi@0 609 * - 'worker callback': The name of the function to call. It will be called
danielebarchiesi@0 610 * with one argument, the item created via DrupalQueue::createItem() in
danielebarchiesi@0 611 * hook_cron().
danielebarchiesi@0 612 * - 'time': (optional) How much time Drupal should spend on calling this
danielebarchiesi@0 613 * worker in seconds. Defaults to 15.
danielebarchiesi@0 614 *
danielebarchiesi@0 615 * @see hook_cron()
danielebarchiesi@0 616 * @see hook_cron_queue_info_alter()
danielebarchiesi@0 617 */
danielebarchiesi@0 618 function hook_cron_queue_info() {
danielebarchiesi@0 619 $queues['aggregator_feeds'] = array(
danielebarchiesi@0 620 'worker callback' => 'aggregator_refresh',
danielebarchiesi@0 621 'time' => 60,
danielebarchiesi@0 622 );
danielebarchiesi@0 623 return $queues;
danielebarchiesi@0 624 }
danielebarchiesi@0 625
danielebarchiesi@0 626 /**
danielebarchiesi@0 627 * Alter cron queue information before cron runs.
danielebarchiesi@0 628 *
danielebarchiesi@0 629 * Called by drupal_cron_run() to allow modules to alter cron queue settings
danielebarchiesi@0 630 * before any jobs are processesed.
danielebarchiesi@0 631 *
danielebarchiesi@0 632 * @param array $queues
danielebarchiesi@0 633 * An array of cron queue information.
danielebarchiesi@0 634 *
danielebarchiesi@0 635 * @see hook_cron_queue_info()
danielebarchiesi@0 636 * @see drupal_cron_run()
danielebarchiesi@0 637 */
danielebarchiesi@0 638 function hook_cron_queue_info_alter(&$queues) {
danielebarchiesi@0 639 // This site has many feeds so let's spend 90 seconds on each cron run
danielebarchiesi@0 640 // updating feeds instead of the default 60.
danielebarchiesi@0 641 $queues['aggregator_feeds']['time'] = 90;
danielebarchiesi@0 642 }
danielebarchiesi@0 643
danielebarchiesi@0 644 /**
danielebarchiesi@0 645 * Allows modules to declare their own Form API element types and specify their
danielebarchiesi@0 646 * default values.
danielebarchiesi@0 647 *
danielebarchiesi@0 648 * This hook allows modules to declare their own form element types and to
danielebarchiesi@0 649 * specify their default values. The values returned by this hook will be
danielebarchiesi@0 650 * merged with the elements returned by hook_form() implementations and so
danielebarchiesi@0 651 * can return defaults for any Form APIs keys in addition to those explicitly
danielebarchiesi@0 652 * mentioned below.
danielebarchiesi@0 653 *
danielebarchiesi@0 654 * Each of the form element types defined by this hook is assumed to have
danielebarchiesi@0 655 * a matching theme function, e.g. theme_elementtype(), which should be
danielebarchiesi@0 656 * registered with hook_theme() as normal.
danielebarchiesi@0 657 *
danielebarchiesi@0 658 * For more information about custom element types see the explanation at
danielebarchiesi@0 659 * http://drupal.org/node/169815.
danielebarchiesi@0 660 *
danielebarchiesi@0 661 * @return
danielebarchiesi@0 662 * An associative array describing the element types being defined. The array
danielebarchiesi@0 663 * contains a sub-array for each element type, with the machine-readable type
danielebarchiesi@0 664 * name as the key. Each sub-array has a number of possible attributes:
danielebarchiesi@0 665 * - "#input": boolean indicating whether or not this element carries a value
danielebarchiesi@0 666 * (even if it's hidden).
danielebarchiesi@0 667 * - "#process": array of callback functions taking $element, $form_state,
danielebarchiesi@0 668 * and $complete_form.
danielebarchiesi@0 669 * - "#after_build": array of callback functions taking $element and $form_state.
danielebarchiesi@0 670 * - "#validate": array of callback functions taking $form and $form_state.
danielebarchiesi@0 671 * - "#element_validate": array of callback functions taking $element and
danielebarchiesi@0 672 * $form_state.
danielebarchiesi@0 673 * - "#pre_render": array of callback functions taking $element and $form_state.
danielebarchiesi@0 674 * - "#post_render": array of callback functions taking $element and $form_state.
danielebarchiesi@0 675 * - "#submit": array of callback functions taking $form and $form_state.
danielebarchiesi@0 676 * - "#title_display": optional string indicating if and how #title should be
danielebarchiesi@0 677 * displayed, see theme_form_element() and theme_form_element_label().
danielebarchiesi@0 678 *
danielebarchiesi@0 679 * @see hook_element_info_alter()
danielebarchiesi@0 680 * @see system_element_info()
danielebarchiesi@0 681 */
danielebarchiesi@0 682 function hook_element_info() {
danielebarchiesi@0 683 $types['filter_format'] = array(
danielebarchiesi@0 684 '#input' => TRUE,
danielebarchiesi@0 685 );
danielebarchiesi@0 686 return $types;
danielebarchiesi@0 687 }
danielebarchiesi@0 688
danielebarchiesi@0 689 /**
danielebarchiesi@0 690 * Alter the element type information returned from modules.
danielebarchiesi@0 691 *
danielebarchiesi@0 692 * A module may implement this hook in order to alter the element type defaults
danielebarchiesi@0 693 * defined by a module.
danielebarchiesi@0 694 *
danielebarchiesi@0 695 * @param $type
danielebarchiesi@0 696 * All element type defaults as collected by hook_element_info().
danielebarchiesi@0 697 *
danielebarchiesi@0 698 * @see hook_element_info()
danielebarchiesi@0 699 */
danielebarchiesi@0 700 function hook_element_info_alter(&$type) {
danielebarchiesi@0 701 // Decrease the default size of textfields.
danielebarchiesi@0 702 if (isset($type['textfield']['#size'])) {
danielebarchiesi@0 703 $type['textfield']['#size'] = 40;
danielebarchiesi@0 704 }
danielebarchiesi@0 705 }
danielebarchiesi@0 706
danielebarchiesi@0 707 /**
danielebarchiesi@0 708 * Perform cleanup tasks.
danielebarchiesi@0 709 *
danielebarchiesi@0 710 * This hook is run at the end of most regular page requests. It is often
danielebarchiesi@0 711 * used for page logging and specialized cleanup. This hook MUST NOT print
danielebarchiesi@0 712 * anything because by the time it runs the response is already sent to
danielebarchiesi@0 713 * the browser.
danielebarchiesi@0 714 *
danielebarchiesi@0 715 * Only use this hook if your code must run even for cached page views.
danielebarchiesi@0 716 * If you have code which must run once on all non-cached pages, use
danielebarchiesi@0 717 * hook_init() instead. That is the usual case. If you implement this hook
danielebarchiesi@0 718 * and see an error like 'Call to undefined function', it is likely that
danielebarchiesi@0 719 * you are depending on the presence of a module which has not been loaded yet.
danielebarchiesi@0 720 * It is not loaded because Drupal is still in bootstrap mode.
danielebarchiesi@0 721 *
danielebarchiesi@0 722 * @param $destination
danielebarchiesi@0 723 * If this hook is invoked as part of a drupal_goto() call, then this argument
danielebarchiesi@0 724 * will be a fully-qualified URL that is the destination of the redirect.
danielebarchiesi@0 725 */
danielebarchiesi@0 726 function hook_exit($destination = NULL) {
danielebarchiesi@0 727 db_update('counter')
danielebarchiesi@0 728 ->expression('hits', 'hits + 1')
danielebarchiesi@0 729 ->condition('type', 1)
danielebarchiesi@0 730 ->execute();
danielebarchiesi@0 731 }
danielebarchiesi@0 732
danielebarchiesi@0 733 /**
danielebarchiesi@0 734 * Perform necessary alterations to the JavaScript before it is presented on
danielebarchiesi@0 735 * the page.
danielebarchiesi@0 736 *
danielebarchiesi@0 737 * @param $javascript
danielebarchiesi@0 738 * An array of all JavaScript being presented on the page.
danielebarchiesi@0 739 *
danielebarchiesi@0 740 * @see drupal_add_js()
danielebarchiesi@0 741 * @see drupal_get_js()
danielebarchiesi@0 742 * @see drupal_js_defaults()
danielebarchiesi@0 743 */
danielebarchiesi@0 744 function hook_js_alter(&$javascript) {
danielebarchiesi@0 745 // Swap out jQuery to use an updated version of the library.
danielebarchiesi@0 746 $javascript['misc/jquery.js']['data'] = drupal_get_path('module', 'jquery_update') . '/jquery.js';
danielebarchiesi@0 747 }
danielebarchiesi@0 748
danielebarchiesi@0 749 /**
danielebarchiesi@0 750 * Registers JavaScript/CSS libraries associated with a module.
danielebarchiesi@0 751 *
danielebarchiesi@0 752 * Modules implementing this return an array of arrays. The key to each
danielebarchiesi@0 753 * sub-array is the machine readable name of the library. Each library may
danielebarchiesi@0 754 * contain the following items:
danielebarchiesi@0 755 *
danielebarchiesi@0 756 * - 'title': The human readable name of the library.
danielebarchiesi@0 757 * - 'website': The URL of the library's web site.
danielebarchiesi@0 758 * - 'version': A string specifying the version of the library; intentionally
danielebarchiesi@0 759 * not a float because a version like "1.2.3" is not a valid float. Use PHP's
danielebarchiesi@0 760 * version_compare() to compare different versions.
danielebarchiesi@0 761 * - 'js': An array of JavaScript elements; each element's key is used as $data
danielebarchiesi@0 762 * argument, each element's value is used as $options array for
danielebarchiesi@0 763 * drupal_add_js(). To add library-specific (not module-specific) JavaScript
danielebarchiesi@0 764 * settings, the key may be skipped, the value must specify
danielebarchiesi@0 765 * 'type' => 'setting', and the actual settings must be contained in a 'data'
danielebarchiesi@0 766 * element of the value.
danielebarchiesi@0 767 * - 'css': Like 'js', an array of CSS elements passed to drupal_add_css().
danielebarchiesi@0 768 * - 'dependencies': An array of libraries that are required for a library. Each
danielebarchiesi@0 769 * element is an array listing the module and name of another library. Note
danielebarchiesi@0 770 * that all dependencies for each dependent library will also be added when
danielebarchiesi@0 771 * this library is added.
danielebarchiesi@0 772 *
danielebarchiesi@0 773 * Registered information for a library should contain re-usable data only.
danielebarchiesi@0 774 * Module- or implementation-specific data and integration logic should be added
danielebarchiesi@0 775 * separately.
danielebarchiesi@0 776 *
danielebarchiesi@0 777 * @return
danielebarchiesi@0 778 * An array defining libraries associated with a module.
danielebarchiesi@0 779 *
danielebarchiesi@0 780 * @see system_library()
danielebarchiesi@0 781 * @see drupal_add_library()
danielebarchiesi@0 782 * @see drupal_get_library()
danielebarchiesi@0 783 */
danielebarchiesi@0 784 function hook_library() {
danielebarchiesi@0 785 // Library One.
danielebarchiesi@0 786 $libraries['library-1'] = array(
danielebarchiesi@0 787 'title' => 'Library One',
danielebarchiesi@0 788 'website' => 'http://example.com/library-1',
danielebarchiesi@0 789 'version' => '1.2',
danielebarchiesi@0 790 'js' => array(
danielebarchiesi@0 791 drupal_get_path('module', 'my_module') . '/library-1.js' => array(),
danielebarchiesi@0 792 ),
danielebarchiesi@0 793 'css' => array(
danielebarchiesi@0 794 drupal_get_path('module', 'my_module') . '/library-2.css' => array(
danielebarchiesi@0 795 'type' => 'file',
danielebarchiesi@0 796 'media' => 'screen',
danielebarchiesi@0 797 ),
danielebarchiesi@0 798 ),
danielebarchiesi@0 799 );
danielebarchiesi@0 800 // Library Two.
danielebarchiesi@0 801 $libraries['library-2'] = array(
danielebarchiesi@0 802 'title' => 'Library Two',
danielebarchiesi@0 803 'website' => 'http://example.com/library-2',
danielebarchiesi@0 804 'version' => '3.1-beta1',
danielebarchiesi@0 805 'js' => array(
danielebarchiesi@0 806 // JavaScript settings may use the 'data' key.
danielebarchiesi@0 807 array(
danielebarchiesi@0 808 'type' => 'setting',
danielebarchiesi@0 809 'data' => array('library2' => TRUE),
danielebarchiesi@0 810 ),
danielebarchiesi@0 811 ),
danielebarchiesi@0 812 'dependencies' => array(
danielebarchiesi@0 813 // Require jQuery UI core by System module.
danielebarchiesi@0 814 array('system', 'ui'),
danielebarchiesi@0 815 // Require our other library.
danielebarchiesi@0 816 array('my_module', 'library-1'),
danielebarchiesi@0 817 // Require another library.
danielebarchiesi@0 818 array('other_module', 'library-3'),
danielebarchiesi@0 819 ),
danielebarchiesi@0 820 );
danielebarchiesi@0 821 return $libraries;
danielebarchiesi@0 822 }
danielebarchiesi@0 823
danielebarchiesi@0 824 /**
danielebarchiesi@0 825 * Alters the JavaScript/CSS library registry.
danielebarchiesi@0 826 *
danielebarchiesi@0 827 * Allows certain, contributed modules to update libraries to newer versions
danielebarchiesi@0 828 * while ensuring backwards compatibility. In general, such manipulations should
danielebarchiesi@0 829 * only be done by designated modules, since most modules that integrate with a
danielebarchiesi@0 830 * certain library also depend on the API of a certain library version.
danielebarchiesi@0 831 *
danielebarchiesi@0 832 * @param $libraries
danielebarchiesi@0 833 * The JavaScript/CSS libraries provided by $module. Keyed by internal library
danielebarchiesi@0 834 * name and passed by reference.
danielebarchiesi@0 835 * @param $module
danielebarchiesi@0 836 * The name of the module that registered the libraries.
danielebarchiesi@0 837 *
danielebarchiesi@0 838 * @see hook_library()
danielebarchiesi@0 839 */
danielebarchiesi@0 840 function hook_library_alter(&$libraries, $module) {
danielebarchiesi@0 841 // Update Farbtastic to version 2.0.
danielebarchiesi@0 842 if ($module == 'system' && isset($libraries['farbtastic'])) {
danielebarchiesi@0 843 // Verify existing version is older than the one we are updating to.
danielebarchiesi@0 844 if (version_compare($libraries['farbtastic']['version'], '2.0', '<')) {
danielebarchiesi@0 845 // Update the existing Farbtastic to version 2.0.
danielebarchiesi@0 846 $libraries['farbtastic']['version'] = '2.0';
danielebarchiesi@0 847 $libraries['farbtastic']['js'] = array(
danielebarchiesi@0 848 drupal_get_path('module', 'farbtastic_update') . '/farbtastic-2.0.js' => array(),
danielebarchiesi@0 849 );
danielebarchiesi@0 850 }
danielebarchiesi@0 851 }
danielebarchiesi@0 852 }
danielebarchiesi@0 853
danielebarchiesi@0 854 /**
danielebarchiesi@0 855 * Alter CSS files before they are output on the page.
danielebarchiesi@0 856 *
danielebarchiesi@0 857 * @param $css
danielebarchiesi@0 858 * An array of all CSS items (files and inline CSS) being requested on the page.
danielebarchiesi@0 859 *
danielebarchiesi@0 860 * @see drupal_add_css()
danielebarchiesi@0 861 * @see drupal_get_css()
danielebarchiesi@0 862 */
danielebarchiesi@0 863 function hook_css_alter(&$css) {
danielebarchiesi@0 864 // Remove defaults.css file.
danielebarchiesi@0 865 unset($css[drupal_get_path('module', 'system') . '/defaults.css']);
danielebarchiesi@0 866 }
danielebarchiesi@0 867
danielebarchiesi@0 868 /**
danielebarchiesi@0 869 * Alter the commands that are sent to the user through the Ajax framework.
danielebarchiesi@0 870 *
danielebarchiesi@0 871 * @param $commands
danielebarchiesi@0 872 * An array of all commands that will be sent to the user.
danielebarchiesi@0 873 *
danielebarchiesi@0 874 * @see ajax_render()
danielebarchiesi@0 875 */
danielebarchiesi@0 876 function hook_ajax_render_alter($commands) {
danielebarchiesi@0 877 // Inject any new status messages into the content area.
danielebarchiesi@0 878 $commands[] = ajax_command_prepend('#block-system-main .content', theme('status_messages'));
danielebarchiesi@0 879 }
danielebarchiesi@0 880
danielebarchiesi@0 881 /**
danielebarchiesi@0 882 * Add elements to a page before it is rendered.
danielebarchiesi@0 883 *
danielebarchiesi@0 884 * Use this hook when you want to add elements at the page level. For your
danielebarchiesi@0 885 * additions to be printed, they have to be placed below a top level array key
danielebarchiesi@0 886 * of the $page array that has the name of a region of the active theme.
danielebarchiesi@0 887 *
danielebarchiesi@0 888 * By default, valid region keys are 'page_top', 'header', 'sidebar_first',
danielebarchiesi@0 889 * 'content', 'sidebar_second' and 'page_bottom'. To get a list of all regions
danielebarchiesi@0 890 * of the active theme, use system_region_list($theme). Note that $theme is a
danielebarchiesi@0 891 * global variable.
danielebarchiesi@0 892 *
danielebarchiesi@0 893 * If you want to alter the elements added by other modules or if your module
danielebarchiesi@0 894 * depends on the elements of other modules, use hook_page_alter() instead which
danielebarchiesi@0 895 * runs after this hook.
danielebarchiesi@0 896 *
danielebarchiesi@0 897 * @param $page
danielebarchiesi@0 898 * Nested array of renderable elements that make up the page.
danielebarchiesi@0 899 *
danielebarchiesi@0 900 * @see hook_page_alter()
danielebarchiesi@0 901 * @see drupal_render_page()
danielebarchiesi@0 902 */
danielebarchiesi@0 903 function hook_page_build(&$page) {
danielebarchiesi@0 904 if (menu_get_object('node', 1)) {
danielebarchiesi@0 905 // We are on a node detail page. Append a standard disclaimer to the
danielebarchiesi@0 906 // content region.
danielebarchiesi@0 907 $page['content']['disclaimer'] = array(
danielebarchiesi@0 908 '#markup' => t('Acme, Inc. is not responsible for the contents of this sample code.'),
danielebarchiesi@0 909 '#weight' => 25,
danielebarchiesi@0 910 );
danielebarchiesi@0 911 }
danielebarchiesi@0 912 }
danielebarchiesi@0 913
danielebarchiesi@0 914 /**
danielebarchiesi@0 915 * Alter a menu router item right after it has been retrieved from the database or cache.
danielebarchiesi@0 916 *
danielebarchiesi@0 917 * This hook is invoked by menu_get_item() and allows for run-time alteration of router
danielebarchiesi@0 918 * information (page_callback, title, and so on) before it is translated and checked for
danielebarchiesi@0 919 * access. The passed-in $router_item is statically cached for the current request, so this
danielebarchiesi@0 920 * hook is only invoked once for any router item that is retrieved via menu_get_item().
danielebarchiesi@0 921 *
danielebarchiesi@0 922 * Usually, modules will only want to inspect the router item and conditionally
danielebarchiesi@0 923 * perform other actions (such as preparing a state for the current request).
danielebarchiesi@0 924 * Note that this hook is invoked for any router item that is retrieved by
danielebarchiesi@0 925 * menu_get_item(), which may or may not be called on the path itself, so implementations
danielebarchiesi@0 926 * should check the $path parameter if the alteration should fire for the current request
danielebarchiesi@0 927 * only.
danielebarchiesi@0 928 *
danielebarchiesi@0 929 * @param $router_item
danielebarchiesi@0 930 * The menu router item for $path.
danielebarchiesi@0 931 * @param $path
danielebarchiesi@0 932 * The originally passed path, for which $router_item is responsible.
danielebarchiesi@0 933 * @param $original_map
danielebarchiesi@0 934 * The path argument map, as contained in $path.
danielebarchiesi@0 935 *
danielebarchiesi@0 936 * @see menu_get_item()
danielebarchiesi@0 937 */
danielebarchiesi@0 938 function hook_menu_get_item_alter(&$router_item, $path, $original_map) {
danielebarchiesi@0 939 // When retrieving the router item for the current path...
danielebarchiesi@0 940 if ($path == $_GET['q']) {
danielebarchiesi@0 941 // ...call a function that prepares something for this request.
danielebarchiesi@0 942 mymodule_prepare_something();
danielebarchiesi@0 943 }
danielebarchiesi@0 944 }
danielebarchiesi@0 945
danielebarchiesi@0 946 /**
danielebarchiesi@0 947 * Define menu items and page callbacks.
danielebarchiesi@0 948 *
danielebarchiesi@0 949 * This hook enables modules to register paths in order to define how URL
danielebarchiesi@0 950 * requests are handled. Paths may be registered for URL handling only, or they
danielebarchiesi@0 951 * can register a link to be placed in a menu (usually the Navigation menu). A
danielebarchiesi@0 952 * path and its associated information is commonly called a "menu router item".
danielebarchiesi@0 953 * This hook is rarely called (for example, when modules are enabled), and
danielebarchiesi@0 954 * its results are cached in the database.
danielebarchiesi@0 955 *
danielebarchiesi@0 956 * hook_menu() implementations return an associative array whose keys define
danielebarchiesi@0 957 * paths and whose values are an associative array of properties for each
danielebarchiesi@0 958 * path. (The complete list of properties is in the return value section below.)
danielebarchiesi@0 959 *
danielebarchiesi@0 960 * @section sec_callback_funcs Callback Functions
danielebarchiesi@0 961 * The definition for each path may include a page callback function, which is
danielebarchiesi@0 962 * invoked when the registered path is requested. If there is no other
danielebarchiesi@0 963 * registered path that fits the requested path better, any further path
danielebarchiesi@0 964 * components are passed to the callback function. For example, your module
danielebarchiesi@0 965 * could register path 'abc/def':
danielebarchiesi@0 966 * @code
danielebarchiesi@0 967 * function mymodule_menu() {
danielebarchiesi@0 968 * $items['abc/def'] = array(
danielebarchiesi@0 969 * 'page callback' => 'mymodule_abc_view',
danielebarchiesi@0 970 * );
danielebarchiesi@0 971 * return $items;
danielebarchiesi@0 972 * }
danielebarchiesi@0 973 *
danielebarchiesi@0 974 * function mymodule_abc_view($ghi = 0, $jkl = '') {
danielebarchiesi@0 975 * // ...
danielebarchiesi@0 976 * }
danielebarchiesi@0 977 * @endcode
danielebarchiesi@0 978 * When path 'abc/def' is requested, no further path components are in the
danielebarchiesi@0 979 * request, and no additional arguments are passed to the callback function (so
danielebarchiesi@0 980 * $ghi and $jkl would take the default values as defined in the function
danielebarchiesi@0 981 * signature). When 'abc/def/123/foo' is requested, $ghi will be '123' and
danielebarchiesi@0 982 * $jkl will be 'foo'. Note that this automatic passing of optional path
danielebarchiesi@0 983 * arguments applies only to page and theme callback functions.
danielebarchiesi@0 984 *
danielebarchiesi@0 985 * @subsection sub_callback_arguments Callback Arguments
danielebarchiesi@0 986 * In addition to optional path arguments, the page callback and other callback
danielebarchiesi@0 987 * functions may specify argument lists as arrays. These argument lists may
danielebarchiesi@0 988 * contain both fixed/hard-coded argument values and integers that correspond
danielebarchiesi@0 989 * to path components. When integers are used and the callback function is
danielebarchiesi@0 990 * called, the corresponding path components will be substituted for the
danielebarchiesi@0 991 * integers. That is, the integer 0 in an argument list will be replaced with
danielebarchiesi@0 992 * the first path component, integer 1 with the second, and so on (path
danielebarchiesi@0 993 * components are numbered starting from zero). To pass an integer without it
danielebarchiesi@0 994 * being replaced with its respective path component, use the string value of
danielebarchiesi@0 995 * the integer (e.g., '1') as the argument value. This substitution feature
danielebarchiesi@0 996 * allows you to re-use a callback function for several different paths. For
danielebarchiesi@0 997 * example:
danielebarchiesi@0 998 * @code
danielebarchiesi@0 999 * function mymodule_menu() {
danielebarchiesi@0 1000 * $items['abc/def'] = array(
danielebarchiesi@0 1001 * 'page callback' => 'mymodule_abc_view',
danielebarchiesi@0 1002 * 'page arguments' => array(1, 'foo'),
danielebarchiesi@0 1003 * );
danielebarchiesi@0 1004 * return $items;
danielebarchiesi@0 1005 * }
danielebarchiesi@0 1006 * @endcode
danielebarchiesi@0 1007 * When path 'abc/def' is requested, the page callback function will get 'def'
danielebarchiesi@0 1008 * as the first argument and (always) 'foo' as the second argument.
danielebarchiesi@0 1009 *
danielebarchiesi@0 1010 * If a page callback function uses an argument list array, and its path is
danielebarchiesi@0 1011 * requested with optional path arguments, then the list array's arguments are
danielebarchiesi@0 1012 * passed to the callback function first, followed by the optional path
danielebarchiesi@0 1013 * arguments. Using the above example, when path 'abc/def/bar/baz' is requested,
danielebarchiesi@0 1014 * mymodule_abc_view() will be called with 'def', 'foo', 'bar' and 'baz' as
danielebarchiesi@0 1015 * arguments, in that order.
danielebarchiesi@0 1016 *
danielebarchiesi@0 1017 * Special care should be taken for the page callback drupal_get_form(), because
danielebarchiesi@0 1018 * your specific form callback function will always receive $form and
danielebarchiesi@0 1019 * &$form_state as the first function arguments:
danielebarchiesi@0 1020 * @code
danielebarchiesi@0 1021 * function mymodule_abc_form($form, &$form_state) {
danielebarchiesi@0 1022 * // ...
danielebarchiesi@0 1023 * return $form;
danielebarchiesi@0 1024 * }
danielebarchiesi@0 1025 * @endcode
danielebarchiesi@0 1026 * See @link form_api Form API documentation @endlink for details.
danielebarchiesi@0 1027 *
danielebarchiesi@0 1028 * @section sec_path_wildcards Wildcards in Paths
danielebarchiesi@0 1029 * @subsection sub_simple_wildcards Simple Wildcards
danielebarchiesi@0 1030 * Wildcards within paths also work with integer substitution. For example,
danielebarchiesi@0 1031 * your module could register path 'my-module/%/edit':
danielebarchiesi@0 1032 * @code
danielebarchiesi@0 1033 * $items['my-module/%/edit'] = array(
danielebarchiesi@0 1034 * 'page callback' => 'mymodule_abc_edit',
danielebarchiesi@0 1035 * 'page arguments' => array(1),
danielebarchiesi@0 1036 * );
danielebarchiesi@0 1037 * @endcode
danielebarchiesi@0 1038 * When path 'my-module/foo/edit' is requested, integer 1 will be replaced
danielebarchiesi@0 1039 * with 'foo' and passed to the callback function. Note that wildcards may not
danielebarchiesi@0 1040 * be used as the first component.
danielebarchiesi@0 1041 *
danielebarchiesi@0 1042 * @subsection sub_autoload_wildcards Auto-Loader Wildcards
danielebarchiesi@0 1043 * Registered paths may also contain special "auto-loader" wildcard components
danielebarchiesi@0 1044 * in the form of '%mymodule_abc', where the '%' part means that this path
danielebarchiesi@0 1045 * component is a wildcard, and the 'mymodule_abc' part defines the prefix for a
danielebarchiesi@0 1046 * load function, which here would be named mymodule_abc_load(). When a matching
danielebarchiesi@0 1047 * path is requested, your load function will receive as its first argument the
danielebarchiesi@0 1048 * path component in the position of the wildcard; load functions may also be
danielebarchiesi@0 1049 * passed additional arguments (see "load arguments" in the return value
danielebarchiesi@0 1050 * section below). For example, your module could register path
danielebarchiesi@0 1051 * 'my-module/%mymodule_abc/edit':
danielebarchiesi@0 1052 * @code
danielebarchiesi@0 1053 * $items['my-module/%mymodule_abc/edit'] = array(
danielebarchiesi@0 1054 * 'page callback' => 'mymodule_abc_edit',
danielebarchiesi@0 1055 * 'page arguments' => array(1),
danielebarchiesi@0 1056 * );
danielebarchiesi@0 1057 * @endcode
danielebarchiesi@0 1058 * When path 'my-module/123/edit' is requested, your load function
danielebarchiesi@0 1059 * mymodule_abc_load() will be invoked with the argument '123', and should
danielebarchiesi@0 1060 * load and return an "abc" object with internal id 123:
danielebarchiesi@0 1061 * @code
danielebarchiesi@0 1062 * function mymodule_abc_load($abc_id) {
danielebarchiesi@0 1063 * return db_query("SELECT * FROM {mymodule_abc} WHERE abc_id = :abc_id", array(':abc_id' => $abc_id))->fetchObject();
danielebarchiesi@0 1064 * }
danielebarchiesi@0 1065 * @endcode
danielebarchiesi@0 1066 * This 'abc' object will then be passed into the callback functions defined
danielebarchiesi@0 1067 * for the menu item, such as the page callback function mymodule_abc_edit()
danielebarchiesi@0 1068 * to replace the integer 1 in the argument array. Note that a load function
danielebarchiesi@0 1069 * should return FALSE when it is unable to provide a loadable object. For
danielebarchiesi@0 1070 * example, the node_load() function for the 'node/%node/edit' menu item will
danielebarchiesi@0 1071 * return FALSE for the path 'node/999/edit' if a node with a node ID of 999
danielebarchiesi@0 1072 * does not exist. The menu routing system will return a 404 error in this case.
danielebarchiesi@0 1073 *
danielebarchiesi@0 1074 * @subsection sub_argument_wildcards Argument Wildcards
danielebarchiesi@0 1075 * You can also define a %wildcard_to_arg() function (for the example menu
danielebarchiesi@0 1076 * entry above this would be 'mymodule_abc_to_arg()'). The _to_arg() function
danielebarchiesi@0 1077 * is invoked to retrieve a value that is used in the path in place of the
danielebarchiesi@0 1078 * wildcard. A good example is user.module, which defines
danielebarchiesi@0 1079 * user_uid_optional_to_arg() (corresponding to the menu entry
danielebarchiesi@0 1080 * 'tracker/%user_uid_optional'). This function returns the user ID of the
danielebarchiesi@0 1081 * current user.
danielebarchiesi@0 1082 *
danielebarchiesi@0 1083 * The _to_arg() function will get called with three arguments:
danielebarchiesi@0 1084 * - $arg: A string representing whatever argument may have been supplied by
danielebarchiesi@0 1085 * the caller (this is particularly useful if you want the _to_arg()
danielebarchiesi@0 1086 * function only supply a (default) value if no other value is specified,
danielebarchiesi@0 1087 * as in the case of user_uid_optional_to_arg().
danielebarchiesi@0 1088 * - $map: An array of all path fragments (e.g. array('node','123','edit') for
danielebarchiesi@0 1089 * 'node/123/edit').
danielebarchiesi@0 1090 * - $index: An integer indicating which element of $map corresponds to $arg.
danielebarchiesi@0 1091 *
danielebarchiesi@0 1092 * _load() and _to_arg() functions may seem similar at first glance, but they
danielebarchiesi@0 1093 * have different purposes and are called at different times. _load()
danielebarchiesi@0 1094 * functions are called when the menu system is collecting arguments to pass
danielebarchiesi@0 1095 * to the callback functions defined for the menu item. _to_arg() functions
danielebarchiesi@0 1096 * are called when the menu system is generating links to related paths, such
danielebarchiesi@0 1097 * as the tabs for a set of MENU_LOCAL_TASK items.
danielebarchiesi@0 1098 *
danielebarchiesi@0 1099 * @section sec_render_tabs Rendering Menu Items As Tabs
danielebarchiesi@0 1100 * You can also make groups of menu items to be rendered (by default) as tabs
danielebarchiesi@0 1101 * on a page. To do that, first create one menu item of type MENU_NORMAL_ITEM,
danielebarchiesi@0 1102 * with your chosen path, such as 'foo'. Then duplicate that menu item, using a
danielebarchiesi@0 1103 * subdirectory path, such as 'foo/tab1', and changing the type to
danielebarchiesi@0 1104 * MENU_DEFAULT_LOCAL_TASK to make it the default tab for the group. Then add
danielebarchiesi@0 1105 * the additional tab items, with paths such as "foo/tab2" etc., with type
danielebarchiesi@0 1106 * MENU_LOCAL_TASK. Example:
danielebarchiesi@0 1107 * @code
danielebarchiesi@0 1108 * // Make "Foo settings" appear on the admin Config page
danielebarchiesi@0 1109 * $items['admin/config/system/foo'] = array(
danielebarchiesi@0 1110 * 'title' => 'Foo settings',
danielebarchiesi@0 1111 * 'type' => MENU_NORMAL_ITEM,
danielebarchiesi@0 1112 * // Page callback, etc. need to be added here.
danielebarchiesi@0 1113 * );
danielebarchiesi@0 1114 * // Make "Tab 1" the main tab on the "Foo settings" page
danielebarchiesi@0 1115 * $items['admin/config/system/foo/tab1'] = array(
danielebarchiesi@0 1116 * 'title' => 'Tab 1',
danielebarchiesi@0 1117 * 'type' => MENU_DEFAULT_LOCAL_TASK,
danielebarchiesi@0 1118 * // Access callback, page callback, and theme callback will be inherited
danielebarchiesi@0 1119 * // from 'admin/config/system/foo', if not specified here to override.
danielebarchiesi@0 1120 * );
danielebarchiesi@0 1121 * // Make an additional tab called "Tab 2" on "Foo settings"
danielebarchiesi@0 1122 * $items['admin/config/system/foo/tab2'] = array(
danielebarchiesi@0 1123 * 'title' => 'Tab 2',
danielebarchiesi@0 1124 * 'type' => MENU_LOCAL_TASK,
danielebarchiesi@0 1125 * // Page callback and theme callback will be inherited from
danielebarchiesi@0 1126 * // 'admin/config/system/foo', if not specified here to override.
danielebarchiesi@0 1127 * // Need to add access callback or access arguments.
danielebarchiesi@0 1128 * );
danielebarchiesi@0 1129 * @endcode
danielebarchiesi@0 1130 *
danielebarchiesi@0 1131 * @return
danielebarchiesi@0 1132 * An array of menu items. Each menu item has a key corresponding to the
danielebarchiesi@0 1133 * Drupal path being registered. The corresponding array value is an
danielebarchiesi@0 1134 * associative array that may contain the following key-value pairs:
danielebarchiesi@0 1135 * - "title": Required. The untranslated title of the menu item.
danielebarchiesi@0 1136 * - "title callback": Function to generate the title; defaults to t().
danielebarchiesi@0 1137 * If you require only the raw string to be output, set this to FALSE.
danielebarchiesi@0 1138 * - "title arguments": Arguments to send to t() or your custom callback,
danielebarchiesi@0 1139 * with path component substitution as described above.
danielebarchiesi@0 1140 * - "description": The untranslated description of the menu item.
danielebarchiesi@0 1141 * - "page callback": The function to call to display a web page when the user
danielebarchiesi@0 1142 * visits the path. If omitted, the parent menu item's callback will be used
danielebarchiesi@0 1143 * instead.
danielebarchiesi@0 1144 * - "page arguments": An array of arguments to pass to the page callback
danielebarchiesi@0 1145 * function, with path component substitution as described above.
danielebarchiesi@0 1146 * - "delivery callback": The function to call to package the result of the
danielebarchiesi@0 1147 * page callback function and send it to the browser. Defaults to
danielebarchiesi@0 1148 * drupal_deliver_html_page() unless a value is inherited from a parent menu
danielebarchiesi@0 1149 * item. Note that this function is called even if the access checks fail,
danielebarchiesi@0 1150 * so any custom delivery callback function should take that into account.
danielebarchiesi@0 1151 * See drupal_deliver_html_page() for an example.
danielebarchiesi@0 1152 * - "access callback": A function returning TRUE if the user has access
danielebarchiesi@0 1153 * rights to this menu item, and FALSE if not. It can also be a boolean
danielebarchiesi@0 1154 * constant instead of a function, and you can also use numeric values
danielebarchiesi@0 1155 * (will be cast to boolean). Defaults to user_access() unless a value is
danielebarchiesi@0 1156 * inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items
danielebarchiesi@0 1157 * can inherit access callbacks. To use the user_access() default callback,
danielebarchiesi@0 1158 * you must specify the permission to check as 'access arguments' (see
danielebarchiesi@0 1159 * below).
danielebarchiesi@0 1160 * - "access arguments": An array of arguments to pass to the access callback
danielebarchiesi@0 1161 * function, with path component substitution as described above. If the
danielebarchiesi@0 1162 * access callback is inherited (see above), the access arguments will be
danielebarchiesi@0 1163 * inherited with it, unless overridden in the child menu item.
danielebarchiesi@0 1164 * - "theme callback": (optional) A function returning the machine-readable
danielebarchiesi@0 1165 * name of the theme that will be used to render the page. If not provided,
danielebarchiesi@0 1166 * the value will be inherited from a parent menu item. If there is no
danielebarchiesi@0 1167 * theme callback, or if the function does not return the name of a current
danielebarchiesi@0 1168 * active theme on the site, the theme for this page will be determined by
danielebarchiesi@0 1169 * either hook_custom_theme() or the default theme instead. As a general
danielebarchiesi@0 1170 * rule, the use of theme callback functions should be limited to pages
danielebarchiesi@0 1171 * whose functionality is very closely tied to a particular theme, since
danielebarchiesi@0 1172 * they can only be overridden by modules which specifically target those
danielebarchiesi@0 1173 * pages in hook_menu_alter(). Modules implementing more generic theme
danielebarchiesi@0 1174 * switching functionality (for example, a module which allows the theme to
danielebarchiesi@0 1175 * be set dynamically based on the current user's role) should use
danielebarchiesi@0 1176 * hook_custom_theme() instead.
danielebarchiesi@0 1177 * - "theme arguments": An array of arguments to pass to the theme callback
danielebarchiesi@0 1178 * function, with path component substitution as described above.
danielebarchiesi@0 1179 * - "file": A file that will be included before the page callback is called;
danielebarchiesi@0 1180 * this allows page callback functions to be in separate files. The file
danielebarchiesi@0 1181 * should be relative to the implementing module's directory unless
danielebarchiesi@0 1182 * otherwise specified by the "file path" option. Does not apply to other
danielebarchiesi@0 1183 * callbacks (only page callback).
danielebarchiesi@0 1184 * - "file path": The path to the directory containing the file specified in
danielebarchiesi@0 1185 * "file". This defaults to the path to the module implementing the hook.
danielebarchiesi@0 1186 * - "load arguments": An array of arguments to be passed to each of the
danielebarchiesi@0 1187 * wildcard object loaders in the path, after the path argument itself.
danielebarchiesi@0 1188 * For example, if a module registers path node/%node/revisions/%/view
danielebarchiesi@0 1189 * with load arguments set to array(3), the '%node' in the path indicates
danielebarchiesi@0 1190 * that the loader function node_load() will be called with the second
danielebarchiesi@0 1191 * path component as the first argument. The 3 in the load arguments
danielebarchiesi@0 1192 * indicates that the fourth path component will also be passed to
danielebarchiesi@0 1193 * node_load() (numbering of path components starts at zero). So, if path
danielebarchiesi@0 1194 * node/12/revisions/29/view is requested, node_load(12, 29) will be called.
danielebarchiesi@0 1195 * There are also two "magic" values that can be used in load arguments.
danielebarchiesi@0 1196 * "%index" indicates the index of the wildcard path component. "%map"
danielebarchiesi@0 1197 * indicates the path components as an array. For example, if a module
danielebarchiesi@0 1198 * registers for several paths of the form 'user/%user_category/edit/*', all
danielebarchiesi@0 1199 * of them can use the same load function user_category_load(), by setting
danielebarchiesi@0 1200 * the load arguments to array('%map', '%index'). For instance, if the user
danielebarchiesi@0 1201 * is editing category 'foo' by requesting path 'user/32/edit/foo', the load
danielebarchiesi@0 1202 * function user_category_load() will be called with 32 as its first
danielebarchiesi@0 1203 * argument, the array ('user', 32, 'edit', 'foo') as the map argument,
danielebarchiesi@0 1204 * and 1 as the index argument (because %user_category is the second path
danielebarchiesi@0 1205 * component and numbering starts at zero). user_category_load() can then
danielebarchiesi@0 1206 * use these values to extract the information that 'foo' is the category
danielebarchiesi@0 1207 * being requested.
danielebarchiesi@0 1208 * - "weight": An integer that determines the relative position of items in
danielebarchiesi@0 1209 * the menu; higher-weighted items sink. Defaults to 0. Menu items with the
danielebarchiesi@0 1210 * same weight are ordered alphabetically.
danielebarchiesi@0 1211 * - "menu_name": Optional. Set this to a custom menu if you don't want your
danielebarchiesi@0 1212 * item to be placed in Navigation.
danielebarchiesi@0 1213 * - "expanded": Optional. If set to TRUE, and if a menu link is provided for
danielebarchiesi@0 1214 * this menu item (as a result of other properties), then the menu link is
danielebarchiesi@0 1215 * always expanded, equivalent to its 'always expanded' checkbox being set
danielebarchiesi@0 1216 * in the UI.
danielebarchiesi@0 1217 * - "context": (optional) Defines the context a tab may appear in. By
danielebarchiesi@0 1218 * default, all tabs are only displayed as local tasks when being rendered
danielebarchiesi@0 1219 * in a page context. All tabs that should be accessible as contextual links
danielebarchiesi@0 1220 * in page region containers outside of the parent menu item's primary page
danielebarchiesi@0 1221 * context should be registered using one of the following contexts:
danielebarchiesi@0 1222 * - MENU_CONTEXT_PAGE: (default) The tab is displayed as local task for the
danielebarchiesi@0 1223 * page context only.
danielebarchiesi@0 1224 * - MENU_CONTEXT_INLINE: The tab is displayed as contextual link outside of
danielebarchiesi@0 1225 * the primary page context only.
danielebarchiesi@0 1226 * Contexts can be combined. For example, to display a tab both on a page
danielebarchiesi@0 1227 * and inline, a menu router item may specify:
danielebarchiesi@0 1228 * @code
danielebarchiesi@0 1229 * 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
danielebarchiesi@0 1230 * @endcode
danielebarchiesi@0 1231 * - "tab_parent": For local task menu items, the path of the task's parent
danielebarchiesi@0 1232 * item; defaults to the same path without the last component (e.g., the
danielebarchiesi@0 1233 * default parent for 'admin/people/create' is 'admin/people').
danielebarchiesi@0 1234 * - "tab_root": For local task menu items, the path of the closest non-tab
danielebarchiesi@0 1235 * item; same default as "tab_parent".
danielebarchiesi@0 1236 * - "position": Position of the block ('left' or 'right') on the system
danielebarchiesi@0 1237 * administration page for this item.
danielebarchiesi@0 1238 * - "type": A bitmask of flags describing properties of the menu item.
danielebarchiesi@0 1239 * Many shortcut bitmasks are provided as constants in menu.inc:
danielebarchiesi@0 1240 * - MENU_NORMAL_ITEM: Normal menu items show up in the menu tree and can be
danielebarchiesi@0 1241 * moved/hidden by the administrator.
danielebarchiesi@0 1242 * - MENU_CALLBACK: Callbacks simply register a path so that the correct
danielebarchiesi@0 1243 * information is generated when the path is accessed.
danielebarchiesi@0 1244 * - MENU_SUGGESTED_ITEM: Modules may "suggest" menu items that the
danielebarchiesi@0 1245 * administrator may enable.
danielebarchiesi@0 1246 * - MENU_LOCAL_ACTION: Local actions are menu items that describe actions
danielebarchiesi@0 1247 * on the parent item such as adding a new user or block, and are
danielebarchiesi@0 1248 * rendered in the action-links list in your theme.
danielebarchiesi@0 1249 * - MENU_LOCAL_TASK: Local tasks are menu items that describe different
danielebarchiesi@0 1250 * displays of data, and are generally rendered as tabs.
danielebarchiesi@0 1251 * - MENU_DEFAULT_LOCAL_TASK: Every set of local tasks should provide one
danielebarchiesi@0 1252 * "default" task, which should display the same page as the parent item.
danielebarchiesi@0 1253 * If the "type" element is omitted, MENU_NORMAL_ITEM is assumed.
danielebarchiesi@0 1254 * - "options": An array of options to be passed to l() when generating a link
danielebarchiesi@0 1255 * from this menu item. Note that the "options" parameter has no effect on
danielebarchiesi@0 1256 * MENU_LOCAL_TASK, MENU_DEFAULT_LOCAL_TASK, and MENU_LOCAL_ACTION items.
danielebarchiesi@0 1257 *
danielebarchiesi@0 1258 * For a detailed usage example, see page_example.module.
danielebarchiesi@0 1259 * For comprehensive documentation on the menu system, see
danielebarchiesi@0 1260 * http://drupal.org/node/102338.
danielebarchiesi@0 1261 */
danielebarchiesi@0 1262 function hook_menu() {
danielebarchiesi@0 1263 $items['example'] = array(
danielebarchiesi@0 1264 'title' => 'Example Page',
danielebarchiesi@0 1265 'page callback' => 'example_page',
danielebarchiesi@0 1266 'access arguments' => array('access content'),
danielebarchiesi@0 1267 'type' => MENU_SUGGESTED_ITEM,
danielebarchiesi@0 1268 );
danielebarchiesi@0 1269 $items['example/feed'] = array(
danielebarchiesi@0 1270 'title' => 'Example RSS feed',
danielebarchiesi@0 1271 'page callback' => 'example_feed',
danielebarchiesi@0 1272 'access arguments' => array('access content'),
danielebarchiesi@0 1273 'type' => MENU_CALLBACK,
danielebarchiesi@0 1274 );
danielebarchiesi@0 1275
danielebarchiesi@0 1276 return $items;
danielebarchiesi@0 1277 }
danielebarchiesi@0 1278
danielebarchiesi@0 1279 /**
danielebarchiesi@0 1280 * Alter the data being saved to the {menu_router} table after hook_menu is invoked.
danielebarchiesi@0 1281 *
danielebarchiesi@0 1282 * This hook is invoked by menu_router_build(). The menu definitions are passed
danielebarchiesi@0 1283 * in by reference. Each element of the $items array is one item returned
danielebarchiesi@0 1284 * by a module from hook_menu. Additional items may be added, or existing items
danielebarchiesi@0 1285 * altered.
danielebarchiesi@0 1286 *
danielebarchiesi@0 1287 * @param $items
danielebarchiesi@0 1288 * Associative array of menu router definitions returned from hook_menu().
danielebarchiesi@0 1289 */
danielebarchiesi@0 1290 function hook_menu_alter(&$items) {
danielebarchiesi@0 1291 // Example - disable the page at node/add
danielebarchiesi@0 1292 $items['node/add']['access callback'] = FALSE;
danielebarchiesi@0 1293 }
danielebarchiesi@0 1294
danielebarchiesi@0 1295 /**
danielebarchiesi@0 1296 * Alter the data being saved to the {menu_links} table by menu_link_save().
danielebarchiesi@0 1297 *
danielebarchiesi@0 1298 * @param $item
danielebarchiesi@0 1299 * Associative array defining a menu link as passed into menu_link_save().
danielebarchiesi@0 1300 *
danielebarchiesi@0 1301 * @see hook_translated_menu_link_alter()
danielebarchiesi@0 1302 */
danielebarchiesi@0 1303 function hook_menu_link_alter(&$item) {
danielebarchiesi@0 1304 // Make all new admin links hidden (a.k.a disabled).
danielebarchiesi@0 1305 if (strpos($item['link_path'], 'admin') === 0 && empty($item['mlid'])) {
danielebarchiesi@0 1306 $item['hidden'] = 1;
danielebarchiesi@0 1307 }
danielebarchiesi@0 1308 // Flag a link to be altered by hook_translated_menu_link_alter().
danielebarchiesi@0 1309 if ($item['link_path'] == 'devel/cache/clear') {
danielebarchiesi@0 1310 $item['options']['alter'] = TRUE;
danielebarchiesi@0 1311 }
danielebarchiesi@0 1312 // Flag a link to be altered by hook_translated_menu_link_alter(), but only
danielebarchiesi@0 1313 // if it is derived from a menu router item; i.e., do not alter a custom
danielebarchiesi@0 1314 // menu link pointing to the same path that has been created by a user.
danielebarchiesi@0 1315 if ($item['link_path'] == 'user' && $item['module'] == 'system') {
danielebarchiesi@0 1316 $item['options']['alter'] = TRUE;
danielebarchiesi@0 1317 }
danielebarchiesi@0 1318 }
danielebarchiesi@0 1319
danielebarchiesi@0 1320 /**
danielebarchiesi@0 1321 * Alter a menu link after it has been translated and before it is rendered.
danielebarchiesi@0 1322 *
danielebarchiesi@0 1323 * This hook is invoked from _menu_link_translate() after a menu link has been
danielebarchiesi@0 1324 * translated; i.e., after dynamic path argument placeholders (%) have been
danielebarchiesi@0 1325 * replaced with actual values, the user access to the link's target page has
danielebarchiesi@0 1326 * been checked, and the link has been localized. It is only invoked if
danielebarchiesi@0 1327 * $item['options']['alter'] has been set to a non-empty value (e.g., TRUE).
danielebarchiesi@0 1328 * This flag should be set using hook_menu_link_alter().
danielebarchiesi@0 1329 *
danielebarchiesi@0 1330 * Implementations of this hook are able to alter any property of the menu link.
danielebarchiesi@0 1331 * For example, this hook may be used to add a page-specific query string to all
danielebarchiesi@0 1332 * menu links, or hide a certain link by setting:
danielebarchiesi@0 1333 * @code
danielebarchiesi@0 1334 * 'hidden' => 1,
danielebarchiesi@0 1335 * @endcode
danielebarchiesi@0 1336 *
danielebarchiesi@0 1337 * @param $item
danielebarchiesi@0 1338 * Associative array defining a menu link after _menu_link_translate()
danielebarchiesi@0 1339 * @param $map
danielebarchiesi@0 1340 * Associative array containing the menu $map (path parts and/or objects).
danielebarchiesi@0 1341 *
danielebarchiesi@0 1342 * @see hook_menu_link_alter()
danielebarchiesi@0 1343 */
danielebarchiesi@0 1344 function hook_translated_menu_link_alter(&$item, $map) {
danielebarchiesi@0 1345 if ($item['href'] == 'devel/cache/clear') {
danielebarchiesi@0 1346 $item['localized_options']['query'] = drupal_get_destination();
danielebarchiesi@0 1347 }
danielebarchiesi@0 1348 }
danielebarchiesi@0 1349
danielebarchiesi@0 1350 /**
danielebarchiesi@0 1351 * Inform modules that a menu link has been created.
danielebarchiesi@0 1352 *
danielebarchiesi@0 1353 * This hook is used to notify modules that menu items have been
danielebarchiesi@0 1354 * created. Contributed modules may use the information to perform
danielebarchiesi@0 1355 * actions based on the information entered into the menu system.
danielebarchiesi@0 1356 *
danielebarchiesi@0 1357 * @param $link
danielebarchiesi@0 1358 * Associative array defining a menu link as passed into menu_link_save().
danielebarchiesi@0 1359 *
danielebarchiesi@0 1360 * @see hook_menu_link_update()
danielebarchiesi@0 1361 * @see hook_menu_link_delete()
danielebarchiesi@0 1362 */
danielebarchiesi@0 1363 function hook_menu_link_insert($link) {
danielebarchiesi@0 1364 // In our sample case, we track menu items as editing sections
danielebarchiesi@0 1365 // of the site. These are stored in our table as 'disabled' items.
danielebarchiesi@0 1366 $record['mlid'] = $link['mlid'];
danielebarchiesi@0 1367 $record['menu_name'] = $link['menu_name'];
danielebarchiesi@0 1368 $record['status'] = 0;
danielebarchiesi@0 1369 drupal_write_record('menu_example', $record);
danielebarchiesi@0 1370 }
danielebarchiesi@0 1371
danielebarchiesi@0 1372 /**
danielebarchiesi@0 1373 * Inform modules that a menu link has been updated.
danielebarchiesi@0 1374 *
danielebarchiesi@0 1375 * This hook is used to notify modules that menu items have been
danielebarchiesi@0 1376 * updated. Contributed modules may use the information to perform
danielebarchiesi@0 1377 * actions based on the information entered into the menu system.
danielebarchiesi@0 1378 *
danielebarchiesi@0 1379 * @param $link
danielebarchiesi@0 1380 * Associative array defining a menu link as passed into menu_link_save().
danielebarchiesi@0 1381 *
danielebarchiesi@0 1382 * @see hook_menu_link_insert()
danielebarchiesi@0 1383 * @see hook_menu_link_delete()
danielebarchiesi@0 1384 */
danielebarchiesi@0 1385 function hook_menu_link_update($link) {
danielebarchiesi@0 1386 // If the parent menu has changed, update our record.
danielebarchiesi@0 1387 $menu_name = db_query("SELECT menu_name FROM {menu_example} WHERE mlid = :mlid", array(':mlid' => $link['mlid']))->fetchField();
danielebarchiesi@0 1388 if ($menu_name != $link['menu_name']) {
danielebarchiesi@0 1389 db_update('menu_example')
danielebarchiesi@0 1390 ->fields(array('menu_name' => $link['menu_name']))
danielebarchiesi@0 1391 ->condition('mlid', $link['mlid'])
danielebarchiesi@0 1392 ->execute();
danielebarchiesi@0 1393 }
danielebarchiesi@0 1394 }
danielebarchiesi@0 1395
danielebarchiesi@0 1396 /**
danielebarchiesi@0 1397 * Inform modules that a menu link has been deleted.
danielebarchiesi@0 1398 *
danielebarchiesi@0 1399 * This hook is used to notify modules that menu items have been
danielebarchiesi@0 1400 * deleted. Contributed modules may use the information to perform
danielebarchiesi@0 1401 * actions based on the information entered into the menu system.
danielebarchiesi@0 1402 *
danielebarchiesi@0 1403 * @param $link
danielebarchiesi@0 1404 * Associative array defining a menu link as passed into menu_link_save().
danielebarchiesi@0 1405 *
danielebarchiesi@0 1406 * @see hook_menu_link_insert()
danielebarchiesi@0 1407 * @see hook_menu_link_update()
danielebarchiesi@0 1408 */
danielebarchiesi@0 1409 function hook_menu_link_delete($link) {
danielebarchiesi@0 1410 // Delete the record from our table.
danielebarchiesi@0 1411 db_delete('menu_example')
danielebarchiesi@0 1412 ->condition('mlid', $link['mlid'])
danielebarchiesi@0 1413 ->execute();
danielebarchiesi@0 1414 }
danielebarchiesi@0 1415
danielebarchiesi@0 1416 /**
danielebarchiesi@0 1417 * Alter tabs and actions displayed on the page before they are rendered.
danielebarchiesi@0 1418 *
danielebarchiesi@0 1419 * This hook is invoked by menu_local_tasks(). The system-determined tabs and
danielebarchiesi@0 1420 * actions are passed in by reference. Additional tabs or actions may be added,
danielebarchiesi@0 1421 * or existing items altered.
danielebarchiesi@0 1422 *
danielebarchiesi@0 1423 * Each tab or action is an associative array containing:
danielebarchiesi@0 1424 * - #theme: The theme function to use to render.
danielebarchiesi@0 1425 * - #link: An associative array containing:
danielebarchiesi@0 1426 * - title: The localized title of the link.
danielebarchiesi@0 1427 * - href: The system path to link to.
danielebarchiesi@0 1428 * - localized_options: An array of options to pass to l().
danielebarchiesi@0 1429 * - #active: Whether the link should be marked as 'active'.
danielebarchiesi@0 1430 *
danielebarchiesi@0 1431 * @param $data
danielebarchiesi@0 1432 * An associative array containing:
danielebarchiesi@0 1433 * - actions: An associative array containing:
danielebarchiesi@0 1434 * - count: The amount of actions determined by the menu system, which can
danielebarchiesi@0 1435 * be ignored.
danielebarchiesi@0 1436 * - output: A list of of actions, each one being an associative array
danielebarchiesi@0 1437 * as described above.
danielebarchiesi@0 1438 * - tabs: An indexed array (list) of tab levels (up to 2 levels), each
danielebarchiesi@0 1439 * containing an associative array:
danielebarchiesi@0 1440 * - count: The amount of tabs determined by the menu system. This value
danielebarchiesi@0 1441 * does not need to be altered if there is more than one tab.
danielebarchiesi@0 1442 * - output: A list of of tabs, each one being an associative array as
danielebarchiesi@0 1443 * described above.
danielebarchiesi@0 1444 * @param $router_item
danielebarchiesi@0 1445 * The menu system router item of the page.
danielebarchiesi@0 1446 * @param $root_path
danielebarchiesi@0 1447 * The path to the root item for this set of tabs.
danielebarchiesi@0 1448 */
danielebarchiesi@0 1449 function hook_menu_local_tasks_alter(&$data, $router_item, $root_path) {
danielebarchiesi@0 1450 // Add an action linking to node/add to all pages.
danielebarchiesi@0 1451 $data['actions']['output'][] = array(
danielebarchiesi@0 1452 '#theme' => 'menu_local_task',
danielebarchiesi@0 1453 '#link' => array(
danielebarchiesi@0 1454 'title' => t('Add new content'),
danielebarchiesi@0 1455 'href' => 'node/add',
danielebarchiesi@0 1456 'localized_options' => array(
danielebarchiesi@0 1457 'attributes' => array(
danielebarchiesi@0 1458 'title' => t('Add new content'),
danielebarchiesi@0 1459 ),
danielebarchiesi@0 1460 ),
danielebarchiesi@0 1461 ),
danielebarchiesi@0 1462 );
danielebarchiesi@0 1463
danielebarchiesi@0 1464 // Add a tab linking to node/add to all pages.
danielebarchiesi@0 1465 $data['tabs'][0]['output'][] = array(
danielebarchiesi@0 1466 '#theme' => 'menu_local_task',
danielebarchiesi@0 1467 '#link' => array(
danielebarchiesi@0 1468 'title' => t('Example tab'),
danielebarchiesi@0 1469 'href' => 'node/add',
danielebarchiesi@0 1470 'localized_options' => array(
danielebarchiesi@0 1471 'attributes' => array(
danielebarchiesi@0 1472 'title' => t('Add new content'),
danielebarchiesi@0 1473 ),
danielebarchiesi@0 1474 ),
danielebarchiesi@0 1475 ),
danielebarchiesi@0 1476 // Define whether this link is active. This can be omitted for
danielebarchiesi@0 1477 // implementations that add links to pages outside of the current page
danielebarchiesi@0 1478 // context.
danielebarchiesi@0 1479 '#active' => ($router_item['path'] == $root_path),
danielebarchiesi@0 1480 );
danielebarchiesi@0 1481 }
danielebarchiesi@0 1482
danielebarchiesi@0 1483 /**
danielebarchiesi@0 1484 * Alter links in the active trail before it is rendered as the breadcrumb.
danielebarchiesi@0 1485 *
danielebarchiesi@0 1486 * This hook is invoked by menu_get_active_breadcrumb() and allows alteration
danielebarchiesi@0 1487 * of the breadcrumb links for the current page, which may be preferred instead
danielebarchiesi@0 1488 * of setting a custom breadcrumb via drupal_set_breadcrumb().
danielebarchiesi@0 1489 *
danielebarchiesi@0 1490 * Implementations should take into account that menu_get_active_breadcrumb()
danielebarchiesi@0 1491 * subsequently performs the following adjustments to the active trail *after*
danielebarchiesi@0 1492 * this hook has been invoked:
danielebarchiesi@0 1493 * - The last link in $active_trail is removed, if its 'href' is identical to
danielebarchiesi@0 1494 * the 'href' of $item. This happens, because the breadcrumb normally does
danielebarchiesi@0 1495 * not contain a link to the current page.
danielebarchiesi@0 1496 * - The (second to) last link in $active_trail is removed, if the current $item
danielebarchiesi@0 1497 * is a MENU_DEFAULT_LOCAL_TASK. This happens in order to do not show a link
danielebarchiesi@0 1498 * to the current page, when being on the path for the default local task;
danielebarchiesi@0 1499 * e.g. when being on the path node/%/view, the breadcrumb should not contain
danielebarchiesi@0 1500 * a link to node/%.
danielebarchiesi@0 1501 *
danielebarchiesi@0 1502 * Each link in the active trail must contain:
danielebarchiesi@0 1503 * - title: The localized title of the link.
danielebarchiesi@0 1504 * - href: The system path to link to.
danielebarchiesi@0 1505 * - localized_options: An array of options to pass to url().
danielebarchiesi@0 1506 *
danielebarchiesi@0 1507 * @param $active_trail
danielebarchiesi@0 1508 * An array containing breadcrumb links for the current page.
danielebarchiesi@0 1509 * @param $item
danielebarchiesi@0 1510 * The menu router item of the current page.
danielebarchiesi@0 1511 *
danielebarchiesi@0 1512 * @see drupal_set_breadcrumb()
danielebarchiesi@0 1513 * @see menu_get_active_breadcrumb()
danielebarchiesi@0 1514 * @see menu_get_active_trail()
danielebarchiesi@0 1515 * @see menu_set_active_trail()
danielebarchiesi@0 1516 */
danielebarchiesi@0 1517 function hook_menu_breadcrumb_alter(&$active_trail, $item) {
danielebarchiesi@0 1518 // Always display a link to the current page by duplicating the last link in
danielebarchiesi@0 1519 // the active trail. This means that menu_get_active_breadcrumb() will remove
danielebarchiesi@0 1520 // the last link (for the current page), but since it is added once more here,
danielebarchiesi@0 1521 // it will appear.
danielebarchiesi@0 1522 if (!drupal_is_front_page()) {
danielebarchiesi@0 1523 $end = end($active_trail);
danielebarchiesi@0 1524 if ($item['href'] == $end['href']) {
danielebarchiesi@0 1525 $active_trail[] = $end;
danielebarchiesi@0 1526 }
danielebarchiesi@0 1527 }
danielebarchiesi@0 1528 }
danielebarchiesi@0 1529
danielebarchiesi@0 1530 /**
danielebarchiesi@0 1531 * Alter contextual links before they are rendered.
danielebarchiesi@0 1532 *
danielebarchiesi@0 1533 * This hook is invoked by menu_contextual_links(). The system-determined
danielebarchiesi@0 1534 * contextual links are passed in by reference. Additional links may be added
danielebarchiesi@0 1535 * or existing links can be altered.
danielebarchiesi@0 1536 *
danielebarchiesi@0 1537 * Each contextual link must at least contain:
danielebarchiesi@0 1538 * - title: The localized title of the link.
danielebarchiesi@0 1539 * - href: The system path to link to.
danielebarchiesi@0 1540 * - localized_options: An array of options to pass to url().
danielebarchiesi@0 1541 *
danielebarchiesi@0 1542 * @param $links
danielebarchiesi@0 1543 * An associative array containing contextual links for the given $root_path,
danielebarchiesi@0 1544 * as described above. The array keys are used to build CSS class names for
danielebarchiesi@0 1545 * contextual links and must therefore be unique for each set of contextual
danielebarchiesi@0 1546 * links.
danielebarchiesi@0 1547 * @param $router_item
danielebarchiesi@0 1548 * The menu router item belonging to the $root_path being requested.
danielebarchiesi@0 1549 * @param $root_path
danielebarchiesi@0 1550 * The (parent) path that has been requested to build contextual links for.
danielebarchiesi@0 1551 * This is a normalized path, which means that an originally passed path of
danielebarchiesi@0 1552 * 'node/123' became 'node/%'.
danielebarchiesi@0 1553 *
danielebarchiesi@0 1554 * @see hook_contextual_links_view_alter()
danielebarchiesi@0 1555 * @see menu_contextual_links()
danielebarchiesi@0 1556 * @see hook_menu()
danielebarchiesi@0 1557 * @see contextual_preprocess()
danielebarchiesi@0 1558 */
danielebarchiesi@0 1559 function hook_menu_contextual_links_alter(&$links, $router_item, $root_path) {
danielebarchiesi@0 1560 // Add a link to all contextual links for nodes.
danielebarchiesi@0 1561 if ($root_path == 'node/%') {
danielebarchiesi@0 1562 $links['foo'] = array(
danielebarchiesi@0 1563 'title' => t('Do fu'),
danielebarchiesi@0 1564 'href' => 'foo/do',
danielebarchiesi@0 1565 'localized_options' => array(
danielebarchiesi@0 1566 'query' => array(
danielebarchiesi@0 1567 'foo' => 'bar',
danielebarchiesi@0 1568 ),
danielebarchiesi@0 1569 ),
danielebarchiesi@0 1570 );
danielebarchiesi@0 1571 }
danielebarchiesi@0 1572 }
danielebarchiesi@0 1573
danielebarchiesi@0 1574 /**
danielebarchiesi@0 1575 * Perform alterations before a page is rendered.
danielebarchiesi@0 1576 *
danielebarchiesi@0 1577 * Use this hook when you want to remove or alter elements at the page
danielebarchiesi@0 1578 * level, or add elements at the page level that depend on an other module's
danielebarchiesi@0 1579 * elements (this hook runs after hook_page_build().
danielebarchiesi@0 1580 *
danielebarchiesi@0 1581 * If you are making changes to entities such as forms, menus, or user
danielebarchiesi@0 1582 * profiles, use those objects' native alter hooks instead (hook_form_alter(),
danielebarchiesi@0 1583 * for example).
danielebarchiesi@0 1584 *
danielebarchiesi@0 1585 * The $page array contains top level elements for each block region:
danielebarchiesi@0 1586 * @code
danielebarchiesi@0 1587 * $page['page_top']
danielebarchiesi@0 1588 * $page['header']
danielebarchiesi@0 1589 * $page['sidebar_first']
danielebarchiesi@0 1590 * $page['content']
danielebarchiesi@0 1591 * $page['sidebar_second']
danielebarchiesi@0 1592 * $page['page_bottom']
danielebarchiesi@0 1593 * @endcode
danielebarchiesi@0 1594 *
danielebarchiesi@0 1595 * The 'content' element contains the main content of the current page, and its
danielebarchiesi@0 1596 * structure will vary depending on what module is responsible for building the
danielebarchiesi@0 1597 * page. Some legacy modules may not return structured content at all: their
danielebarchiesi@0 1598 * pre-rendered markup will be located in $page['content']['main']['#markup'].
danielebarchiesi@0 1599 *
danielebarchiesi@0 1600 * Pages built by Drupal's core Node and Blog modules use a standard structure:
danielebarchiesi@0 1601 *
danielebarchiesi@0 1602 * @code
danielebarchiesi@0 1603 * // Node body.
danielebarchiesi@0 1604 * $page['content']['system_main']['nodes'][$nid]['body']
danielebarchiesi@0 1605 * // Array of links attached to the node (add comments, read more).
danielebarchiesi@0 1606 * $page['content']['system_main']['nodes'][$nid]['links']
danielebarchiesi@0 1607 * // The node object itself.
danielebarchiesi@0 1608 * $page['content']['system_main']['nodes'][$nid]['#node']
danielebarchiesi@0 1609 * // The results pager.
danielebarchiesi@0 1610 * $page['content']['system_main']['pager']
danielebarchiesi@0 1611 * @endcode
danielebarchiesi@0 1612 *
danielebarchiesi@0 1613 * Blocks may be referenced by their module/delta pair within a region:
danielebarchiesi@0 1614 * @code
danielebarchiesi@0 1615 * // The login block in the first sidebar region.
danielebarchiesi@0 1616 * $page['sidebar_first']['user_login']['#block'];
danielebarchiesi@0 1617 * @endcode
danielebarchiesi@0 1618 *
danielebarchiesi@0 1619 * @param $page
danielebarchiesi@0 1620 * Nested array of renderable elements that make up the page.
danielebarchiesi@0 1621 *
danielebarchiesi@0 1622 * @see hook_page_build()
danielebarchiesi@0 1623 * @see drupal_render_page()
danielebarchiesi@0 1624 */
danielebarchiesi@0 1625 function hook_page_alter(&$page) {
danielebarchiesi@0 1626 // Add help text to the user login block.
danielebarchiesi@0 1627 $page['sidebar_first']['user_login']['help'] = array(
danielebarchiesi@0 1628 '#weight' => -10,
danielebarchiesi@0 1629 '#markup' => t('To post comments or add new content, you first have to log in.'),
danielebarchiesi@0 1630 );
danielebarchiesi@0 1631 }
danielebarchiesi@0 1632
danielebarchiesi@0 1633 /**
danielebarchiesi@0 1634 * Perform alterations before a form is rendered.
danielebarchiesi@0 1635 *
danielebarchiesi@0 1636 * One popular use of this hook is to add form elements to the node form. When
danielebarchiesi@0 1637 * altering a node form, the node object can be accessed at $form['#node'].
danielebarchiesi@0 1638 *
danielebarchiesi@0 1639 * In addition to hook_form_alter(), which is called for all forms, there are
danielebarchiesi@0 1640 * two more specific form hooks available. The first,
danielebarchiesi@0 1641 * hook_form_BASE_FORM_ID_alter(), allows targeting of a form/forms via a base
danielebarchiesi@0 1642 * form (if one exists). The second, hook_form_FORM_ID_alter(), can be used to
danielebarchiesi@0 1643 * target a specific form directly.
danielebarchiesi@0 1644 *
danielebarchiesi@0 1645 * The call order is as follows: all existing form alter functions are called
danielebarchiesi@0 1646 * for module A, then all for module B, etc., followed by all for any base
danielebarchiesi@0 1647 * theme(s), and finally for the theme itself. The module order is determined
danielebarchiesi@0 1648 * by system weight, then by module name.
danielebarchiesi@0 1649 *
danielebarchiesi@0 1650 * Within each module, form alter hooks are called in the following order:
danielebarchiesi@0 1651 * first, hook_form_alter(); second, hook_form_BASE_FORM_ID_alter(); third,
danielebarchiesi@0 1652 * hook_form_FORM_ID_alter(). So, for each module, the more general hooks are
danielebarchiesi@0 1653 * called first followed by the more specific.
danielebarchiesi@0 1654 *
danielebarchiesi@0 1655 * @param $form
danielebarchiesi@0 1656 * Nested array of form elements that comprise the form.
danielebarchiesi@0 1657 * @param $form_state
danielebarchiesi@0 1658 * A keyed array containing the current state of the form. The arguments
danielebarchiesi@0 1659 * that drupal_get_form() was originally called with are available in the
danielebarchiesi@0 1660 * array $form_state['build_info']['args'].
danielebarchiesi@0 1661 * @param $form_id
danielebarchiesi@0 1662 * String representing the name of the form itself. Typically this is the
danielebarchiesi@0 1663 * name of the function that generated the form.
danielebarchiesi@0 1664 *
danielebarchiesi@0 1665 * @see hook_form_BASE_FORM_ID_alter()
danielebarchiesi@0 1666 * @see hook_form_FORM_ID_alter()
danielebarchiesi@0 1667 * @see forms_api_reference.html
danielebarchiesi@0 1668 */
danielebarchiesi@0 1669 function hook_form_alter(&$form, &$form_state, $form_id) {
danielebarchiesi@0 1670 if (isset($form['type']) && $form['type']['#value'] . '_node_settings' == $form_id) {
danielebarchiesi@0 1671 $form['workflow']['upload_' . $form['type']['#value']] = array(
danielebarchiesi@0 1672 '#type' => 'radios',
danielebarchiesi@0 1673 '#title' => t('Attachments'),
danielebarchiesi@0 1674 '#default_value' => variable_get('upload_' . $form['type']['#value'], 1),
danielebarchiesi@0 1675 '#options' => array(t('Disabled'), t('Enabled')),
danielebarchiesi@0 1676 );
danielebarchiesi@0 1677 }
danielebarchiesi@0 1678 }
danielebarchiesi@0 1679
danielebarchiesi@0 1680 /**
danielebarchiesi@0 1681 * Provide a form-specific alteration instead of the global hook_form_alter().
danielebarchiesi@0 1682 *
danielebarchiesi@0 1683 * Modules can implement hook_form_FORM_ID_alter() to modify a specific form,
danielebarchiesi@0 1684 * rather than implementing hook_form_alter() and checking the form ID, or
danielebarchiesi@0 1685 * using long switch statements to alter multiple forms.
danielebarchiesi@0 1686 *
danielebarchiesi@0 1687 * Form alter hooks are called in the following order: hook_form_alter(),
danielebarchiesi@0 1688 * hook_form_BASE_FORM_ID_alter(), hook_form_FORM_ID_alter(). See
danielebarchiesi@0 1689 * hook_form_alter() for more details.
danielebarchiesi@0 1690 *
danielebarchiesi@0 1691 * @param $form
danielebarchiesi@0 1692 * Nested array of form elements that comprise the form.
danielebarchiesi@0 1693 * @param $form_state
danielebarchiesi@0 1694 * A keyed array containing the current state of the form. The arguments
danielebarchiesi@0 1695 * that drupal_get_form() was originally called with are available in the
danielebarchiesi@0 1696 * array $form_state['build_info']['args'].
danielebarchiesi@0 1697 * @param $form_id
danielebarchiesi@0 1698 * String representing the name of the form itself. Typically this is the
danielebarchiesi@0 1699 * name of the function that generated the form.
danielebarchiesi@0 1700 *
danielebarchiesi@0 1701 * @see hook_form_alter()
danielebarchiesi@0 1702 * @see hook_form_BASE_FORM_ID_alter()
danielebarchiesi@0 1703 * @see drupal_prepare_form()
danielebarchiesi@0 1704 * @see forms_api_reference.html
danielebarchiesi@0 1705 */
danielebarchiesi@0 1706 function hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
danielebarchiesi@0 1707 // Modification for the form with the given form ID goes here. For example, if
danielebarchiesi@0 1708 // FORM_ID is "user_register_form" this code would run only on the user
danielebarchiesi@0 1709 // registration form.
danielebarchiesi@0 1710
danielebarchiesi@0 1711 // Add a checkbox to registration form about agreeing to terms of use.
danielebarchiesi@0 1712 $form['terms_of_use'] = array(
danielebarchiesi@0 1713 '#type' => 'checkbox',
danielebarchiesi@0 1714 '#title' => t("I agree with the website's terms and conditions."),
danielebarchiesi@0 1715 '#required' => TRUE,
danielebarchiesi@0 1716 );
danielebarchiesi@0 1717 }
danielebarchiesi@0 1718
danielebarchiesi@0 1719 /**
danielebarchiesi@0 1720 * Provide a form-specific alteration for shared ('base') forms.
danielebarchiesi@0 1721 *
danielebarchiesi@0 1722 * By default, when drupal_get_form() is called, Drupal looks for a function
danielebarchiesi@0 1723 * with the same name as the form ID, and uses that function to build the form.
danielebarchiesi@0 1724 * In contrast, base forms allow multiple form IDs to be mapped to a single base
danielebarchiesi@0 1725 * (also called 'factory') form function.
danielebarchiesi@0 1726 *
danielebarchiesi@0 1727 * Modules can implement hook_form_BASE_FORM_ID_alter() to modify a specific
danielebarchiesi@0 1728 * base form, rather than implementing hook_form_alter() and checking for
danielebarchiesi@0 1729 * conditions that would identify the shared form constructor.
danielebarchiesi@0 1730 *
danielebarchiesi@0 1731 * To identify the base form ID for a particular form (or to determine whether
danielebarchiesi@0 1732 * one exists) check the $form_state. The base form ID is stored under
danielebarchiesi@0 1733 * $form_state['build_info']['base_form_id'].
danielebarchiesi@0 1734 *
danielebarchiesi@0 1735 * See hook_forms() for more information on how to implement base forms in
danielebarchiesi@0 1736 * Drupal.
danielebarchiesi@0 1737 *
danielebarchiesi@0 1738 * Form alter hooks are called in the following order: hook_form_alter(),
danielebarchiesi@0 1739 * hook_form_BASE_FORM_ID_alter(), hook_form_FORM_ID_alter(). See
danielebarchiesi@0 1740 * hook_form_alter() for more details.
danielebarchiesi@0 1741 *
danielebarchiesi@0 1742 * @param $form
danielebarchiesi@0 1743 * Nested array of form elements that comprise the form.
danielebarchiesi@0 1744 * @param $form_state
danielebarchiesi@0 1745 * A keyed array containing the current state of the form.
danielebarchiesi@0 1746 * @param $form_id
danielebarchiesi@0 1747 * String representing the name of the form itself. Typically this is the
danielebarchiesi@0 1748 * name of the function that generated the form.
danielebarchiesi@0 1749 *
danielebarchiesi@0 1750 * @see hook_form_alter()
danielebarchiesi@0 1751 * @see hook_form_FORM_ID_alter()
danielebarchiesi@0 1752 * @see drupal_prepare_form()
danielebarchiesi@0 1753 * @see hook_forms()
danielebarchiesi@0 1754 */
danielebarchiesi@0 1755 function hook_form_BASE_FORM_ID_alter(&$form, &$form_state, $form_id) {
danielebarchiesi@0 1756 // Modification for the form with the given BASE_FORM_ID goes here. For
danielebarchiesi@0 1757 // example, if BASE_FORM_ID is "node_form", this code would run on every
danielebarchiesi@0 1758 // node form, regardless of node type.
danielebarchiesi@0 1759
danielebarchiesi@0 1760 // Add a checkbox to the node form about agreeing to terms of use.
danielebarchiesi@0 1761 $form['terms_of_use'] = array(
danielebarchiesi@0 1762 '#type' => 'checkbox',
danielebarchiesi@0 1763 '#title' => t("I agree with the website's terms and conditions."),
danielebarchiesi@0 1764 '#required' => TRUE,
danielebarchiesi@0 1765 );
danielebarchiesi@0 1766 }
danielebarchiesi@0 1767
danielebarchiesi@0 1768 /**
danielebarchiesi@0 1769 * Map form_ids to form builder functions.
danielebarchiesi@0 1770 *
danielebarchiesi@0 1771 * By default, when drupal_get_form() is called, the system will look for a
danielebarchiesi@0 1772 * function with the same name as the form ID, and use that function to build
danielebarchiesi@0 1773 * the form. If no such function is found, Drupal calls this hook. Modules
danielebarchiesi@0 1774 * implementing this hook can then provide their own instructions for mapping
danielebarchiesi@0 1775 * form IDs to constructor functions. As a result, you can easily map multiple
danielebarchiesi@0 1776 * form IDs to a single form constructor (referred to as a 'base' form).
danielebarchiesi@0 1777 *
danielebarchiesi@0 1778 * Using a base form can help to avoid code duplication, by allowing many
danielebarchiesi@0 1779 * similar forms to use the same code base. Another benefit is that it becomes
danielebarchiesi@0 1780 * much easier for other modules to apply a general change to the group of
danielebarchiesi@0 1781 * forms; hook_form_BASE_FORM_ID_alter() can be used to easily alter multiple
danielebarchiesi@0 1782 * forms at once by directly targeting the shared base form.
danielebarchiesi@0 1783 *
danielebarchiesi@0 1784 * Two example use cases where base forms may be useful are given below.
danielebarchiesi@0 1785 *
danielebarchiesi@0 1786 * First, you can use this hook to tell the form system to use a different
danielebarchiesi@0 1787 * function to build certain forms in your module; this is often used to define
danielebarchiesi@0 1788 * a form "factory" function that is used to build several similar forms. In
danielebarchiesi@0 1789 * this case, your hook implementation will likely ignore all of the input
danielebarchiesi@0 1790 * arguments. See node_forms() for an example of this. Note, node_forms() is the
danielebarchiesi@0 1791 * hook_forms() implementation; the base form itself is defined in node_form().
danielebarchiesi@0 1792 *
danielebarchiesi@0 1793 * Second, you could use this hook to define how to build a form with a
danielebarchiesi@0 1794 * dynamically-generated form ID. In this case, you would need to verify that
danielebarchiesi@0 1795 * the $form_id input matched your module's format for dynamically-generated
danielebarchiesi@0 1796 * form IDs, and if so, act appropriately.
danielebarchiesi@0 1797 *
danielebarchiesi@0 1798 * @param $form_id
danielebarchiesi@0 1799 * The unique string identifying the desired form.
danielebarchiesi@0 1800 * @param $args
danielebarchiesi@0 1801 * An array containing the original arguments provided to drupal_get_form()
danielebarchiesi@0 1802 * or drupal_form_submit(). These are always passed to the form builder and
danielebarchiesi@0 1803 * do not have to be specified manually in 'callback arguments'.
danielebarchiesi@0 1804 *
danielebarchiesi@0 1805 * @return
danielebarchiesi@0 1806 * An associative array whose keys define form_ids and whose values are an
danielebarchiesi@0 1807 * associative array defining the following keys:
danielebarchiesi@0 1808 * - callback: The name of the form builder function to invoke. This will be
danielebarchiesi@0 1809 * used for the base form ID, for example, to target a base form using
danielebarchiesi@0 1810 * hook_form_BASE_FORM_ID_alter().
danielebarchiesi@0 1811 * - callback arguments: (optional) Additional arguments to pass to the
danielebarchiesi@0 1812 * function defined in 'callback', which are prepended to $args.
danielebarchiesi@0 1813 * - wrapper_callback: (optional) The name of a form builder function to
danielebarchiesi@0 1814 * invoke before the form builder defined in 'callback' is invoked. This
danielebarchiesi@0 1815 * wrapper callback may prepopulate the $form array with form elements,
danielebarchiesi@0 1816 * which will then be already contained in the $form that is passed on to
danielebarchiesi@0 1817 * the form builder defined in 'callback'. For example, a wrapper callback
danielebarchiesi@0 1818 * could setup wizard-alike form buttons that are the same for a variety of
danielebarchiesi@0 1819 * forms that belong to the wizard, which all share the same wrapper
danielebarchiesi@0 1820 * callback.
danielebarchiesi@0 1821 */
danielebarchiesi@0 1822 function hook_forms($form_id, $args) {
danielebarchiesi@0 1823 // Simply reroute the (non-existing) $form_id 'mymodule_first_form' to
danielebarchiesi@0 1824 // 'mymodule_main_form'.
danielebarchiesi@0 1825 $forms['mymodule_first_form'] = array(
danielebarchiesi@0 1826 'callback' => 'mymodule_main_form',
danielebarchiesi@0 1827 );
danielebarchiesi@0 1828
danielebarchiesi@0 1829 // Reroute the $form_id and prepend an additional argument that gets passed to
danielebarchiesi@0 1830 // the 'mymodule_main_form' form builder function.
danielebarchiesi@0 1831 $forms['mymodule_second_form'] = array(
danielebarchiesi@0 1832 'callback' => 'mymodule_main_form',
danielebarchiesi@0 1833 'callback arguments' => array('some parameter'),
danielebarchiesi@0 1834 );
danielebarchiesi@0 1835
danielebarchiesi@0 1836 // Reroute the $form_id, but invoke the form builder function
danielebarchiesi@0 1837 // 'mymodule_main_form_wrapper' first, so we can prepopulate the $form array
danielebarchiesi@0 1838 // that is passed to the actual form builder 'mymodule_main_form'.
danielebarchiesi@0 1839 $forms['mymodule_wrapped_form'] = array(
danielebarchiesi@0 1840 'callback' => 'mymodule_main_form',
danielebarchiesi@0 1841 'wrapper_callback' => 'mymodule_main_form_wrapper',
danielebarchiesi@0 1842 );
danielebarchiesi@0 1843
danielebarchiesi@0 1844 return $forms;
danielebarchiesi@0 1845 }
danielebarchiesi@0 1846
danielebarchiesi@0 1847 /**
danielebarchiesi@0 1848 * Perform setup tasks for all page requests.
danielebarchiesi@0 1849 *
danielebarchiesi@0 1850 * This hook is run at the beginning of the page request. It is typically
danielebarchiesi@0 1851 * used to set up global parameters that are needed later in the request.
danielebarchiesi@0 1852 *
danielebarchiesi@0 1853 * Only use this hook if your code must run even for cached page views. This
danielebarchiesi@0 1854 * hook is called before the theme, modules, or most include files are loaded
danielebarchiesi@0 1855 * into memory. It happens while Drupal is still in bootstrap mode.
danielebarchiesi@0 1856 *
danielebarchiesi@0 1857 * @see hook_init()
danielebarchiesi@0 1858 */
danielebarchiesi@0 1859 function hook_boot() {
danielebarchiesi@0 1860 // We need user_access() in the shutdown function. Make sure it gets loaded.
danielebarchiesi@0 1861 drupal_load('module', 'user');
danielebarchiesi@0 1862 drupal_register_shutdown_function('devel_shutdown');
danielebarchiesi@0 1863 }
danielebarchiesi@0 1864
danielebarchiesi@0 1865 /**
danielebarchiesi@0 1866 * Perform setup tasks for non-cached page requests.
danielebarchiesi@0 1867 *
danielebarchiesi@0 1868 * This hook is run at the beginning of the page request. It is typically
danielebarchiesi@0 1869 * used to set up global parameters that are needed later in the request.
danielebarchiesi@0 1870 * When this hook is called, the theme and all modules are already loaded in
danielebarchiesi@0 1871 * memory.
danielebarchiesi@0 1872 *
danielebarchiesi@0 1873 * This hook is not run on cached pages.
danielebarchiesi@0 1874 *
danielebarchiesi@0 1875 * To add CSS or JS that should be present on all pages, modules should not
danielebarchiesi@0 1876 * implement this hook, but declare these files in their .info file.
danielebarchiesi@0 1877 *
danielebarchiesi@0 1878 * @see hook_boot()
danielebarchiesi@0 1879 */
danielebarchiesi@0 1880 function hook_init() {
danielebarchiesi@0 1881 // Since this file should only be loaded on the front page, it cannot be
danielebarchiesi@0 1882 // declared in the info file.
danielebarchiesi@0 1883 if (drupal_is_front_page()) {
danielebarchiesi@0 1884 drupal_add_css(drupal_get_path('module', 'foo') . '/foo.css');
danielebarchiesi@0 1885 }
danielebarchiesi@0 1886 }
danielebarchiesi@0 1887
danielebarchiesi@0 1888 /**
danielebarchiesi@0 1889 * Define image toolkits provided by this module.
danielebarchiesi@0 1890 *
danielebarchiesi@0 1891 * The file which includes each toolkit's functions must be declared as part of
danielebarchiesi@0 1892 * the files array in the module .info file so that the registry will find and
danielebarchiesi@0 1893 * parse it.
danielebarchiesi@0 1894 *
danielebarchiesi@0 1895 * The toolkit's functions must be named image_toolkitname_operation().
danielebarchiesi@0 1896 * where the operation may be:
danielebarchiesi@0 1897 * - 'load': Required. See image_gd_load() for usage.
danielebarchiesi@0 1898 * - 'save': Required. See image_gd_save() for usage.
danielebarchiesi@0 1899 * - 'settings': Optional. See image_gd_settings() for usage.
danielebarchiesi@0 1900 * - 'resize': Optional. See image_gd_resize() for usage.
danielebarchiesi@0 1901 * - 'rotate': Optional. See image_gd_rotate() for usage.
danielebarchiesi@0 1902 * - 'crop': Optional. See image_gd_crop() for usage.
danielebarchiesi@0 1903 * - 'desaturate': Optional. See image_gd_desaturate() for usage.
danielebarchiesi@0 1904 *
danielebarchiesi@0 1905 * @return
danielebarchiesi@0 1906 * An array with the toolkit name as keys and sub-arrays with these keys:
danielebarchiesi@0 1907 * - 'title': A string with the toolkit's title.
danielebarchiesi@0 1908 * - 'available': A Boolean value to indicate that the toolkit is operating
danielebarchiesi@0 1909 * properly, e.g. all required libraries exist.
danielebarchiesi@0 1910 *
danielebarchiesi@0 1911 * @see system_image_toolkits()
danielebarchiesi@0 1912 */
danielebarchiesi@0 1913 function hook_image_toolkits() {
danielebarchiesi@0 1914 return array(
danielebarchiesi@0 1915 'working' => array(
danielebarchiesi@0 1916 'title' => t('A toolkit that works.'),
danielebarchiesi@0 1917 'available' => TRUE,
danielebarchiesi@0 1918 ),
danielebarchiesi@0 1919 'broken' => array(
danielebarchiesi@0 1920 'title' => t('A toolkit that is "broken" and will not be listed.'),
danielebarchiesi@0 1921 'available' => FALSE,
danielebarchiesi@0 1922 ),
danielebarchiesi@0 1923 );
danielebarchiesi@0 1924 }
danielebarchiesi@0 1925
danielebarchiesi@0 1926 /**
danielebarchiesi@0 1927 * Alter an email message created with the drupal_mail() function.
danielebarchiesi@0 1928 *
danielebarchiesi@0 1929 * hook_mail_alter() allows modification of email messages created and sent
danielebarchiesi@0 1930 * with drupal_mail(). Usage examples include adding and/or changing message
danielebarchiesi@0 1931 * text, message fields, and message headers.
danielebarchiesi@0 1932 *
danielebarchiesi@0 1933 * Email messages sent using functions other than drupal_mail() will not
danielebarchiesi@0 1934 * invoke hook_mail_alter(). For example, a contributed module directly
danielebarchiesi@0 1935 * calling the drupal_mail_system()->mail() or PHP mail() function
danielebarchiesi@0 1936 * will not invoke this hook. All core modules use drupal_mail() for
danielebarchiesi@0 1937 * messaging, it is best practice but not mandatory in contributed modules.
danielebarchiesi@0 1938 *
danielebarchiesi@0 1939 * @param $message
danielebarchiesi@0 1940 * An array containing the message data. Keys in this array include:
danielebarchiesi@0 1941 * - 'id':
danielebarchiesi@0 1942 * The drupal_mail() id of the message. Look at module source code or
danielebarchiesi@0 1943 * drupal_mail() for possible id values.
danielebarchiesi@0 1944 * - 'to':
danielebarchiesi@0 1945 * The address or addresses the message will be sent to. The formatting of
danielebarchiesi@0 1946 * this string will be validated with the
danielebarchiesi@0 1947 * @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink
danielebarchiesi@0 1948 * - 'from':
danielebarchiesi@0 1949 * The address the message will be marked as being from, which is
danielebarchiesi@0 1950 * either a custom address or the site-wide default email address.
danielebarchiesi@0 1951 * - 'subject':
danielebarchiesi@0 1952 * Subject of the email to be sent. This must not contain any newline
danielebarchiesi@0 1953 * characters, or the email may not be sent properly.
danielebarchiesi@0 1954 * - 'body':
danielebarchiesi@0 1955 * An array of strings containing the message text. The message body is
danielebarchiesi@0 1956 * created by concatenating the individual array strings into a single text
danielebarchiesi@0 1957 * string using "\n\n" as a separator.
danielebarchiesi@0 1958 * - 'headers':
danielebarchiesi@0 1959 * Associative array containing mail headers, such as From, Sender,
danielebarchiesi@0 1960 * MIME-Version, Content-Type, etc.
danielebarchiesi@0 1961 * - 'params':
danielebarchiesi@0 1962 * An array of optional parameters supplied by the caller of drupal_mail()
danielebarchiesi@0 1963 * that is used to build the message before hook_mail_alter() is invoked.
danielebarchiesi@0 1964 * - 'language':
danielebarchiesi@0 1965 * The language object used to build the message before hook_mail_alter()
danielebarchiesi@0 1966 * is invoked.
danielebarchiesi@0 1967 * - 'send':
danielebarchiesi@0 1968 * Set to FALSE to abort sending this email message.
danielebarchiesi@0 1969 *
danielebarchiesi@0 1970 * @see drupal_mail()
danielebarchiesi@0 1971 */
danielebarchiesi@0 1972 function hook_mail_alter(&$message) {
danielebarchiesi@0 1973 if ($message['id'] == 'modulename_messagekey') {
danielebarchiesi@0 1974 if (!example_notifications_optin($message['to'], $message['id'])) {
danielebarchiesi@0 1975 // If the recipient has opted to not receive such messages, cancel
danielebarchiesi@0 1976 // sending.
danielebarchiesi@0 1977 $message['send'] = FALSE;
danielebarchiesi@0 1978 return;
danielebarchiesi@0 1979 }
danielebarchiesi@0 1980 $message['body'][] = "--\nMail sent out from " . variable_get('site_name', t('Drupal'));
danielebarchiesi@0 1981 }
danielebarchiesi@0 1982 }
danielebarchiesi@0 1983
danielebarchiesi@0 1984 /**
danielebarchiesi@0 1985 * Alter the registry of modules implementing a hook.
danielebarchiesi@0 1986 *
danielebarchiesi@0 1987 * This hook is invoked during module_implements(). A module may implement this
danielebarchiesi@0 1988 * hook in order to reorder the implementing modules, which are otherwise
danielebarchiesi@0 1989 * ordered by the module's system weight.
danielebarchiesi@0 1990 *
danielebarchiesi@0 1991 * Note that hooks invoked using drupal_alter() can have multiple variations
danielebarchiesi@0 1992 * (such as hook_form_alter() and hook_form_FORM_ID_alter()). drupal_alter()
danielebarchiesi@0 1993 * will call all such variants defined by a single module in turn. For the
danielebarchiesi@0 1994 * purposes of hook_module_implements_alter(), these variants are treated as
danielebarchiesi@0 1995 * a single hook. Thus, to ensure that your implementation of
danielebarchiesi@0 1996 * hook_form_FORM_ID_alter() is called at the right time, you will have to
danielebarchiesi@0 1997 * change the order of hook_form_alter() implementation in
danielebarchiesi@0 1998 * hook_module_implements_alter().
danielebarchiesi@0 1999 *
danielebarchiesi@0 2000 * @param $implementations
danielebarchiesi@0 2001 * An array keyed by the module's name. The value of each item corresponds
danielebarchiesi@0 2002 * to a $group, which is usually FALSE, unless the implementation is in a
danielebarchiesi@0 2003 * file named $module.$group.inc.
danielebarchiesi@0 2004 * @param $hook
danielebarchiesi@0 2005 * The name of the module hook being implemented.
danielebarchiesi@0 2006 */
danielebarchiesi@0 2007 function hook_module_implements_alter(&$implementations, $hook) {
danielebarchiesi@0 2008 if ($hook == 'rdf_mapping') {
danielebarchiesi@0 2009 // Move my_module_rdf_mapping() to the end of the list. module_implements()
danielebarchiesi@0 2010 // iterates through $implementations with a foreach loop which PHP iterates
danielebarchiesi@0 2011 // in the order that the items were added, so to move an item to the end of
danielebarchiesi@0 2012 // the array, we remove it and then add it.
danielebarchiesi@0 2013 $group = $implementations['my_module'];
danielebarchiesi@0 2014 unset($implementations['my_module']);
danielebarchiesi@0 2015 $implementations['my_module'] = $group;
danielebarchiesi@0 2016 }
danielebarchiesi@0 2017 }
danielebarchiesi@0 2018
danielebarchiesi@0 2019 /**
danielebarchiesi@0 2020 * Return additional themes provided by modules.
danielebarchiesi@0 2021 *
danielebarchiesi@0 2022 * Only use this hook for testing purposes. Use a hidden MYMODULE_test.module
danielebarchiesi@0 2023 * to implement this hook. Testing themes should be hidden, too.
danielebarchiesi@0 2024 *
danielebarchiesi@0 2025 * This hook is invoked from _system_rebuild_theme_data() and allows modules to
danielebarchiesi@0 2026 * register additional themes outside of the regular 'themes' directories of a
danielebarchiesi@0 2027 * Drupal installation.
danielebarchiesi@0 2028 *
danielebarchiesi@0 2029 * @return
danielebarchiesi@0 2030 * An associative array. Each key is the system name of a theme and each value
danielebarchiesi@0 2031 * is the corresponding path to the theme's .info file.
danielebarchiesi@0 2032 */
danielebarchiesi@0 2033 function hook_system_theme_info() {
danielebarchiesi@0 2034 $themes['mymodule_test_theme'] = drupal_get_path('module', 'mymodule') . '/mymodule_test_theme/mymodule_test_theme.info';
danielebarchiesi@0 2035 return $themes;
danielebarchiesi@0 2036 }
danielebarchiesi@0 2037
danielebarchiesi@0 2038 /**
danielebarchiesi@0 2039 * Alter the information parsed from module and theme .info files
danielebarchiesi@0 2040 *
danielebarchiesi@0 2041 * This hook is invoked in _system_rebuild_module_data() and in
danielebarchiesi@0 2042 * _system_rebuild_theme_data(). A module may implement this hook in order to
danielebarchiesi@0 2043 * add to or alter the data generated by reading the .info file with
danielebarchiesi@0 2044 * drupal_parse_info_file().
danielebarchiesi@0 2045 *
danielebarchiesi@0 2046 * @param $info
danielebarchiesi@0 2047 * The .info file contents, passed by reference so that it can be altered.
danielebarchiesi@0 2048 * @param $file
danielebarchiesi@0 2049 * Full information about the module or theme, including $file->name, and
danielebarchiesi@0 2050 * $file->filename
danielebarchiesi@0 2051 * @param $type
danielebarchiesi@0 2052 * Either 'module' or 'theme', depending on the type of .info file that was
danielebarchiesi@0 2053 * passed.
danielebarchiesi@0 2054 */
danielebarchiesi@0 2055 function hook_system_info_alter(&$info, $file, $type) {
danielebarchiesi@0 2056 // Only fill this in if the .info file does not define a 'datestamp'.
danielebarchiesi@0 2057 if (empty($info['datestamp'])) {
danielebarchiesi@0 2058 $info['datestamp'] = filemtime($file->filename);
danielebarchiesi@0 2059 }
danielebarchiesi@0 2060 }
danielebarchiesi@0 2061
danielebarchiesi@0 2062 /**
danielebarchiesi@0 2063 * Define user permissions.
danielebarchiesi@0 2064 *
danielebarchiesi@0 2065 * This hook can supply permissions that the module defines, so that they
danielebarchiesi@0 2066 * can be selected on the user permissions page and used to grant or restrict
danielebarchiesi@0 2067 * access to actions the module performs.
danielebarchiesi@0 2068 *
danielebarchiesi@0 2069 * Permissions are checked using user_access().
danielebarchiesi@0 2070 *
danielebarchiesi@0 2071 * For a detailed usage example, see page_example.module.
danielebarchiesi@0 2072 *
danielebarchiesi@0 2073 * @return
danielebarchiesi@0 2074 * An array whose keys are permission names and whose corresponding values
danielebarchiesi@0 2075 * are arrays containing the following key-value pairs:
danielebarchiesi@0 2076 * - title: The human-readable name of the permission, to be shown on the
danielebarchiesi@0 2077 * permission administration page. This should be wrapped in the t()
danielebarchiesi@0 2078 * function so it can be translated.
danielebarchiesi@0 2079 * - description: (optional) A description of what the permission does. This
danielebarchiesi@0 2080 * should be wrapped in the t() function so it can be translated.
danielebarchiesi@0 2081 * - restrict access: (optional) A boolean which can be set to TRUE to
danielebarchiesi@0 2082 * indicate that site administrators should restrict access to this
danielebarchiesi@0 2083 * permission to trusted users. This should be used for permissions that
danielebarchiesi@0 2084 * have inherent security risks across a variety of potential use cases
danielebarchiesi@0 2085 * (for example, the "administer filters" and "bypass node access"
danielebarchiesi@0 2086 * permissions provided by Drupal core). When set to TRUE, a standard
danielebarchiesi@0 2087 * warning message defined in user_admin_permissions() and output via
danielebarchiesi@0 2088 * theme_user_permission_description() will be associated with the
danielebarchiesi@0 2089 * permission and displayed with it on the permission administration page.
danielebarchiesi@0 2090 * Defaults to FALSE.
danielebarchiesi@0 2091 * - warning: (optional) A translated warning message to display for this
danielebarchiesi@0 2092 * permission on the permission administration page. This warning overrides
danielebarchiesi@0 2093 * the automatic warning generated by 'restrict access' being set to TRUE.
danielebarchiesi@0 2094 * This should rarely be used, since it is important for all permissions to
danielebarchiesi@0 2095 * have a clear, consistent security warning that is the same across the
danielebarchiesi@0 2096 * site. Use the 'description' key instead to provide any information that
danielebarchiesi@0 2097 * is specific to the permission you are defining.
danielebarchiesi@0 2098 *
danielebarchiesi@0 2099 * @see theme_user_permission_description()
danielebarchiesi@0 2100 */
danielebarchiesi@0 2101 function hook_permission() {
danielebarchiesi@0 2102 return array(
danielebarchiesi@0 2103 'administer my module' => array(
danielebarchiesi@0 2104 'title' => t('Administer my module'),
danielebarchiesi@0 2105 'description' => t('Perform administration tasks for my module.'),
danielebarchiesi@0 2106 ),
danielebarchiesi@0 2107 );
danielebarchiesi@0 2108 }
danielebarchiesi@0 2109
danielebarchiesi@0 2110 /**
danielebarchiesi@0 2111 * Register a module (or theme's) theme implementations.
danielebarchiesi@0 2112 *
danielebarchiesi@0 2113 * The implementations declared by this hook have two purposes: either they
danielebarchiesi@0 2114 * specify how a particular render array is to be rendered as HTML (this is
danielebarchiesi@0 2115 * usually the case if the theme function is assigned to the render array's
danielebarchiesi@0 2116 * #theme property), or they return the HTML that should be returned by an
danielebarchiesi@0 2117 * invocation of theme(). See
danielebarchiesi@0 2118 * @link http://drupal.org/node/933976 Using the theme layer Drupal 7.x @endlink
danielebarchiesi@0 2119 * for more information on how to implement theme hooks.
danielebarchiesi@0 2120 *
danielebarchiesi@0 2121 * The following parameters are all optional.
danielebarchiesi@0 2122 *
danielebarchiesi@0 2123 * @param array $existing
danielebarchiesi@0 2124 * An array of existing implementations that may be used for override
danielebarchiesi@0 2125 * purposes. This is primarily useful for themes that may wish to examine
danielebarchiesi@0 2126 * existing implementations to extract data (such as arguments) so that
danielebarchiesi@0 2127 * it may properly register its own, higher priority implementations.
danielebarchiesi@0 2128 * @param $type
danielebarchiesi@0 2129 * Whether a theme, module, etc. is being processed. This is primarily useful
danielebarchiesi@0 2130 * so that themes tell if they are the actual theme being called or a parent
danielebarchiesi@0 2131 * theme. May be one of:
danielebarchiesi@0 2132 * - 'module': A module is being checked for theme implementations.
danielebarchiesi@0 2133 * - 'base_theme_engine': A theme engine is being checked for a theme that is
danielebarchiesi@0 2134 * a parent of the actual theme being used.
danielebarchiesi@0 2135 * - 'theme_engine': A theme engine is being checked for the actual theme
danielebarchiesi@0 2136 * being used.
danielebarchiesi@0 2137 * - 'base_theme': A base theme is being checked for theme implementations.
danielebarchiesi@0 2138 * - 'theme': The actual theme in use is being checked.
danielebarchiesi@0 2139 * @param $theme
danielebarchiesi@0 2140 * The actual name of theme, module, etc. that is being being processed.
danielebarchiesi@0 2141 * @param $path
danielebarchiesi@0 2142 * The directory path of the theme or module, so that it doesn't need to be
danielebarchiesi@0 2143 * looked up.
danielebarchiesi@0 2144 *
danielebarchiesi@0 2145 * @return array
danielebarchiesi@0 2146 * An associative array of theme hook information. The keys on the outer
danielebarchiesi@0 2147 * array are the internal names of the hooks, and the values are arrays
danielebarchiesi@0 2148 * containing information about the hook. Each information array must contain
danielebarchiesi@0 2149 * either a 'variables' element or a 'render element' element, but not both.
danielebarchiesi@0 2150 * Use 'render element' if you are theming a single element or element tree
danielebarchiesi@0 2151 * composed of elements, such as a form array, a page array, or a single
danielebarchiesi@0 2152 * checkbox element. Use 'variables' if your theme implementation is
danielebarchiesi@0 2153 * intended to be called directly through theme() and has multiple arguments
danielebarchiesi@0 2154 * for the data and style; in this case, the variables not supplied by the
danielebarchiesi@0 2155 * calling function will be given default values and passed to the template
danielebarchiesi@0 2156 * or theme function. The returned theme information array can contain the
danielebarchiesi@0 2157 * following key/value pairs:
danielebarchiesi@0 2158 * - variables: (see above) Each array key is the name of the variable, and
danielebarchiesi@0 2159 * the value given is used as the default value if the function calling
danielebarchiesi@0 2160 * theme() does not supply it. Template implementations receive each array
danielebarchiesi@0 2161 * key as a variable in the template file (so they must be legal PHP
danielebarchiesi@0 2162 * variable names). Function implementations are passed the variables in a
danielebarchiesi@0 2163 * single $variables function argument.
danielebarchiesi@0 2164 * - render element: (see above) The name of the renderable element or element
danielebarchiesi@0 2165 * tree to pass to the theme function. This name is used as the name of the
danielebarchiesi@0 2166 * variable that holds the renderable element or tree in preprocess and
danielebarchiesi@0 2167 * process functions.
danielebarchiesi@0 2168 * - file: The file the implementation resides in. This file will be included
danielebarchiesi@0 2169 * prior to the theme being rendered, to make sure that the function or
danielebarchiesi@0 2170 * preprocess function (as needed) is actually loaded; this makes it
danielebarchiesi@0 2171 * possible to split theme functions out into separate files quite easily.
danielebarchiesi@0 2172 * - path: Override the path of the file to be used. Ordinarily the module or
danielebarchiesi@0 2173 * theme path will be used, but if the file will not be in the default
danielebarchiesi@0 2174 * path, include it here. This path should be relative to the Drupal root
danielebarchiesi@0 2175 * directory.
danielebarchiesi@0 2176 * - template: If specified, this theme implementation is a template, and
danielebarchiesi@0 2177 * this is the template file without an extension. Do not put .tpl.php on
danielebarchiesi@0 2178 * this file; that extension will be added automatically by the default
danielebarchiesi@0 2179 * rendering engine (which is PHPTemplate). If 'path', above, is specified,
danielebarchiesi@0 2180 * the template should also be in this path.
danielebarchiesi@0 2181 * - function: If specified, this will be the function name to invoke for
danielebarchiesi@0 2182 * this implementation. If neither 'template' nor 'function' is specified,
danielebarchiesi@0 2183 * a default function name will be assumed. For example, if a module
danielebarchiesi@0 2184 * registers the 'node' theme hook, 'theme_node' will be assigned to its
danielebarchiesi@0 2185 * function. If the chameleon theme registers the node hook, it will be
danielebarchiesi@0 2186 * assigned 'chameleon_node' as its function.
danielebarchiesi@0 2187 * - base hook: A string declaring the base theme hook if this theme
danielebarchiesi@0 2188 * implementation is actually implementing a suggestion for another theme
danielebarchiesi@0 2189 * hook.
danielebarchiesi@0 2190 * - pattern: A regular expression pattern to be used to allow this theme
danielebarchiesi@0 2191 * implementation to have a dynamic name. The convention is to use __ to
danielebarchiesi@0 2192 * differentiate the dynamic portion of the theme. For example, to allow
danielebarchiesi@0 2193 * forums to be themed individually, the pattern might be: 'forum__'. Then,
danielebarchiesi@0 2194 * when the forum is themed, call:
danielebarchiesi@0 2195 * @code
danielebarchiesi@0 2196 * theme(array('forum__' . $tid, 'forum'), $forum)
danielebarchiesi@0 2197 * @endcode
danielebarchiesi@0 2198 * - preprocess functions: A list of functions used to preprocess this data.
danielebarchiesi@0 2199 * Ordinarily this won't be used; it's automatically filled in. By default,
danielebarchiesi@0 2200 * for a module this will be filled in as template_preprocess_HOOK. For
danielebarchiesi@0 2201 * a theme this will be filled in as phptemplate_preprocess and
danielebarchiesi@0 2202 * phptemplate_preprocess_HOOK as well as themename_preprocess and
danielebarchiesi@0 2203 * themename_preprocess_HOOK.
danielebarchiesi@0 2204 * - override preprocess functions: Set to TRUE when a theme does NOT want
danielebarchiesi@0 2205 * the standard preprocess functions to run. This can be used to give a
danielebarchiesi@0 2206 * theme FULL control over how variables are set. For example, if a theme
danielebarchiesi@0 2207 * wants total control over how certain variables in the page.tpl.php are
danielebarchiesi@0 2208 * set, this can be set to true. Please keep in mind that when this is used
danielebarchiesi@0 2209 * by a theme, that theme becomes responsible for making sure necessary
danielebarchiesi@0 2210 * variables are set.
danielebarchiesi@0 2211 * - type: (automatically derived) Where the theme hook is defined:
danielebarchiesi@0 2212 * 'module', 'theme_engine', or 'theme'.
danielebarchiesi@0 2213 * - theme path: (automatically derived) The directory path of the theme or
danielebarchiesi@0 2214 * module, so that it doesn't need to be looked up.
danielebarchiesi@0 2215 *
danielebarchiesi@0 2216 * @see hook_theme_registry_alter()
danielebarchiesi@0 2217 */
danielebarchiesi@0 2218 function hook_theme($existing, $type, $theme, $path) {
danielebarchiesi@0 2219 return array(
danielebarchiesi@0 2220 'forum_display' => array(
danielebarchiesi@0 2221 'variables' => array('forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),
danielebarchiesi@0 2222 ),
danielebarchiesi@0 2223 'forum_list' => array(
danielebarchiesi@0 2224 'variables' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL),
danielebarchiesi@0 2225 ),
danielebarchiesi@0 2226 'forum_topic_list' => array(
danielebarchiesi@0 2227 'variables' => array('tid' => NULL, 'topics' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),
danielebarchiesi@0 2228 ),
danielebarchiesi@0 2229 'forum_icon' => array(
danielebarchiesi@0 2230 'variables' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0),
danielebarchiesi@0 2231 ),
danielebarchiesi@0 2232 'status_report' => array(
danielebarchiesi@0 2233 'render element' => 'requirements',
danielebarchiesi@0 2234 'file' => 'system.admin.inc',
danielebarchiesi@0 2235 ),
danielebarchiesi@0 2236 'system_date_time_settings' => array(
danielebarchiesi@0 2237 'render element' => 'form',
danielebarchiesi@0 2238 'file' => 'system.admin.inc',
danielebarchiesi@0 2239 ),
danielebarchiesi@0 2240 );
danielebarchiesi@0 2241 }
danielebarchiesi@0 2242
danielebarchiesi@0 2243 /**
danielebarchiesi@0 2244 * Alter the theme registry information returned from hook_theme().
danielebarchiesi@0 2245 *
danielebarchiesi@0 2246 * The theme registry stores information about all available theme hooks,
danielebarchiesi@0 2247 * including which callback functions those hooks will call when triggered,
danielebarchiesi@0 2248 * what template files are exposed by these hooks, and so on.
danielebarchiesi@0 2249 *
danielebarchiesi@0 2250 * Note that this hook is only executed as the theme cache is re-built.
danielebarchiesi@0 2251 * Changes here will not be visible until the next cache clear.
danielebarchiesi@0 2252 *
danielebarchiesi@0 2253 * The $theme_registry array is keyed by theme hook name, and contains the
danielebarchiesi@0 2254 * information returned from hook_theme(), as well as additional properties
danielebarchiesi@0 2255 * added by _theme_process_registry().
danielebarchiesi@0 2256 *
danielebarchiesi@0 2257 * For example:
danielebarchiesi@0 2258 * @code
danielebarchiesi@0 2259 * $theme_registry['user_profile'] = array(
danielebarchiesi@0 2260 * 'variables' => array(
danielebarchiesi@0 2261 * 'account' => NULL,
danielebarchiesi@0 2262 * ),
danielebarchiesi@0 2263 * 'template' => 'modules/user/user-profile',
danielebarchiesi@0 2264 * 'file' => 'modules/user/user.pages.inc',
danielebarchiesi@0 2265 * 'type' => 'module',
danielebarchiesi@0 2266 * 'theme path' => 'modules/user',
danielebarchiesi@0 2267 * 'preprocess functions' => array(
danielebarchiesi@0 2268 * 0 => 'template_preprocess',
danielebarchiesi@0 2269 * 1 => 'template_preprocess_user_profile',
danielebarchiesi@0 2270 * ),
danielebarchiesi@0 2271 * );
danielebarchiesi@0 2272 * @endcode
danielebarchiesi@0 2273 *
danielebarchiesi@0 2274 * @param $theme_registry
danielebarchiesi@0 2275 * The entire cache of theme registry information, post-processing.
danielebarchiesi@0 2276 *
danielebarchiesi@0 2277 * @see hook_theme()
danielebarchiesi@0 2278 * @see _theme_process_registry()
danielebarchiesi@0 2279 */
danielebarchiesi@0 2280 function hook_theme_registry_alter(&$theme_registry) {
danielebarchiesi@0 2281 // Kill the next/previous forum topic navigation links.
danielebarchiesi@0 2282 foreach ($theme_registry['forum_topic_navigation']['preprocess functions'] as $key => $value) {
danielebarchiesi@0 2283 if ($value == 'template_preprocess_forum_topic_navigation') {
danielebarchiesi@0 2284 unset($theme_registry['forum_topic_navigation']['preprocess functions'][$key]);
danielebarchiesi@0 2285 }
danielebarchiesi@0 2286 }
danielebarchiesi@0 2287 }
danielebarchiesi@0 2288
danielebarchiesi@0 2289 /**
danielebarchiesi@0 2290 * Return the machine-readable name of the theme to use for the current page.
danielebarchiesi@0 2291 *
danielebarchiesi@0 2292 * This hook can be used to dynamically set the theme for the current page
danielebarchiesi@0 2293 * request. It should be used by modules which need to override the theme
danielebarchiesi@0 2294 * based on dynamic conditions (for example, a module which allows the theme to
danielebarchiesi@0 2295 * be set based on the current user's role). The return value of this hook will
danielebarchiesi@0 2296 * be used on all pages except those which have a valid per-page or per-section
danielebarchiesi@0 2297 * theme set via a theme callback function in hook_menu(); the themes on those
danielebarchiesi@0 2298 * pages can only be overridden using hook_menu_alter().
danielebarchiesi@0 2299 *
danielebarchiesi@0 2300 * Note that returning different themes for the same path may not work with page
danielebarchiesi@0 2301 * caching. This is most likely to be a problem if an anonymous user on a given
danielebarchiesi@0 2302 * path could have different themes returned under different conditions.
danielebarchiesi@0 2303 *
danielebarchiesi@0 2304 * Since only one theme can be used at a time, the last (i.e., highest
danielebarchiesi@0 2305 * weighted) module which returns a valid theme name from this hook will
danielebarchiesi@0 2306 * prevail.
danielebarchiesi@0 2307 *
danielebarchiesi@0 2308 * @return
danielebarchiesi@0 2309 * The machine-readable name of the theme that should be used for the current
danielebarchiesi@0 2310 * page request. The value returned from this function will only have an
danielebarchiesi@0 2311 * effect if it corresponds to a currently-active theme on the site. Do not
danielebarchiesi@0 2312 * return a value if you do not wish to set a custom theme.
danielebarchiesi@0 2313 */
danielebarchiesi@0 2314 function hook_custom_theme() {
danielebarchiesi@0 2315 // Allow the user to request a particular theme via a query parameter.
danielebarchiesi@0 2316 if (isset($_GET['theme'])) {
danielebarchiesi@0 2317 return $_GET['theme'];
danielebarchiesi@0 2318 }
danielebarchiesi@0 2319 }
danielebarchiesi@0 2320
danielebarchiesi@0 2321 /**
danielebarchiesi@0 2322 * Register XML-RPC callbacks.
danielebarchiesi@0 2323 *
danielebarchiesi@0 2324 * This hook lets a module register callback functions to be called when
danielebarchiesi@0 2325 * particular XML-RPC methods are invoked by a client.
danielebarchiesi@0 2326 *
danielebarchiesi@0 2327 * @return
danielebarchiesi@0 2328 * An array which maps XML-RPC methods to Drupal functions. Each array
danielebarchiesi@0 2329 * element is either a pair of method => function or an array with four
danielebarchiesi@0 2330 * entries:
danielebarchiesi@0 2331 * - The XML-RPC method name (for example, module.function).
danielebarchiesi@0 2332 * - The Drupal callback function (for example, module_function).
danielebarchiesi@0 2333 * - The method signature is an array of XML-RPC types. The first element
danielebarchiesi@0 2334 * of this array is the type of return value and then you should write a
danielebarchiesi@0 2335 * list of the types of the parameters. XML-RPC types are the following
danielebarchiesi@0 2336 * (See the types at http://www.xmlrpc.com/spec):
danielebarchiesi@0 2337 * - "boolean": 0 (false) or 1 (true).
danielebarchiesi@0 2338 * - "double": a floating point number (for example, -12.214).
danielebarchiesi@0 2339 * - "int": a integer number (for example, -12).
danielebarchiesi@0 2340 * - "array": an array without keys (for example, array(1, 2, 3)).
danielebarchiesi@0 2341 * - "struct": an associative array or an object (for example,
danielebarchiesi@0 2342 * array('one' => 1, 'two' => 2)).
danielebarchiesi@0 2343 * - "date": when you return a date, then you may either return a
danielebarchiesi@0 2344 * timestamp (time(), mktime() etc.) or an ISO8601 timestamp. When
danielebarchiesi@0 2345 * date is specified as an input parameter, then you get an object,
danielebarchiesi@0 2346 * which is described in the function xmlrpc_date
danielebarchiesi@0 2347 * - "base64": a string containing binary data, automatically
danielebarchiesi@0 2348 * encoded/decoded automatically.
danielebarchiesi@0 2349 * - "string": anything else, typically a string.
danielebarchiesi@0 2350 * - A descriptive help string, enclosed in a t() function for translation
danielebarchiesi@0 2351 * purposes.
danielebarchiesi@0 2352 * Both forms are shown in the example.
danielebarchiesi@0 2353 */
danielebarchiesi@0 2354 function hook_xmlrpc() {
danielebarchiesi@0 2355 return array(
danielebarchiesi@0 2356 'drupal.login' => 'drupal_login',
danielebarchiesi@0 2357 array(
danielebarchiesi@0 2358 'drupal.site.ping',
danielebarchiesi@0 2359 'drupal_directory_ping',
danielebarchiesi@0 2360 array('boolean', 'string', 'string', 'string', 'string', 'string'),
danielebarchiesi@0 2361 t('Handling ping request'))
danielebarchiesi@0 2362 );
danielebarchiesi@0 2363 }
danielebarchiesi@0 2364
danielebarchiesi@0 2365 /**
danielebarchiesi@0 2366 * Alters the definition of XML-RPC methods before they are called.
danielebarchiesi@0 2367 *
danielebarchiesi@0 2368 * This hook allows modules to modify the callback definition of declared
danielebarchiesi@0 2369 * XML-RPC methods, right before they are invoked by a client. Methods may be
danielebarchiesi@0 2370 * added, or existing methods may be altered.
danielebarchiesi@0 2371 *
danielebarchiesi@0 2372 * Note that hook_xmlrpc() supports two distinct and incompatible formats to
danielebarchiesi@0 2373 * define a callback, so care must be taken when altering other methods.
danielebarchiesi@0 2374 *
danielebarchiesi@0 2375 * @param $methods
danielebarchiesi@0 2376 * An asssociative array of method callback definitions, as returned from
danielebarchiesi@0 2377 * hook_xmlrpc() implementations.
danielebarchiesi@0 2378 *
danielebarchiesi@0 2379 * @see hook_xmlrpc()
danielebarchiesi@0 2380 * @see xmlrpc_server()
danielebarchiesi@0 2381 */
danielebarchiesi@0 2382 function hook_xmlrpc_alter(&$methods) {
danielebarchiesi@0 2383 // Directly change a simple method.
danielebarchiesi@0 2384 $methods['drupal.login'] = 'mymodule_login';
danielebarchiesi@0 2385
danielebarchiesi@0 2386 // Alter complex definitions.
danielebarchiesi@0 2387 foreach ($methods as $key => &$method) {
danielebarchiesi@0 2388 // Skip simple method definitions.
danielebarchiesi@0 2389 if (!is_int($key)) {
danielebarchiesi@0 2390 continue;
danielebarchiesi@0 2391 }
danielebarchiesi@0 2392 // Perform the wanted manipulation.
danielebarchiesi@0 2393 if ($method[0] == 'drupal.site.ping') {
danielebarchiesi@0 2394 $method[1] = 'mymodule_directory_ping';
danielebarchiesi@0 2395 }
danielebarchiesi@0 2396 }
danielebarchiesi@0 2397 }
danielebarchiesi@0 2398
danielebarchiesi@0 2399 /**
danielebarchiesi@0 2400 * Log an event message.
danielebarchiesi@0 2401 *
danielebarchiesi@0 2402 * This hook allows modules to route log events to custom destinations, such as
danielebarchiesi@0 2403 * SMS, Email, pager, syslog, ...etc.
danielebarchiesi@0 2404 *
danielebarchiesi@0 2405 * @param $log_entry
danielebarchiesi@0 2406 * An associative array containing the following keys:
danielebarchiesi@0 2407 * - type: The type of message for this entry.
danielebarchiesi@0 2408 * - user: The user object for the user who was logged in when the event
danielebarchiesi@0 2409 * happened.
danielebarchiesi@0 2410 * - uid: The user ID for the user who was logged in when the event happened.
danielebarchiesi@0 2411 * - request_uri: The request URI for the page the event happened in.
danielebarchiesi@0 2412 * - referer: The page that referred the user to the page where the event
danielebarchiesi@0 2413 * occurred.
danielebarchiesi@0 2414 * - ip: The IP address where the request for the page came from.
danielebarchiesi@0 2415 * - timestamp: The UNIX timestamp of the date/time the event occurred.
danielebarchiesi@0 2416 * - severity: The severity of the message; one of the following values as
danielebarchiesi@0 2417 * defined in @link http://www.faqs.org/rfcs/rfc3164.html RFC 3164: @endlink
danielebarchiesi@0 2418 * - WATCHDOG_EMERGENCY: Emergency, system is unusable.
danielebarchiesi@0 2419 * - WATCHDOG_ALERT: Alert, action must be taken immediately.
danielebarchiesi@0 2420 * - WATCHDOG_CRITICAL: Critical conditions.
danielebarchiesi@0 2421 * - WATCHDOG_ERROR: Error conditions.
danielebarchiesi@0 2422 * - WATCHDOG_WARNING: Warning conditions.
danielebarchiesi@0 2423 * - WATCHDOG_NOTICE: Normal but significant conditions.
danielebarchiesi@0 2424 * - WATCHDOG_INFO: Informational messages.
danielebarchiesi@0 2425 * - WATCHDOG_DEBUG: Debug-level messages.
danielebarchiesi@0 2426 * - link: An optional link provided by the module that called the watchdog()
danielebarchiesi@0 2427 * function.
danielebarchiesi@0 2428 * - message: The text of the message to be logged. Variables in the message
danielebarchiesi@0 2429 * are indicated by using placeholder strings alongside the variables
danielebarchiesi@0 2430 * argument to declare the value of the placeholders. See t() for
danielebarchiesi@0 2431 * documentation on how the message and variable parameters interact.
danielebarchiesi@0 2432 * - variables: An array of variables to be inserted into the message on
danielebarchiesi@0 2433 * display. Will be NULL or missing if a message is already translated or if
danielebarchiesi@0 2434 * the message is not possible to translate.
danielebarchiesi@0 2435 */
danielebarchiesi@0 2436 function hook_watchdog(array $log_entry) {
danielebarchiesi@0 2437 global $base_url, $language;
danielebarchiesi@0 2438
danielebarchiesi@0 2439 $severity_list = array(
danielebarchiesi@0 2440 WATCHDOG_EMERGENCY => t('Emergency'),
danielebarchiesi@0 2441 WATCHDOG_ALERT => t('Alert'),
danielebarchiesi@0 2442 WATCHDOG_CRITICAL => t('Critical'),
danielebarchiesi@0 2443 WATCHDOG_ERROR => t('Error'),
danielebarchiesi@0 2444 WATCHDOG_WARNING => t('Warning'),
danielebarchiesi@0 2445 WATCHDOG_NOTICE => t('Notice'),
danielebarchiesi@0 2446 WATCHDOG_INFO => t('Info'),
danielebarchiesi@0 2447 WATCHDOG_DEBUG => t('Debug'),
danielebarchiesi@0 2448 );
danielebarchiesi@0 2449
danielebarchiesi@0 2450 $to = 'someone@example.com';
danielebarchiesi@0 2451 $params = array();
danielebarchiesi@0 2452 $params['subject'] = t('[@site_name] @severity_desc: Alert from your web site', array(
danielebarchiesi@0 2453 '@site_name' => variable_get('site_name', 'Drupal'),
danielebarchiesi@0 2454 '@severity_desc' => $severity_list[$log_entry['severity']],
danielebarchiesi@0 2455 ));
danielebarchiesi@0 2456
danielebarchiesi@0 2457 $params['message'] = "\nSite: @base_url";
danielebarchiesi@0 2458 $params['message'] .= "\nSeverity: (@severity) @severity_desc";
danielebarchiesi@0 2459 $params['message'] .= "\nTimestamp: @timestamp";
danielebarchiesi@0 2460 $params['message'] .= "\nType: @type";
danielebarchiesi@0 2461 $params['message'] .= "\nIP Address: @ip";
danielebarchiesi@0 2462 $params['message'] .= "\nRequest URI: @request_uri";
danielebarchiesi@0 2463 $params['message'] .= "\nReferrer URI: @referer_uri";
danielebarchiesi@0 2464 $params['message'] .= "\nUser: (@uid) @name";
danielebarchiesi@0 2465 $params['message'] .= "\nLink: @link";
danielebarchiesi@0 2466 $params['message'] .= "\nMessage: \n\n@message";
danielebarchiesi@0 2467
danielebarchiesi@0 2468 $params['message'] = t($params['message'], array(
danielebarchiesi@0 2469 '@base_url' => $base_url,
danielebarchiesi@0 2470 '@severity' => $log_entry['severity'],
danielebarchiesi@0 2471 '@severity_desc' => $severity_list[$log_entry['severity']],
danielebarchiesi@0 2472 '@timestamp' => format_date($log_entry['timestamp']),
danielebarchiesi@0 2473 '@type' => $log_entry['type'],
danielebarchiesi@0 2474 '@ip' => $log_entry['ip'],
danielebarchiesi@0 2475 '@request_uri' => $log_entry['request_uri'],
danielebarchiesi@0 2476 '@referer_uri' => $log_entry['referer'],
danielebarchiesi@0 2477 '@uid' => $log_entry['uid'],
danielebarchiesi@0 2478 '@name' => $log_entry['user']->name,
danielebarchiesi@0 2479 '@link' => strip_tags($log_entry['link']),
danielebarchiesi@0 2480 '@message' => strip_tags($log_entry['message']),
danielebarchiesi@0 2481 ));
danielebarchiesi@0 2482
danielebarchiesi@0 2483 drupal_mail('emaillog', 'entry', $to, $language, $params);
danielebarchiesi@0 2484 }
danielebarchiesi@0 2485
danielebarchiesi@0 2486 /**
danielebarchiesi@0 2487 * Prepare a message based on parameters; called from drupal_mail().
danielebarchiesi@0 2488 *
danielebarchiesi@0 2489 * Note that hook_mail(), unlike hook_mail_alter(), is only called on the
danielebarchiesi@0 2490 * $module argument to drupal_mail(), not all modules.
danielebarchiesi@0 2491 *
danielebarchiesi@0 2492 * @param $key
danielebarchiesi@0 2493 * An identifier of the mail.
danielebarchiesi@0 2494 * @param $message
danielebarchiesi@0 2495 * An array to be filled in. Elements in this array include:
danielebarchiesi@0 2496 * - id: An ID to identify the mail sent. Look at module source code
danielebarchiesi@0 2497 * or drupal_mail() for possible id values.
danielebarchiesi@0 2498 * - to: The address or addresses the message will be sent to. The formatting
danielebarchiesi@0 2499 * of this string will be validated with the
danielebarchiesi@0 2500 * @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink
danielebarchiesi@0 2501 * - subject: Subject of the e-mail to be sent. This must not contain any
danielebarchiesi@0 2502 * newline characters, or the mail may not be sent properly. drupal_mail()
danielebarchiesi@0 2503 * sets this to an empty string when the hook is invoked.
danielebarchiesi@0 2504 * - body: An array of lines containing the message to be sent. Drupal will
danielebarchiesi@0 2505 * format the correct line endings for you. drupal_mail() sets this to an
danielebarchiesi@0 2506 * empty array when the hook is invoked.
danielebarchiesi@0 2507 * - from: The address the message will be marked as being from, which is
danielebarchiesi@0 2508 * set by drupal_mail() to either a custom address or the site-wide
danielebarchiesi@0 2509 * default email address when the hook is invoked.
danielebarchiesi@0 2510 * - headers: Associative array containing mail headers, such as From,
danielebarchiesi@0 2511 * Sender, MIME-Version, Content-Type, etc. drupal_mail() pre-fills
danielebarchiesi@0 2512 * several headers in this array.
danielebarchiesi@0 2513 * @param $params
danielebarchiesi@0 2514 * An array of parameters supplied by the caller of drupal_mail().
danielebarchiesi@0 2515 */
danielebarchiesi@0 2516 function hook_mail($key, &$message, $params) {
danielebarchiesi@0 2517 $account = $params['account'];
danielebarchiesi@0 2518 $context = $params['context'];
danielebarchiesi@0 2519 $variables = array(
danielebarchiesi@0 2520 '%site_name' => variable_get('site_name', 'Drupal'),
danielebarchiesi@0 2521 '%username' => format_username($account),
danielebarchiesi@0 2522 );
danielebarchiesi@0 2523 if ($context['hook'] == 'taxonomy') {
danielebarchiesi@0 2524 $entity = $params['entity'];
danielebarchiesi@0 2525 $vocabulary = taxonomy_vocabulary_load($entity->vid);
danielebarchiesi@0 2526 $variables += array(
danielebarchiesi@0 2527 '%term_name' => $entity->name,
danielebarchiesi@0 2528 '%term_description' => $entity->description,
danielebarchiesi@0 2529 '%term_id' => $entity->tid,
danielebarchiesi@0 2530 '%vocabulary_name' => $vocabulary->name,
danielebarchiesi@0 2531 '%vocabulary_description' => $vocabulary->description,
danielebarchiesi@0 2532 '%vocabulary_id' => $vocabulary->vid,
danielebarchiesi@0 2533 );
danielebarchiesi@0 2534 }
danielebarchiesi@0 2535
danielebarchiesi@0 2536 // Node-based variable translation is only available if we have a node.
danielebarchiesi@0 2537 if (isset($params['node'])) {
danielebarchiesi@0 2538 $node = $params['node'];
danielebarchiesi@0 2539 $variables += array(
danielebarchiesi@0 2540 '%uid' => $node->uid,
danielebarchiesi@0 2541 '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
danielebarchiesi@0 2542 '%node_type' => node_type_get_name($node),
danielebarchiesi@0 2543 '%title' => $node->title,
danielebarchiesi@0 2544 '%teaser' => $node->teaser,
danielebarchiesi@0 2545 '%body' => $node->body,
danielebarchiesi@0 2546 );
danielebarchiesi@0 2547 }
danielebarchiesi@0 2548 $subject = strtr($context['subject'], $variables);
danielebarchiesi@0 2549 $body = strtr($context['message'], $variables);
danielebarchiesi@0 2550 $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
danielebarchiesi@0 2551 $message['body'][] = drupal_html_to_text($body);
danielebarchiesi@0 2552 }
danielebarchiesi@0 2553
danielebarchiesi@0 2554 /**
danielebarchiesi@0 2555 * Add a list of cache tables to be cleared.
danielebarchiesi@0 2556 *
danielebarchiesi@0 2557 * This hook allows your module to add cache table names to the list of cache
danielebarchiesi@0 2558 * tables that will be cleared by the Clear button on the Performance page or
danielebarchiesi@0 2559 * whenever drupal_flush_all_caches is invoked.
danielebarchiesi@0 2560 *
danielebarchiesi@0 2561 * @return
danielebarchiesi@0 2562 * An array of cache table names.
danielebarchiesi@0 2563 *
danielebarchiesi@0 2564 * @see drupal_flush_all_caches()
danielebarchiesi@0 2565 */
danielebarchiesi@0 2566 function hook_flush_caches() {
danielebarchiesi@0 2567 return array('cache_example');
danielebarchiesi@0 2568 }
danielebarchiesi@0 2569
danielebarchiesi@0 2570 /**
danielebarchiesi@0 2571 * Perform necessary actions after modules are installed.
danielebarchiesi@0 2572 *
danielebarchiesi@0 2573 * This function differs from hook_install() in that it gives all other modules
danielebarchiesi@0 2574 * a chance to perform actions when a module is installed, whereas
danielebarchiesi@0 2575 * hook_install() is only called on the module actually being installed. See
danielebarchiesi@0 2576 * module_enable() for a detailed description of the order in which install and
danielebarchiesi@0 2577 * enable hooks are invoked.
danielebarchiesi@0 2578 *
danielebarchiesi@0 2579 * @param $modules
danielebarchiesi@0 2580 * An array of the modules that were installed.
danielebarchiesi@0 2581 *
danielebarchiesi@0 2582 * @see module_enable()
danielebarchiesi@0 2583 * @see hook_modules_enabled()
danielebarchiesi@0 2584 * @see hook_install()
danielebarchiesi@0 2585 */
danielebarchiesi@0 2586 function hook_modules_installed($modules) {
danielebarchiesi@0 2587 if (in_array('lousy_module', $modules)) {
danielebarchiesi@0 2588 variable_set('lousy_module_conflicting_variable', FALSE);
danielebarchiesi@0 2589 }
danielebarchiesi@0 2590 }
danielebarchiesi@0 2591
danielebarchiesi@0 2592 /**
danielebarchiesi@0 2593 * Perform necessary actions after modules are enabled.
danielebarchiesi@0 2594 *
danielebarchiesi@0 2595 * This function differs from hook_enable() in that it gives all other modules a
danielebarchiesi@0 2596 * chance to perform actions when modules are enabled, whereas hook_enable() is
danielebarchiesi@0 2597 * only called on the module actually being enabled. See module_enable() for a
danielebarchiesi@0 2598 * detailed description of the order in which install and enable hooks are
danielebarchiesi@0 2599 * invoked.
danielebarchiesi@0 2600 *
danielebarchiesi@0 2601 * @param $modules
danielebarchiesi@0 2602 * An array of the modules that were enabled.
danielebarchiesi@0 2603 *
danielebarchiesi@0 2604 * @see hook_enable()
danielebarchiesi@0 2605 * @see hook_modules_installed()
danielebarchiesi@0 2606 * @see module_enable()
danielebarchiesi@0 2607 */
danielebarchiesi@0 2608 function hook_modules_enabled($modules) {
danielebarchiesi@0 2609 if (in_array('lousy_module', $modules)) {
danielebarchiesi@0 2610 drupal_set_message(t('mymodule is not compatible with lousy_module'), 'error');
danielebarchiesi@0 2611 mymodule_disable_functionality();
danielebarchiesi@0 2612 }
danielebarchiesi@0 2613 }
danielebarchiesi@0 2614
danielebarchiesi@0 2615 /**
danielebarchiesi@0 2616 * Perform necessary actions after modules are disabled.
danielebarchiesi@0 2617 *
danielebarchiesi@0 2618 * This function differs from hook_disable() in that it gives all other modules
danielebarchiesi@0 2619 * a chance to perform actions when modules are disabled, whereas hook_disable()
danielebarchiesi@0 2620 * is only called on the module actually being disabled.
danielebarchiesi@0 2621 *
danielebarchiesi@0 2622 * @param $modules
danielebarchiesi@0 2623 * An array of the modules that were disabled.
danielebarchiesi@0 2624 *
danielebarchiesi@0 2625 * @see hook_disable()
danielebarchiesi@0 2626 * @see hook_modules_uninstalled()
danielebarchiesi@0 2627 */
danielebarchiesi@0 2628 function hook_modules_disabled($modules) {
danielebarchiesi@0 2629 if (in_array('lousy_module', $modules)) {
danielebarchiesi@0 2630 mymodule_enable_functionality();
danielebarchiesi@0 2631 }
danielebarchiesi@0 2632 }
danielebarchiesi@0 2633
danielebarchiesi@0 2634 /**
danielebarchiesi@0 2635 * Perform necessary actions after modules are uninstalled.
danielebarchiesi@0 2636 *
danielebarchiesi@0 2637 * This function differs from hook_uninstall() in that it gives all other
danielebarchiesi@0 2638 * modules a chance to perform actions when a module is uninstalled, whereas
danielebarchiesi@0 2639 * hook_uninstall() is only called on the module actually being uninstalled.
danielebarchiesi@0 2640 *
danielebarchiesi@0 2641 * It is recommended that you implement this hook if your module stores
danielebarchiesi@0 2642 * data that may have been set by other modules.
danielebarchiesi@0 2643 *
danielebarchiesi@0 2644 * @param $modules
danielebarchiesi@0 2645 * An array of the modules that were uninstalled.
danielebarchiesi@0 2646 *
danielebarchiesi@0 2647 * @see hook_uninstall()
danielebarchiesi@0 2648 * @see hook_modules_disabled()
danielebarchiesi@0 2649 */
danielebarchiesi@0 2650 function hook_modules_uninstalled($modules) {
danielebarchiesi@0 2651 foreach ($modules as $module) {
danielebarchiesi@0 2652 db_delete('mymodule_table')
danielebarchiesi@0 2653 ->condition('module', $module)
danielebarchiesi@0 2654 ->execute();
danielebarchiesi@0 2655 }
danielebarchiesi@0 2656 mymodule_cache_rebuild();
danielebarchiesi@0 2657 }
danielebarchiesi@0 2658
danielebarchiesi@0 2659 /**
danielebarchiesi@0 2660 * Registers PHP stream wrapper implementations associated with a module.
danielebarchiesi@0 2661 *
danielebarchiesi@0 2662 * Provide a facility for managing and querying user-defined stream wrappers
danielebarchiesi@0 2663 * in PHP. PHP's internal stream_get_wrappers() doesn't return the class
danielebarchiesi@0 2664 * registered to handle a stream, which we need to be able to find the handler
danielebarchiesi@0 2665 * for class instantiation.
danielebarchiesi@0 2666 *
danielebarchiesi@0 2667 * If a module registers a scheme that is already registered with PHP, it will
danielebarchiesi@0 2668 * be unregistered and replaced with the specified class.
danielebarchiesi@0 2669 *
danielebarchiesi@0 2670 * @return
danielebarchiesi@0 2671 * A nested array, keyed first by scheme name ("public" for "public://"),
danielebarchiesi@0 2672 * then keyed by the following values:
danielebarchiesi@0 2673 * - 'name' A short string to name the wrapper.
danielebarchiesi@0 2674 * - 'class' A string specifying the PHP class that implements the
danielebarchiesi@0 2675 * DrupalStreamWrapperInterface interface.
danielebarchiesi@0 2676 * - 'description' A string with a short description of what the wrapper does.
danielebarchiesi@0 2677 * - 'type' (Optional) A bitmask of flags indicating what type of streams this
danielebarchiesi@0 2678 * wrapper will access - local or remote, readable and/or writeable, etc.
danielebarchiesi@0 2679 * Many shortcut constants are defined in stream_wrappers.inc. Defaults to
danielebarchiesi@0 2680 * STREAM_WRAPPERS_NORMAL which includes all of these bit flags:
danielebarchiesi@0 2681 * - STREAM_WRAPPERS_READ
danielebarchiesi@0 2682 * - STREAM_WRAPPERS_WRITE
danielebarchiesi@0 2683 * - STREAM_WRAPPERS_VISIBLE
danielebarchiesi@0 2684 *
danielebarchiesi@0 2685 * @see file_get_stream_wrappers()
danielebarchiesi@0 2686 * @see hook_stream_wrappers_alter()
danielebarchiesi@0 2687 * @see system_stream_wrappers()
danielebarchiesi@0 2688 */
danielebarchiesi@0 2689 function hook_stream_wrappers() {
danielebarchiesi@0 2690 return array(
danielebarchiesi@0 2691 'public' => array(
danielebarchiesi@0 2692 'name' => t('Public files'),
danielebarchiesi@0 2693 'class' => 'DrupalPublicStreamWrapper',
danielebarchiesi@0 2694 'description' => t('Public local files served by the webserver.'),
danielebarchiesi@0 2695 'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
danielebarchiesi@0 2696 ),
danielebarchiesi@0 2697 'private' => array(
danielebarchiesi@0 2698 'name' => t('Private files'),
danielebarchiesi@0 2699 'class' => 'DrupalPrivateStreamWrapper',
danielebarchiesi@0 2700 'description' => t('Private local files served by Drupal.'),
danielebarchiesi@0 2701 'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
danielebarchiesi@0 2702 ),
danielebarchiesi@0 2703 'temp' => array(
danielebarchiesi@0 2704 'name' => t('Temporary files'),
danielebarchiesi@0 2705 'class' => 'DrupalTempStreamWrapper',
danielebarchiesi@0 2706 'description' => t('Temporary local files for upload and previews.'),
danielebarchiesi@0 2707 'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,
danielebarchiesi@0 2708 ),
danielebarchiesi@0 2709 'cdn' => array(
danielebarchiesi@0 2710 'name' => t('Content delivery network files'),
danielebarchiesi@0 2711 'class' => 'MyModuleCDNStreamWrapper',
danielebarchiesi@0 2712 'description' => t('Files served by a content delivery network.'),
danielebarchiesi@0 2713 // 'type' can be omitted to use the default of STREAM_WRAPPERS_NORMAL
danielebarchiesi@0 2714 ),
danielebarchiesi@0 2715 'youtube' => array(
danielebarchiesi@0 2716 'name' => t('YouTube video'),
danielebarchiesi@0 2717 'class' => 'MyModuleYouTubeStreamWrapper',
danielebarchiesi@0 2718 'description' => t('Video streamed from YouTube.'),
danielebarchiesi@0 2719 // A module implementing YouTube integration may decide to support using
danielebarchiesi@0 2720 // the YouTube API for uploading video, but here, we assume that this
danielebarchiesi@0 2721 // particular module only supports playing YouTube video.
danielebarchiesi@0 2722 'type' => STREAM_WRAPPERS_READ_VISIBLE,
danielebarchiesi@0 2723 ),
danielebarchiesi@0 2724 );
danielebarchiesi@0 2725 }
danielebarchiesi@0 2726
danielebarchiesi@0 2727 /**
danielebarchiesi@0 2728 * Alters the list of PHP stream wrapper implementations.
danielebarchiesi@0 2729 *
danielebarchiesi@0 2730 * @see file_get_stream_wrappers()
danielebarchiesi@0 2731 * @see hook_stream_wrappers()
danielebarchiesi@0 2732 */
danielebarchiesi@0 2733 function hook_stream_wrappers_alter(&$wrappers) {
danielebarchiesi@0 2734 // Change the name of private files to reflect the performance.
danielebarchiesi@0 2735 $wrappers['private']['name'] = t('Slow files');
danielebarchiesi@0 2736 }
danielebarchiesi@0 2737
danielebarchiesi@0 2738 /**
danielebarchiesi@0 2739 * Load additional information into file objects.
danielebarchiesi@0 2740 *
danielebarchiesi@0 2741 * file_load_multiple() calls this hook to allow modules to load
danielebarchiesi@0 2742 * additional information into each file.
danielebarchiesi@0 2743 *
danielebarchiesi@0 2744 * @param $files
danielebarchiesi@0 2745 * An array of file objects, indexed by fid.
danielebarchiesi@0 2746 *
danielebarchiesi@0 2747 * @see file_load_multiple()
danielebarchiesi@0 2748 * @see file_load()
danielebarchiesi@0 2749 */
danielebarchiesi@0 2750 function hook_file_load($files) {
danielebarchiesi@0 2751 // Add the upload specific data into the file object.
danielebarchiesi@0 2752 $result = db_query('SELECT * FROM {upload} u WHERE u.fid IN (:fids)', array(':fids' => array_keys($files)))->fetchAll(PDO::FETCH_ASSOC);
danielebarchiesi@0 2753 foreach ($result as $record) {
danielebarchiesi@0 2754 foreach ($record as $key => $value) {
danielebarchiesi@0 2755 $files[$record['fid']]->$key = $value;
danielebarchiesi@0 2756 }
danielebarchiesi@0 2757 }
danielebarchiesi@0 2758 }
danielebarchiesi@0 2759
danielebarchiesi@0 2760 /**
danielebarchiesi@0 2761 * Check that files meet a given criteria.
danielebarchiesi@0 2762 *
danielebarchiesi@0 2763 * This hook lets modules perform additional validation on files. They're able
danielebarchiesi@0 2764 * to report a failure by returning one or more error messages.
danielebarchiesi@0 2765 *
danielebarchiesi@0 2766 * @param $file
danielebarchiesi@0 2767 * The file object being validated.
danielebarchiesi@0 2768 * @return
danielebarchiesi@0 2769 * An array of error messages. If there are no problems with the file return
danielebarchiesi@0 2770 * an empty array.
danielebarchiesi@0 2771 *
danielebarchiesi@0 2772 * @see file_validate()
danielebarchiesi@0 2773 */
danielebarchiesi@0 2774 function hook_file_validate($file) {
danielebarchiesi@0 2775 $errors = array();
danielebarchiesi@0 2776
danielebarchiesi@0 2777 if (empty($file->filename)) {
danielebarchiesi@0 2778 $errors[] = t("The file's name is empty. Please give a name to the file.");
danielebarchiesi@0 2779 }
danielebarchiesi@0 2780 if (strlen($file->filename) > 255) {
danielebarchiesi@0 2781 $errors[] = t("The file's name exceeds the 255 characters limit. Please rename the file and try again.");
danielebarchiesi@0 2782 }
danielebarchiesi@0 2783
danielebarchiesi@0 2784 return $errors;
danielebarchiesi@0 2785 }
danielebarchiesi@0 2786
danielebarchiesi@0 2787 /**
danielebarchiesi@0 2788 * Act on a file being inserted or updated.
danielebarchiesi@0 2789 *
danielebarchiesi@0 2790 * This hook is called when a file has been added to the database. The hook
danielebarchiesi@0 2791 * doesn't distinguish between files created as a result of a copy or those
danielebarchiesi@0 2792 * created by an upload.
danielebarchiesi@0 2793 *
danielebarchiesi@0 2794 * @param $file
danielebarchiesi@0 2795 * The file that has just been created.
danielebarchiesi@0 2796 *
danielebarchiesi@0 2797 * @see file_save()
danielebarchiesi@0 2798 */
danielebarchiesi@0 2799 function hook_file_presave($file) {
danielebarchiesi@0 2800 // Change the file timestamp to an hour prior.
danielebarchiesi@0 2801 $file->timestamp -= 3600;
danielebarchiesi@0 2802 }
danielebarchiesi@0 2803
danielebarchiesi@0 2804 /**
danielebarchiesi@0 2805 * Respond to a file being added.
danielebarchiesi@0 2806 *
danielebarchiesi@0 2807 * This hook is called after a file has been added to the database. The hook
danielebarchiesi@0 2808 * doesn't distinguish between files created as a result of a copy or those
danielebarchiesi@0 2809 * created by an upload.
danielebarchiesi@0 2810 *
danielebarchiesi@0 2811 * @param $file
danielebarchiesi@0 2812 * The file that has been added.
danielebarchiesi@0 2813 *
danielebarchiesi@0 2814 * @see file_save()
danielebarchiesi@0 2815 */
danielebarchiesi@0 2816 function hook_file_insert($file) {
danielebarchiesi@0 2817 // Add a message to the log, if the file is a jpg
danielebarchiesi@0 2818 $validate = file_validate_extensions($file, 'jpg');
danielebarchiesi@0 2819 if (empty($validate)) {
danielebarchiesi@0 2820 watchdog('file', 'A jpg has been added.');
danielebarchiesi@0 2821 }
danielebarchiesi@0 2822 }
danielebarchiesi@0 2823
danielebarchiesi@0 2824 /**
danielebarchiesi@0 2825 * Respond to a file being updated.
danielebarchiesi@0 2826 *
danielebarchiesi@0 2827 * This hook is called when file_save() is called on an existing file.
danielebarchiesi@0 2828 *
danielebarchiesi@0 2829 * @param $file
danielebarchiesi@0 2830 * The file that has just been updated.
danielebarchiesi@0 2831 *
danielebarchiesi@0 2832 * @see file_save()
danielebarchiesi@0 2833 */
danielebarchiesi@0 2834 function hook_file_update($file) {
danielebarchiesi@0 2835 $file_user = user_load($file->uid);
danielebarchiesi@0 2836 // Make sure that the file name starts with the owner's user name.
danielebarchiesi@0 2837 if (strpos($file->filename, $file_user->name) !== 0) {
danielebarchiesi@0 2838 $old_filename = $file->filename;
danielebarchiesi@0 2839 $file->filename = $file_user->name . '_' . $file->filename;
danielebarchiesi@0 2840 $file->save();
danielebarchiesi@0 2841
danielebarchiesi@0 2842 watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->filename)));
danielebarchiesi@0 2843 }
danielebarchiesi@0 2844 }
danielebarchiesi@0 2845
danielebarchiesi@0 2846 /**
danielebarchiesi@0 2847 * Respond to a file that has been copied.
danielebarchiesi@0 2848 *
danielebarchiesi@0 2849 * @param $file
danielebarchiesi@0 2850 * The newly copied file object.
danielebarchiesi@0 2851 * @param $source
danielebarchiesi@0 2852 * The original file before the copy.
danielebarchiesi@0 2853 *
danielebarchiesi@0 2854 * @see file_copy()
danielebarchiesi@0 2855 */
danielebarchiesi@0 2856 function hook_file_copy($file, $source) {
danielebarchiesi@0 2857 $file_user = user_load($file->uid);
danielebarchiesi@0 2858 // Make sure that the file name starts with the owner's user name.
danielebarchiesi@0 2859 if (strpos($file->filename, $file_user->name) !== 0) {
danielebarchiesi@0 2860 $file->filename = $file_user->name . '_' . $file->filename;
danielebarchiesi@0 2861 $file->save();
danielebarchiesi@0 2862
danielebarchiesi@0 2863 watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
danielebarchiesi@0 2864 }
danielebarchiesi@0 2865 }
danielebarchiesi@0 2866
danielebarchiesi@0 2867 /**
danielebarchiesi@0 2868 * Respond to a file that has been moved.
danielebarchiesi@0 2869 *
danielebarchiesi@0 2870 * @param $file
danielebarchiesi@0 2871 * The updated file object after the move.
danielebarchiesi@0 2872 * @param $source
danielebarchiesi@0 2873 * The original file object before the move.
danielebarchiesi@0 2874 *
danielebarchiesi@0 2875 * @see file_move()
danielebarchiesi@0 2876 */
danielebarchiesi@0 2877 function hook_file_move($file, $source) {
danielebarchiesi@0 2878 $file_user = user_load($file->uid);
danielebarchiesi@0 2879 // Make sure that the file name starts with the owner's user name.
danielebarchiesi@0 2880 if (strpos($file->filename, $file_user->name) !== 0) {
danielebarchiesi@0 2881 $file->filename = $file_user->name . '_' . $file->filename;
danielebarchiesi@0 2882 $file->save();
danielebarchiesi@0 2883
danielebarchiesi@0 2884 watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
danielebarchiesi@0 2885 }
danielebarchiesi@0 2886 }
danielebarchiesi@0 2887
danielebarchiesi@0 2888 /**
danielebarchiesi@0 2889 * Respond to a file being deleted.
danielebarchiesi@0 2890 *
danielebarchiesi@0 2891 * @param $file
danielebarchiesi@0 2892 * The file that has just been deleted.
danielebarchiesi@0 2893 *
danielebarchiesi@0 2894 * @see file_delete()
danielebarchiesi@0 2895 */
danielebarchiesi@0 2896 function hook_file_delete($file) {
danielebarchiesi@0 2897 // Delete all information associated with the file.
danielebarchiesi@0 2898 db_delete('upload')->condition('fid', $file->fid)->execute();
danielebarchiesi@0 2899 }
danielebarchiesi@0 2900
danielebarchiesi@0 2901 /**
danielebarchiesi@0 2902 * Control access to private file downloads and specify HTTP headers.
danielebarchiesi@0 2903 *
danielebarchiesi@0 2904 * This hook allows modules enforce permissions on file downloads when the
danielebarchiesi@0 2905 * private file download method is selected. Modules can also provide headers
danielebarchiesi@0 2906 * to specify information like the file's name or MIME type.
danielebarchiesi@0 2907 *
danielebarchiesi@0 2908 * @param $uri
danielebarchiesi@0 2909 * The URI of the file.
danielebarchiesi@0 2910 * @return
danielebarchiesi@0 2911 * If the user does not have permission to access the file, return -1. If the
danielebarchiesi@0 2912 * user has permission, return an array with the appropriate headers. If the
danielebarchiesi@0 2913 * file is not controlled by the current module, the return value should be
danielebarchiesi@0 2914 * NULL.
danielebarchiesi@0 2915 *
danielebarchiesi@0 2916 * @see file_download()
danielebarchiesi@0 2917 */
danielebarchiesi@0 2918 function hook_file_download($uri) {
danielebarchiesi@0 2919 // Check if the file is controlled by the current module.
danielebarchiesi@0 2920 if (!file_prepare_directory($uri)) {
danielebarchiesi@0 2921 $uri = FALSE;
danielebarchiesi@0 2922 }
danielebarchiesi@0 2923 if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) {
danielebarchiesi@0 2924 if (!user_access('access user profiles')) {
danielebarchiesi@0 2925 // Access to the file is denied.
danielebarchiesi@0 2926 return -1;
danielebarchiesi@0 2927 }
danielebarchiesi@0 2928 else {
danielebarchiesi@0 2929 $info = image_get_info($uri);
danielebarchiesi@0 2930 return array('Content-Type' => $info['mime_type']);
danielebarchiesi@0 2931 }
danielebarchiesi@0 2932 }
danielebarchiesi@0 2933 }
danielebarchiesi@0 2934
danielebarchiesi@0 2935 /**
danielebarchiesi@0 2936 * Alter the URL to a file.
danielebarchiesi@0 2937 *
danielebarchiesi@0 2938 * This hook is called from file_create_url(), and is called fairly
danielebarchiesi@0 2939 * frequently (10+ times per page), depending on how many files there are in a
danielebarchiesi@0 2940 * given page.
danielebarchiesi@0 2941 * If CSS and JS aggregation are disabled, this can become very frequently
danielebarchiesi@0 2942 * (50+ times per page) so performance is critical.
danielebarchiesi@0 2943 *
danielebarchiesi@0 2944 * This function should alter the URI, if it wants to rewrite the file URL.
danielebarchiesi@0 2945 *
danielebarchiesi@0 2946 * @param $uri
danielebarchiesi@0 2947 * The URI to a file for which we need an external URL, or the path to a
danielebarchiesi@0 2948 * shipped file.
danielebarchiesi@0 2949 */
danielebarchiesi@0 2950 function hook_file_url_alter(&$uri) {
danielebarchiesi@0 2951 global $user;
danielebarchiesi@0 2952
danielebarchiesi@0 2953 // User 1 will always see the local file in this example.
danielebarchiesi@0 2954 if ($user->uid == 1) {
danielebarchiesi@0 2955 return;
danielebarchiesi@0 2956 }
danielebarchiesi@0 2957
danielebarchiesi@0 2958 $cdn1 = 'http://cdn1.example.com';
danielebarchiesi@0 2959 $cdn2 = 'http://cdn2.example.com';
danielebarchiesi@0 2960 $cdn_extensions = array('css', 'js', 'gif', 'jpg', 'jpeg', 'png');
danielebarchiesi@0 2961
danielebarchiesi@0 2962 // Most CDNs don't support private file transfers without a lot of hassle,
danielebarchiesi@0 2963 // so don't support this in the common case.
danielebarchiesi@0 2964 $schemes = array('public');
danielebarchiesi@0 2965
danielebarchiesi@0 2966 $scheme = file_uri_scheme($uri);
danielebarchiesi@0 2967
danielebarchiesi@0 2968 // Only serve shipped files and public created files from the CDN.
danielebarchiesi@0 2969 if (!$scheme || in_array($scheme, $schemes)) {
danielebarchiesi@0 2970 // Shipped files.
danielebarchiesi@0 2971 if (!$scheme) {
danielebarchiesi@0 2972 $path = $uri;
danielebarchiesi@0 2973 }
danielebarchiesi@0 2974 // Public created files.
danielebarchiesi@0 2975 else {
danielebarchiesi@0 2976 $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
danielebarchiesi@0 2977 $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
danielebarchiesi@0 2978 }
danielebarchiesi@0 2979
danielebarchiesi@0 2980 // Clean up Windows paths.
danielebarchiesi@0 2981 $path = str_replace('\\', '/', $path);
danielebarchiesi@0 2982
danielebarchiesi@0 2983 // Serve files with one of the CDN extensions from CDN 1, all others from
danielebarchiesi@0 2984 // CDN 2.
danielebarchiesi@0 2985 $pathinfo = pathinfo($path);
danielebarchiesi@0 2986 if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], $cdn_extensions)) {
danielebarchiesi@0 2987 $uri = $cdn1 . '/' . $path;
danielebarchiesi@0 2988 }
danielebarchiesi@0 2989 else {
danielebarchiesi@0 2990 $uri = $cdn2 . '/' . $path;
danielebarchiesi@0 2991 }
danielebarchiesi@0 2992 }
danielebarchiesi@0 2993 }
danielebarchiesi@0 2994
danielebarchiesi@0 2995 /**
danielebarchiesi@0 2996 * Check installation requirements and do status reporting.
danielebarchiesi@0 2997 *
danielebarchiesi@0 2998 * This hook has three closely related uses, determined by the $phase argument:
danielebarchiesi@0 2999 * - Checking installation requirements ($phase == 'install').
danielebarchiesi@0 3000 * - Checking update requirements ($phase == 'update').
danielebarchiesi@0 3001 * - Status reporting ($phase == 'runtime').
danielebarchiesi@0 3002 *
danielebarchiesi@0 3003 * Note that this hook, like all others dealing with installation and updates,
danielebarchiesi@0 3004 * must reside in a module_name.install file, or it will not properly abort
danielebarchiesi@0 3005 * the installation of the module if a critical requirement is missing.
danielebarchiesi@0 3006 *
danielebarchiesi@0 3007 * During the 'install' phase, modules can for example assert that
danielebarchiesi@0 3008 * library or server versions are available or sufficient.
danielebarchiesi@0 3009 * Note that the installation of a module can happen during installation of
danielebarchiesi@0 3010 * Drupal itself (by install.php) with an installation profile or later by hand.
danielebarchiesi@0 3011 * As a consequence, install-time requirements must be checked without access
danielebarchiesi@0 3012 * to the full Drupal API, because it is not available during install.php.
danielebarchiesi@0 3013 * For localization you should for example use $t = get_t() to
danielebarchiesi@0 3014 * retrieve the appropriate localization function name (t() or st()).
danielebarchiesi@0 3015 * If a requirement has a severity of REQUIREMENT_ERROR, install.php will abort
danielebarchiesi@0 3016 * or at least the module will not install.
danielebarchiesi@0 3017 * Other severity levels have no effect on the installation.
danielebarchiesi@0 3018 * Module dependencies do not belong to these installation requirements,
danielebarchiesi@0 3019 * but should be defined in the module's .info file.
danielebarchiesi@0 3020 *
danielebarchiesi@0 3021 * The 'runtime' phase is not limited to pure installation requirements
danielebarchiesi@0 3022 * but can also be used for more general status information like maintenance
danielebarchiesi@0 3023 * tasks and security issues.
danielebarchiesi@0 3024 * The returned 'requirements' will be listed on the status report in the
danielebarchiesi@0 3025 * administration section, with indication of the severity level.
danielebarchiesi@0 3026 * Moreover, any requirement with a severity of REQUIREMENT_ERROR severity will
danielebarchiesi@0 3027 * result in a notice on the administration configuration page.
danielebarchiesi@0 3028 *
danielebarchiesi@0 3029 * @param $phase
danielebarchiesi@0 3030 * The phase in which requirements are checked:
danielebarchiesi@0 3031 * - install: The module is being installed.
danielebarchiesi@0 3032 * - update: The module is enabled and update.php is run.
danielebarchiesi@0 3033 * - runtime: The runtime requirements are being checked and shown on the
danielebarchiesi@0 3034 * status report page.
danielebarchiesi@0 3035 *
danielebarchiesi@0 3036 * @return
danielebarchiesi@0 3037 * An associative array where the keys are arbitrary but must be unique (it
danielebarchiesi@0 3038 * is suggested to use the module short name as a prefix) and the values are
danielebarchiesi@0 3039 * themselves associative arrays with the following elements:
danielebarchiesi@0 3040 * - title: The name of the requirement.
danielebarchiesi@0 3041 * - value: The current value (e.g., version, time, level, etc). During
danielebarchiesi@0 3042 * install phase, this should only be used for version numbers, do not set
danielebarchiesi@0 3043 * it if not applicable.
danielebarchiesi@0 3044 * - description: The description of the requirement/status.
danielebarchiesi@0 3045 * - severity: The requirement's result/severity level, one of:
danielebarchiesi@0 3046 * - REQUIREMENT_INFO: For info only.
danielebarchiesi@0 3047 * - REQUIREMENT_OK: The requirement is satisfied.
danielebarchiesi@0 3048 * - REQUIREMENT_WARNING: The requirement failed with a warning.
danielebarchiesi@0 3049 * - REQUIREMENT_ERROR: The requirement failed with an error.
danielebarchiesi@0 3050 */
danielebarchiesi@0 3051 function hook_requirements($phase) {
danielebarchiesi@0 3052 $requirements = array();
danielebarchiesi@0 3053 // Ensure translations don't break during installation.
danielebarchiesi@0 3054 $t = get_t();
danielebarchiesi@0 3055
danielebarchiesi@0 3056 // Report Drupal version
danielebarchiesi@0 3057 if ($phase == 'runtime') {
danielebarchiesi@0 3058 $requirements['drupal'] = array(
danielebarchiesi@0 3059 'title' => $t('Drupal'),
danielebarchiesi@0 3060 'value' => VERSION,
danielebarchiesi@0 3061 'severity' => REQUIREMENT_INFO
danielebarchiesi@0 3062 );
danielebarchiesi@0 3063 }
danielebarchiesi@0 3064
danielebarchiesi@0 3065 // Test PHP version
danielebarchiesi@0 3066 $requirements['php'] = array(
danielebarchiesi@0 3067 'title' => $t('PHP'),
danielebarchiesi@0 3068 'value' => ($phase == 'runtime') ? l(phpversion(), 'admin/reports/status/php') : phpversion(),
danielebarchiesi@0 3069 );
danielebarchiesi@0 3070 if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) {
danielebarchiesi@0 3071 $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP));
danielebarchiesi@0 3072 $requirements['php']['severity'] = REQUIREMENT_ERROR;
danielebarchiesi@0 3073 }
danielebarchiesi@0 3074
danielebarchiesi@0 3075 // Report cron status
danielebarchiesi@0 3076 if ($phase == 'runtime') {
danielebarchiesi@0 3077 $cron_last = variable_get('cron_last');
danielebarchiesi@0 3078
danielebarchiesi@0 3079 if (is_numeric($cron_last)) {
danielebarchiesi@0 3080 $requirements['cron']['value'] = $t('Last run !time ago', array('!time' => format_interval(REQUEST_TIME - $cron_last)));
danielebarchiesi@0 3081 }
danielebarchiesi@0 3082 else {
danielebarchiesi@0 3083 $requirements['cron'] = array(
danielebarchiesi@0 3084 'description' => $t('Cron has not run. It appears cron jobs have not been setup on your system. Check the help pages for <a href="@url">configuring cron jobs</a>.', array('@url' => 'http://drupal.org/cron')),
danielebarchiesi@0 3085 'severity' => REQUIREMENT_ERROR,
danielebarchiesi@0 3086 'value' => $t('Never run'),
danielebarchiesi@0 3087 );
danielebarchiesi@0 3088 }
danielebarchiesi@0 3089
danielebarchiesi@0 3090 $requirements['cron']['description'] .= ' ' . $t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/reports/status/run-cron')));
danielebarchiesi@0 3091
danielebarchiesi@0 3092 $requirements['cron']['title'] = $t('Cron maintenance tasks');
danielebarchiesi@0 3093 }
danielebarchiesi@0 3094
danielebarchiesi@0 3095 return $requirements;
danielebarchiesi@0 3096 }
danielebarchiesi@0 3097
danielebarchiesi@0 3098 /**
danielebarchiesi@0 3099 * Define the current version of the database schema.
danielebarchiesi@0 3100 *
danielebarchiesi@0 3101 * A Drupal schema definition is an array structure representing one or
danielebarchiesi@0 3102 * more tables and their related keys and indexes. A schema is defined by
danielebarchiesi@0 3103 * hook_schema() which must live in your module's .install file.
danielebarchiesi@0 3104 *
danielebarchiesi@0 3105 * This hook is called at install and uninstall time, and in the latter
danielebarchiesi@0 3106 * case, it cannot rely on the .module file being loaded or hooks being known.
danielebarchiesi@0 3107 * If the .module file is needed, it may be loaded with drupal_load().
danielebarchiesi@0 3108 *
danielebarchiesi@0 3109 * The tables declared by this hook will be automatically created when
danielebarchiesi@0 3110 * the module is first enabled, and removed when the module is uninstalled.
danielebarchiesi@0 3111 * This happens before hook_install() is invoked, and after hook_uninstall()
danielebarchiesi@0 3112 * is invoked, respectively.
danielebarchiesi@0 3113 *
danielebarchiesi@0 3114 * By declaring the tables used by your module via an implementation of
danielebarchiesi@0 3115 * hook_schema(), these tables will be available on all supported database
danielebarchiesi@0 3116 * engines. You don't have to deal with the different SQL dialects for table
danielebarchiesi@0 3117 * creation and alteration of the supported database engines.
danielebarchiesi@0 3118 *
danielebarchiesi@0 3119 * See the Schema API Handbook at http://drupal.org/node/146843 for
danielebarchiesi@0 3120 * details on schema definition structures.
danielebarchiesi@0 3121 *
danielebarchiesi@0 3122 * @return
danielebarchiesi@0 3123 * A schema definition structure array. For each element of the
danielebarchiesi@0 3124 * array, the key is a table name and the value is a table structure
danielebarchiesi@0 3125 * definition.
danielebarchiesi@0 3126 *
danielebarchiesi@0 3127 * @ingroup schemaapi
danielebarchiesi@0 3128 */
danielebarchiesi@0 3129 function hook_schema() {
danielebarchiesi@0 3130 $schema['node'] = array(
danielebarchiesi@0 3131 // example (partial) specification for table "node"
danielebarchiesi@0 3132 'description' => 'The base table for nodes.',
danielebarchiesi@0 3133 'fields' => array(
danielebarchiesi@0 3134 'nid' => array(
danielebarchiesi@0 3135 'description' => 'The primary identifier for a node.',
danielebarchiesi@0 3136 'type' => 'serial',
danielebarchiesi@0 3137 'unsigned' => TRUE,
danielebarchiesi@0 3138 'not null' => TRUE,
danielebarchiesi@0 3139 ),
danielebarchiesi@0 3140 'vid' => array(
danielebarchiesi@0 3141 'description' => 'The current {node_revision}.vid version identifier.',
danielebarchiesi@0 3142 'type' => 'int',
danielebarchiesi@0 3143 'unsigned' => TRUE,
danielebarchiesi@0 3144 'not null' => TRUE,
danielebarchiesi@0 3145 'default' => 0,
danielebarchiesi@0 3146 ),
danielebarchiesi@0 3147 'type' => array(
danielebarchiesi@0 3148 'description' => 'The {node_type} of this node.',
danielebarchiesi@0 3149 'type' => 'varchar',
danielebarchiesi@0 3150 'length' => 32,
danielebarchiesi@0 3151 'not null' => TRUE,
danielebarchiesi@0 3152 'default' => '',
danielebarchiesi@0 3153 ),
danielebarchiesi@0 3154 'title' => array(
danielebarchiesi@0 3155 'description' => 'The title of this node, always treated as non-markup plain text.',
danielebarchiesi@0 3156 'type' => 'varchar',
danielebarchiesi@0 3157 'length' => 255,
danielebarchiesi@0 3158 'not null' => TRUE,
danielebarchiesi@0 3159 'default' => '',
danielebarchiesi@0 3160 ),
danielebarchiesi@0 3161 ),
danielebarchiesi@0 3162 'indexes' => array(
danielebarchiesi@0 3163 'node_changed' => array('changed'),
danielebarchiesi@0 3164 'node_created' => array('created'),
danielebarchiesi@0 3165 ),
danielebarchiesi@0 3166 'unique keys' => array(
danielebarchiesi@0 3167 'nid_vid' => array('nid', 'vid'),
danielebarchiesi@0 3168 'vid' => array('vid'),
danielebarchiesi@0 3169 ),
danielebarchiesi@0 3170 'foreign keys' => array(
danielebarchiesi@0 3171 'node_revision' => array(
danielebarchiesi@0 3172 'table' => 'node_revision',
danielebarchiesi@0 3173 'columns' => array('vid' => 'vid'),
danielebarchiesi@0 3174 ),
danielebarchiesi@0 3175 'node_author' => array(
danielebarchiesi@0 3176 'table' => 'users',
danielebarchiesi@0 3177 'columns' => array('uid' => 'uid'),
danielebarchiesi@0 3178 ),
danielebarchiesi@0 3179 ),
danielebarchiesi@0 3180 'primary key' => array('nid'),
danielebarchiesi@0 3181 );
danielebarchiesi@0 3182 return $schema;
danielebarchiesi@0 3183 }
danielebarchiesi@0 3184
danielebarchiesi@0 3185 /**
danielebarchiesi@0 3186 * Perform alterations to existing database schemas.
danielebarchiesi@0 3187 *
danielebarchiesi@0 3188 * When a module modifies the database structure of another module (by
danielebarchiesi@0 3189 * changing, adding or removing fields, keys or indexes), it should
danielebarchiesi@0 3190 * implement hook_schema_alter() to update the default $schema to take its
danielebarchiesi@0 3191 * changes into account.
danielebarchiesi@0 3192 *
danielebarchiesi@0 3193 * See hook_schema() for details on the schema definition structure.
danielebarchiesi@0 3194 *
danielebarchiesi@0 3195 * @param $schema
danielebarchiesi@0 3196 * Nested array describing the schemas for all modules.
danielebarchiesi@0 3197 *
danielebarchiesi@0 3198 * @ingroup schemaapi
danielebarchiesi@0 3199 */
danielebarchiesi@0 3200 function hook_schema_alter(&$schema) {
danielebarchiesi@0 3201 // Add field to existing schema.
danielebarchiesi@0 3202 $schema['users']['fields']['timezone_id'] = array(
danielebarchiesi@0 3203 'type' => 'int',
danielebarchiesi@0 3204 'not null' => TRUE,
danielebarchiesi@0 3205 'default' => 0,
danielebarchiesi@0 3206 'description' => 'Per-user timezone configuration.',
danielebarchiesi@0 3207 );
danielebarchiesi@0 3208 }
danielebarchiesi@0 3209
danielebarchiesi@0 3210 /**
danielebarchiesi@0 3211 * Perform alterations to a structured query.
danielebarchiesi@0 3212 *
danielebarchiesi@0 3213 * Structured (aka dynamic) queries that have tags associated may be altered by any module
danielebarchiesi@0 3214 * before the query is executed.
danielebarchiesi@0 3215 *
danielebarchiesi@0 3216 * @param $query
danielebarchiesi@0 3217 * A Query object describing the composite parts of a SQL query.
danielebarchiesi@0 3218 *
danielebarchiesi@0 3219 * @see hook_query_TAG_alter()
danielebarchiesi@0 3220 * @see node_query_node_access_alter()
danielebarchiesi@0 3221 * @see QueryAlterableInterface
danielebarchiesi@0 3222 * @see SelectQueryInterface
danielebarchiesi@0 3223 */
danielebarchiesi@0 3224 function hook_query_alter(QueryAlterableInterface $query) {
danielebarchiesi@0 3225 if ($query->hasTag('micro_limit')) {
danielebarchiesi@0 3226 $query->range(0, 2);
danielebarchiesi@0 3227 }
danielebarchiesi@0 3228 }
danielebarchiesi@0 3229
danielebarchiesi@0 3230 /**
danielebarchiesi@0 3231 * Perform alterations to a structured query for a given tag.
danielebarchiesi@0 3232 *
danielebarchiesi@0 3233 * @param $query
danielebarchiesi@0 3234 * An Query object describing the composite parts of a SQL query.
danielebarchiesi@0 3235 *
danielebarchiesi@0 3236 * @see hook_query_alter()
danielebarchiesi@0 3237 * @see node_query_node_access_alter()
danielebarchiesi@0 3238 * @see QueryAlterableInterface
danielebarchiesi@0 3239 * @see SelectQueryInterface
danielebarchiesi@0 3240 */
danielebarchiesi@0 3241 function hook_query_TAG_alter(QueryAlterableInterface $query) {
danielebarchiesi@0 3242 // Skip the extra expensive alterations if site has no node access control modules.
danielebarchiesi@0 3243 if (!node_access_view_all_nodes()) {
danielebarchiesi@0 3244 // Prevent duplicates records.
danielebarchiesi@0 3245 $query->distinct();
danielebarchiesi@0 3246 // The recognized operations are 'view', 'update', 'delete'.
danielebarchiesi@0 3247 if (!$op = $query->getMetaData('op')) {
danielebarchiesi@0 3248 $op = 'view';
danielebarchiesi@0 3249 }
danielebarchiesi@0 3250 // Skip the extra joins and conditions for node admins.
danielebarchiesi@0 3251 if (!user_access('bypass node access')) {
danielebarchiesi@0 3252 // The node_access table has the access grants for any given node.
danielebarchiesi@0 3253 $access_alias = $query->join('node_access', 'na', '%alias.nid = n.nid');
danielebarchiesi@0 3254 $or = db_or();
danielebarchiesi@0 3255 // If any grant exists for the specified user, then user has access to the node for the specified operation.
danielebarchiesi@0 3256 foreach (node_access_grants($op, $query->getMetaData('account')) as $realm => $gids) {
danielebarchiesi@0 3257 foreach ($gids as $gid) {
danielebarchiesi@0 3258 $or->condition(db_and()
danielebarchiesi@0 3259 ->condition($access_alias . '.gid', $gid)
danielebarchiesi@0 3260 ->condition($access_alias . '.realm', $realm)
danielebarchiesi@0 3261 );
danielebarchiesi@0 3262 }
danielebarchiesi@0 3263 }
danielebarchiesi@0 3264
danielebarchiesi@0 3265 if (count($or->conditions())) {
danielebarchiesi@0 3266 $query->condition($or);
danielebarchiesi@0 3267 }
danielebarchiesi@0 3268
danielebarchiesi@0 3269 $query->condition($access_alias . 'grant_' . $op, 1, '>=');
danielebarchiesi@0 3270 }
danielebarchiesi@0 3271 }
danielebarchiesi@0 3272 }
danielebarchiesi@0 3273
danielebarchiesi@0 3274 /**
danielebarchiesi@0 3275 * Perform setup tasks when the module is installed.
danielebarchiesi@0 3276 *
danielebarchiesi@0 3277 * If the module implements hook_schema(), the database tables will
danielebarchiesi@0 3278 * be created before this hook is fired.
danielebarchiesi@0 3279 *
danielebarchiesi@0 3280 * Implementations of this hook are by convention declared in the module's
danielebarchiesi@0 3281 * .install file. The implementation can rely on the .module file being loaded.
danielebarchiesi@0 3282 * The hook will only be called the first time a module is enabled or after it
danielebarchiesi@0 3283 * is re-enabled after being uninstalled. The module's schema version will be
danielebarchiesi@0 3284 * set to the module's greatest numbered update hook. Because of this, any time
danielebarchiesi@0 3285 * a hook_update_N() is added to the module, this function needs to be updated
danielebarchiesi@0 3286 * to reflect the current version of the database schema.
danielebarchiesi@0 3287 *
danielebarchiesi@0 3288 * See the @link http://drupal.org/node/146843 Schema API documentation @endlink
danielebarchiesi@0 3289 * for details on hook_schema and how database tables are defined.
danielebarchiesi@0 3290 *
danielebarchiesi@0 3291 * Note that since this function is called from a full bootstrap, all functions
danielebarchiesi@0 3292 * (including those in modules enabled by the current page request) are
danielebarchiesi@0 3293 * available when this hook is called. Use cases could be displaying a user
danielebarchiesi@0 3294 * message, or calling a module function necessary for initial setup, etc.
danielebarchiesi@0 3295 *
danielebarchiesi@0 3296 * Please be sure that anything added or modified in this function that can
danielebarchiesi@0 3297 * be removed during uninstall should be removed with hook_uninstall().
danielebarchiesi@0 3298 *
danielebarchiesi@0 3299 * @see hook_schema()
danielebarchiesi@0 3300 * @see module_enable()
danielebarchiesi@0 3301 * @see hook_enable()
danielebarchiesi@0 3302 * @see hook_disable()
danielebarchiesi@0 3303 * @see hook_uninstall()
danielebarchiesi@0 3304 * @see hook_modules_installed()
danielebarchiesi@0 3305 */
danielebarchiesi@0 3306 function hook_install() {
danielebarchiesi@0 3307 // Populate the default {node_access} record.
danielebarchiesi@0 3308 db_insert('node_access')
danielebarchiesi@0 3309 ->fields(array(
danielebarchiesi@0 3310 'nid' => 0,
danielebarchiesi@0 3311 'gid' => 0,
danielebarchiesi@0 3312 'realm' => 'all',
danielebarchiesi@0 3313 'grant_view' => 1,
danielebarchiesi@0 3314 'grant_update' => 0,
danielebarchiesi@0 3315 'grant_delete' => 0,
danielebarchiesi@0 3316 ))
danielebarchiesi@0 3317 ->execute();
danielebarchiesi@0 3318 }
danielebarchiesi@0 3319
danielebarchiesi@0 3320 /**
danielebarchiesi@0 3321 * Perform a single update.
danielebarchiesi@0 3322 *
danielebarchiesi@0 3323 * For each change that requires one or more actions to be performed when
danielebarchiesi@0 3324 * updating a site, add a new hook_update_N(), which will be called by
danielebarchiesi@0 3325 * update.php. The documentation block preceding this function is stripped of
danielebarchiesi@0 3326 * newlines and used as the description for the update on the pending updates
danielebarchiesi@0 3327 * task list. Schema updates should adhere to the
danielebarchiesi@0 3328 * @link http://drupal.org/node/150215 Schema API. @endlink
danielebarchiesi@0 3329 *
danielebarchiesi@0 3330 * Implementations of hook_update_N() are named (module name)_update_(number).
danielebarchiesi@0 3331 * The numbers are composed of three parts:
danielebarchiesi@0 3332 * - 1 digit for Drupal core compatibility.
danielebarchiesi@0 3333 * - 1 digit for your module's major release version (e.g., is this the 7.x-1.*
danielebarchiesi@0 3334 * (1) or 7.x-2.* (2) series of your module?). This digit should be 0 for
danielebarchiesi@0 3335 * initial porting of your module to a new Drupal core API.
danielebarchiesi@0 3336 * - 2 digits for sequential counting, starting with 00.
danielebarchiesi@0 3337 *
danielebarchiesi@0 3338 * Examples:
danielebarchiesi@0 3339 * - mymodule_update_7000(): This is the required update for mymodule to run
danielebarchiesi@0 3340 * with Drupal core API 7.x when upgrading from Drupal core API 6.x.
danielebarchiesi@0 3341 * - mymodule_update_7100(): This is the first update to get the database ready
danielebarchiesi@0 3342 * to run mymodule 7.x-1.*.
danielebarchiesi@0 3343 * - mymodule_update_7200(): This is the first update to get the database ready
danielebarchiesi@0 3344 * to run mymodule 7.x-2.*. Users can directly update from 6.x-2.* to 7.x-2.*
danielebarchiesi@0 3345 * and they get all 70xx and 72xx updates, but not 71xx updates, because
danielebarchiesi@0 3346 * those reside in the 7.x-1.x branch only.
danielebarchiesi@0 3347 *
danielebarchiesi@0 3348 * A good rule of thumb is to remove updates older than two major releases of
danielebarchiesi@0 3349 * Drupal. See hook_update_last_removed() to notify Drupal about the removals.
danielebarchiesi@0 3350 * For further information about releases and release numbers see:
danielebarchiesi@0 3351 * @link http://drupal.org/node/711070 Maintaining a drupal.org project with Git @endlink
danielebarchiesi@0 3352 *
danielebarchiesi@0 3353 * Never renumber update functions.
danielebarchiesi@0 3354 *
danielebarchiesi@0 3355 * Implementations of this hook should be placed in a mymodule.install file in
danielebarchiesi@0 3356 * the same directory as mymodule.module. Drupal core's updates are implemented
danielebarchiesi@0 3357 * using the system module as a name and stored in database/updates.inc.
danielebarchiesi@0 3358 *
danielebarchiesi@0 3359 * Not all module functions are available from within a hook_update_N() function.
danielebarchiesi@0 3360 * In order to call a function from your mymodule.module or an include file,
danielebarchiesi@0 3361 * you need to explicitly load that file first.
danielebarchiesi@0 3362 *
danielebarchiesi@0 3363 * During database updates the schema of any module could be out of date. For
danielebarchiesi@0 3364 * this reason, caution is needed when using any API function within an update
danielebarchiesi@0 3365 * function - particularly CRUD functions, functions that depend on the schema
danielebarchiesi@0 3366 * (for example by using drupal_write_record()), and any functions that invoke
danielebarchiesi@0 3367 * hooks. See @link update_api Update versions of API functions @endlink for
danielebarchiesi@0 3368 * details.
danielebarchiesi@0 3369 *
danielebarchiesi@0 3370 * If your update task is potentially time-consuming, you'll need to implement a
danielebarchiesi@0 3371 * multipass update to avoid PHP timeouts. Multipass updates use the $sandbox
danielebarchiesi@0 3372 * parameter provided by the batch API (normally, $context['sandbox']) to store
danielebarchiesi@0 3373 * information between successive calls, and the $sandbox['#finished'] value
danielebarchiesi@0 3374 * to provide feedback regarding completion level.
danielebarchiesi@0 3375 *
danielebarchiesi@0 3376 * See the batch operations page for more information on how to use the
danielebarchiesi@0 3377 * @link http://drupal.org/node/180528 Batch API. @endlink
danielebarchiesi@0 3378 *
danielebarchiesi@0 3379 * @param $sandbox
danielebarchiesi@0 3380 * Stores information for multipass updates. See above for more information.
danielebarchiesi@0 3381 *
danielebarchiesi@0 3382 * @throws DrupalUpdateException, PDOException
danielebarchiesi@0 3383 * In case of error, update hooks should throw an instance of DrupalUpdateException
danielebarchiesi@0 3384 * with a meaningful message for the user. If a database query fails for whatever
danielebarchiesi@0 3385 * reason, it will throw a PDOException.
danielebarchiesi@0 3386 *
danielebarchiesi@0 3387 * @return
danielebarchiesi@0 3388 * Optionally, update hooks may return a translated string that will be
danielebarchiesi@0 3389 * displayed to the user after the update has completed. If no message is
danielebarchiesi@0 3390 * returned, no message will be presented to the user.
danielebarchiesi@0 3391 *
danielebarchiesi@0 3392 * @see batch
danielebarchiesi@0 3393 * @see schemaapi
danielebarchiesi@0 3394 * @see update_api
danielebarchiesi@0 3395 * @see hook_update_last_removed()
danielebarchiesi@0 3396 * @see update_get_update_list()
danielebarchiesi@0 3397 */
danielebarchiesi@0 3398 function hook_update_N(&$sandbox) {
danielebarchiesi@0 3399 // For non-multipass updates, the signature can simply be;
danielebarchiesi@0 3400 // function hook_update_N() {
danielebarchiesi@0 3401
danielebarchiesi@0 3402 // For most updates, the following is sufficient.
danielebarchiesi@0 3403 db_add_field('mytable1', 'newcol', array('type' => 'int', 'not null' => TRUE, 'description' => 'My new integer column.'));
danielebarchiesi@0 3404
danielebarchiesi@0 3405 // However, for more complex operations that may take a long time,
danielebarchiesi@0 3406 // you may hook into Batch API as in the following example.
danielebarchiesi@0 3407
danielebarchiesi@0 3408 // Update 3 users at a time to have an exclamation point after their names.
danielebarchiesi@0 3409 // (They're really happy that we can do batch API in this hook!)
danielebarchiesi@0 3410 if (!isset($sandbox['progress'])) {
danielebarchiesi@0 3411 $sandbox['progress'] = 0;
danielebarchiesi@0 3412 $sandbox['current_uid'] = 0;
danielebarchiesi@0 3413 // We'll -1 to disregard the uid 0...
danielebarchiesi@0 3414 $sandbox['max'] = db_query('SELECT COUNT(DISTINCT uid) FROM {users}')->fetchField() - 1;
danielebarchiesi@0 3415 }
danielebarchiesi@0 3416
danielebarchiesi@0 3417 $users = db_select('users', 'u')
danielebarchiesi@0 3418 ->fields('u', array('uid', 'name'))
danielebarchiesi@0 3419 ->condition('uid', $sandbox['current_uid'], '>')
danielebarchiesi@0 3420 ->range(0, 3)
danielebarchiesi@0 3421 ->orderBy('uid', 'ASC')
danielebarchiesi@0 3422 ->execute();
danielebarchiesi@0 3423
danielebarchiesi@0 3424 foreach ($users as $user) {
danielebarchiesi@0 3425 $user->name .= '!';
danielebarchiesi@0 3426 db_update('users')
danielebarchiesi@0 3427 ->fields(array('name' => $user->name))
danielebarchiesi@0 3428 ->condition('uid', $user->uid)
danielebarchiesi@0 3429 ->execute();
danielebarchiesi@0 3430
danielebarchiesi@0 3431 $sandbox['progress']++;
danielebarchiesi@0 3432 $sandbox['current_uid'] = $user->uid;
danielebarchiesi@0 3433 }
danielebarchiesi@0 3434
danielebarchiesi@0 3435 $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
danielebarchiesi@0 3436
danielebarchiesi@0 3437 // To display a message to the user when the update is completed, return it.
danielebarchiesi@0 3438 // If you do not want to display a completion message, simply return nothing.
danielebarchiesi@0 3439 return t('The update did what it was supposed to do.');
danielebarchiesi@0 3440
danielebarchiesi@0 3441 // In case of an error, simply throw an exception with an error message.
danielebarchiesi@0 3442 throw new DrupalUpdateException('Something went wrong; here is what you should do.');
danielebarchiesi@0 3443 }
danielebarchiesi@0 3444
danielebarchiesi@0 3445 /**
danielebarchiesi@0 3446 * Return an array of information about module update dependencies.
danielebarchiesi@0 3447 *
danielebarchiesi@0 3448 * This can be used to indicate update functions from other modules that your
danielebarchiesi@0 3449 * module's update functions depend on, or vice versa. It is used by the update
danielebarchiesi@0 3450 * system to determine the appropriate order in which updates should be run, as
danielebarchiesi@0 3451 * well as to search for missing dependencies.
danielebarchiesi@0 3452 *
danielebarchiesi@0 3453 * Implementations of this hook should be placed in a mymodule.install file in
danielebarchiesi@0 3454 * the same directory as mymodule.module.
danielebarchiesi@0 3455 *
danielebarchiesi@0 3456 * @return
danielebarchiesi@0 3457 * A multidimensional array containing information about the module update
danielebarchiesi@0 3458 * dependencies. The first two levels of keys represent the module and update
danielebarchiesi@0 3459 * number (respectively) for which information is being returned, and the
danielebarchiesi@0 3460 * value is an array of information about that update's dependencies. Within
danielebarchiesi@0 3461 * this array, each key represents a module, and each value represents the
danielebarchiesi@0 3462 * number of an update function within that module. In the event that your
danielebarchiesi@0 3463 * update function depends on more than one update from a particular module,
danielebarchiesi@0 3464 * you should always list the highest numbered one here (since updates within
danielebarchiesi@0 3465 * a given module always run in numerical order).
danielebarchiesi@0 3466 *
danielebarchiesi@0 3467 * @see update_resolve_dependencies()
danielebarchiesi@0 3468 * @see hook_update_N()
danielebarchiesi@0 3469 */
danielebarchiesi@0 3470 function hook_update_dependencies() {
danielebarchiesi@0 3471 // Indicate that the mymodule_update_7000() function provided by this module
danielebarchiesi@0 3472 // must run after the another_module_update_7002() function provided by the
danielebarchiesi@0 3473 // 'another_module' module.
danielebarchiesi@0 3474 $dependencies['mymodule'][7000] = array(
danielebarchiesi@0 3475 'another_module' => 7002,
danielebarchiesi@0 3476 );
danielebarchiesi@0 3477 // Indicate that the mymodule_update_7001() function provided by this module
danielebarchiesi@0 3478 // must run before the yet_another_module_update_7004() function provided by
danielebarchiesi@0 3479 // the 'yet_another_module' module. (Note that declaring dependencies in this
danielebarchiesi@0 3480 // direction should be done only in rare situations, since it can lead to the
danielebarchiesi@0 3481 // following problem: If a site has already run the yet_another_module
danielebarchiesi@0 3482 // module's database updates before it updates its codebase to pick up the
danielebarchiesi@0 3483 // newest mymodule code, then the dependency declared here will be ignored.)
danielebarchiesi@0 3484 $dependencies['yet_another_module'][7004] = array(
danielebarchiesi@0 3485 'mymodule' => 7001,
danielebarchiesi@0 3486 );
danielebarchiesi@0 3487 return $dependencies;
danielebarchiesi@0 3488 }
danielebarchiesi@0 3489
danielebarchiesi@0 3490 /**
danielebarchiesi@0 3491 * Return a number which is no longer available as hook_update_N().
danielebarchiesi@0 3492 *
danielebarchiesi@0 3493 * If you remove some update functions from your mymodule.install file, you
danielebarchiesi@0 3494 * should notify Drupal of those missing functions. This way, Drupal can
danielebarchiesi@0 3495 * ensure that no update is accidentally skipped.
danielebarchiesi@0 3496 *
danielebarchiesi@0 3497 * Implementations of this hook should be placed in a mymodule.install file in
danielebarchiesi@0 3498 * the same directory as mymodule.module.
danielebarchiesi@0 3499 *
danielebarchiesi@0 3500 * @return
danielebarchiesi@0 3501 * An integer, corresponding to hook_update_N() which has been removed from
danielebarchiesi@0 3502 * mymodule.install.
danielebarchiesi@0 3503 *
danielebarchiesi@0 3504 * @see hook_update_N()
danielebarchiesi@0 3505 */
danielebarchiesi@0 3506 function hook_update_last_removed() {
danielebarchiesi@0 3507 // We've removed the 5.x-1.x version of mymodule, including database updates.
danielebarchiesi@0 3508 // The next update function is mymodule_update_5200().
danielebarchiesi@0 3509 return 5103;
danielebarchiesi@0 3510 }
danielebarchiesi@0 3511
danielebarchiesi@0 3512 /**
danielebarchiesi@0 3513 * Remove any information that the module sets.
danielebarchiesi@0 3514 *
danielebarchiesi@0 3515 * The information that the module should remove includes:
danielebarchiesi@0 3516 * - variables that the module has set using variable_set() or system_settings_form()
danielebarchiesi@0 3517 * - modifications to existing tables
danielebarchiesi@0 3518 *
danielebarchiesi@0 3519 * The module should not remove its entry from the {system} table. Database
danielebarchiesi@0 3520 * tables defined by hook_schema() will be removed automatically.
danielebarchiesi@0 3521 *
danielebarchiesi@0 3522 * The uninstall hook must be implemented in the module's .install file. It
danielebarchiesi@0 3523 * will fire when the module gets uninstalled but before the module's database
danielebarchiesi@0 3524 * tables are removed, allowing your module to query its own tables during
danielebarchiesi@0 3525 * this routine.
danielebarchiesi@0 3526 *
danielebarchiesi@0 3527 * When hook_uninstall() is called, your module will already be disabled, so
danielebarchiesi@0 3528 * its .module file will not be automatically included. If you need to call API
danielebarchiesi@0 3529 * functions from your .module file in this hook, use drupal_load() to make
danielebarchiesi@0 3530 * them available. (Keep this usage to a minimum, though, especially when
danielebarchiesi@0 3531 * calling API functions that invoke hooks, or API functions from modules
danielebarchiesi@0 3532 * listed as dependencies, since these may not be available or work as expected
danielebarchiesi@0 3533 * when the module is disabled.)
danielebarchiesi@0 3534 *
danielebarchiesi@0 3535 * @see hook_install()
danielebarchiesi@0 3536 * @see hook_schema()
danielebarchiesi@0 3537 * @see hook_disable()
danielebarchiesi@0 3538 * @see hook_modules_uninstalled()
danielebarchiesi@0 3539 */
danielebarchiesi@0 3540 function hook_uninstall() {
danielebarchiesi@0 3541 variable_del('upload_file_types');
danielebarchiesi@0 3542 }
danielebarchiesi@0 3543
danielebarchiesi@0 3544 /**
danielebarchiesi@0 3545 * Perform necessary actions after module is enabled.
danielebarchiesi@0 3546 *
danielebarchiesi@0 3547 * The hook is called every time the module is enabled. It should be
danielebarchiesi@0 3548 * implemented in the module's .install file. The implementation can
danielebarchiesi@0 3549 * rely on the .module file being loaded.
danielebarchiesi@0 3550 *
danielebarchiesi@0 3551 * @see module_enable()
danielebarchiesi@0 3552 * @see hook_install()
danielebarchiesi@0 3553 * @see hook_modules_enabled()
danielebarchiesi@0 3554 */
danielebarchiesi@0 3555 function hook_enable() {
danielebarchiesi@0 3556 mymodule_cache_rebuild();
danielebarchiesi@0 3557 }
danielebarchiesi@0 3558
danielebarchiesi@0 3559 /**
danielebarchiesi@0 3560 * Perform necessary actions before module is disabled.
danielebarchiesi@0 3561 *
danielebarchiesi@0 3562 * The hook is called every time the module is disabled. It should be
danielebarchiesi@0 3563 * implemented in the module's .install file. The implementation can rely
danielebarchiesi@0 3564 * on the .module file being loaded.
danielebarchiesi@0 3565 *
danielebarchiesi@0 3566 * @see hook_uninstall()
danielebarchiesi@0 3567 * @see hook_modules_disabled()
danielebarchiesi@0 3568 */
danielebarchiesi@0 3569 function hook_disable() {
danielebarchiesi@0 3570 mymodule_cache_rebuild();
danielebarchiesi@0 3571 }
danielebarchiesi@0 3572
danielebarchiesi@0 3573 /**
danielebarchiesi@0 3574 * Perform necessary alterations to the list of files parsed by the registry.
danielebarchiesi@0 3575 *
danielebarchiesi@0 3576 * Modules can manually modify the list of files before the registry parses
danielebarchiesi@0 3577 * them. The $modules array provides the .info file information, which includes
danielebarchiesi@0 3578 * the list of files registered to each module. Any files in the list can then
danielebarchiesi@0 3579 * be added to the list of files that the registry will parse, or modify
danielebarchiesi@0 3580 * attributes of a file.
danielebarchiesi@0 3581 *
danielebarchiesi@0 3582 * A necessary alteration made by the core SimpleTest module is to force .test
danielebarchiesi@0 3583 * files provided by disabled modules into the list of files parsed by the
danielebarchiesi@0 3584 * registry.
danielebarchiesi@0 3585 *
danielebarchiesi@0 3586 * @param $files
danielebarchiesi@0 3587 * List of files to be parsed by the registry. The list will contain
danielebarchiesi@0 3588 * files found in each enabled module's info file and the core includes
danielebarchiesi@0 3589 * directory. The array is keyed by the file path and contains an array of
danielebarchiesi@0 3590 * the related module's name and weight as used internally by
danielebarchiesi@0 3591 * _registry_update() and related functions.
danielebarchiesi@0 3592 *
danielebarchiesi@0 3593 * For example:
danielebarchiesi@0 3594 * @code
danielebarchiesi@0 3595 * $files["modules/system/system.module"] = array(
danielebarchiesi@0 3596 * 'module' => 'system',
danielebarchiesi@0 3597 * 'weight' => 0,
danielebarchiesi@0 3598 * );
danielebarchiesi@0 3599 * @endcode
danielebarchiesi@0 3600 * @param $modules
danielebarchiesi@0 3601 * An array containing all module information stored in the {system} table.
danielebarchiesi@0 3602 * Each element of the array also contains the module's .info file
danielebarchiesi@0 3603 * information in the property 'info'. An additional 'dir' property has been
danielebarchiesi@0 3604 * added to the module information which provides the path to the directory
danielebarchiesi@0 3605 * in which the module resides. The example shows how to take advantage of
danielebarchiesi@0 3606 * both properties.
danielebarchiesi@0 3607 *
danielebarchiesi@0 3608 * @see _registry_update()
danielebarchiesi@0 3609 * @see simpletest_test_get_all()
danielebarchiesi@0 3610 */
danielebarchiesi@0 3611 function hook_registry_files_alter(&$files, $modules) {
danielebarchiesi@0 3612 foreach ($modules as $module) {
danielebarchiesi@0 3613 // Only add test files for disabled modules, as enabled modules should
danielebarchiesi@0 3614 // already include any test files they provide.
danielebarchiesi@0 3615 if (!$module->status) {
danielebarchiesi@0 3616 $dir = $module->dir;
danielebarchiesi@0 3617 foreach ($module->info['files'] as $file) {
danielebarchiesi@0 3618 if (substr($file, -5) == '.test') {
danielebarchiesi@0 3619 $files["$dir/$file"] = array('module' => $module->name, 'weight' => $module->weight);
danielebarchiesi@0 3620 }
danielebarchiesi@0 3621 }
danielebarchiesi@0 3622 }
danielebarchiesi@0 3623 }
danielebarchiesi@0 3624 }
danielebarchiesi@0 3625
danielebarchiesi@0 3626 /**
danielebarchiesi@0 3627 * Return an array of tasks to be performed by an installation profile.
danielebarchiesi@0 3628 *
danielebarchiesi@0 3629 * Any tasks you define here will be run, in order, after the installer has
danielebarchiesi@0 3630 * finished the site configuration step but before it has moved on to the
danielebarchiesi@0 3631 * final import of languages and the end of the installation. You can have any
danielebarchiesi@0 3632 * number of custom tasks to perform during this phase.
danielebarchiesi@0 3633 *
danielebarchiesi@0 3634 * Each task you define here corresponds to a callback function which you must
danielebarchiesi@0 3635 * separately define and which is called when your task is run. This function
danielebarchiesi@0 3636 * will receive the global installation state variable, $install_state, as
danielebarchiesi@0 3637 * input, and has the opportunity to access or modify any of its settings. See
danielebarchiesi@0 3638 * the install_state_defaults() function in the installer for the list of
danielebarchiesi@0 3639 * $install_state settings used by Drupal core.
danielebarchiesi@0 3640 *
danielebarchiesi@0 3641 * At the end of your task function, you can indicate that you want the
danielebarchiesi@0 3642 * installer to pause and display a page to the user by returning any themed
danielebarchiesi@0 3643 * output that should be displayed on that page (but see below for tasks that
danielebarchiesi@0 3644 * use the form API or batch API; the return values of these task functions are
danielebarchiesi@0 3645 * handled differently). You should also use drupal_set_title() within the task
danielebarchiesi@0 3646 * callback function to set a custom page title. For some tasks, however, you
danielebarchiesi@0 3647 * may want to simply do some processing and pass control to the next task
danielebarchiesi@0 3648 * without ending the page request; to indicate this, simply do not send back
danielebarchiesi@0 3649 * a return value from your task function at all. This can be used, for
danielebarchiesi@0 3650 * example, by installation profiles that need to configure certain site
danielebarchiesi@0 3651 * settings in the database without obtaining any input from the user.
danielebarchiesi@0 3652 *
danielebarchiesi@0 3653 * The task function is treated specially if it defines a form or requires
danielebarchiesi@0 3654 * batch processing; in that case, you should return either the form API
danielebarchiesi@0 3655 * definition or batch API array, as appropriate. See below for more
danielebarchiesi@0 3656 * information on the 'type' key that you must define in the task definition
danielebarchiesi@0 3657 * to inform the installer that your task falls into one of those two
danielebarchiesi@0 3658 * categories. It is important to use these APIs directly, since the installer
danielebarchiesi@0 3659 * may be run non-interactively (for example, via a command line script), all
danielebarchiesi@0 3660 * in one page request; in that case, the installer will automatically take
danielebarchiesi@0 3661 * care of submitting forms and processing batches correctly for both types of
danielebarchiesi@0 3662 * installations. You can inspect the $install_state['interactive'] boolean to
danielebarchiesi@0 3663 * see whether or not the current installation is interactive, if you need
danielebarchiesi@0 3664 * access to this information.
danielebarchiesi@0 3665 *
danielebarchiesi@0 3666 * Remember that a user installing Drupal interactively will be able to reload
danielebarchiesi@0 3667 * an installation page multiple times, so you should use variable_set() and
danielebarchiesi@0 3668 * variable_get() if you are collecting any data that you need to store and
danielebarchiesi@0 3669 * inspect later. It is important to remove any temporary variables using
danielebarchiesi@0 3670 * variable_del() before your last task has completed and control is handed
danielebarchiesi@0 3671 * back to the installer.
danielebarchiesi@0 3672 *
danielebarchiesi@0 3673 * @param array $install_state
danielebarchiesi@0 3674 * An array of information about the current installation state.
danielebarchiesi@0 3675 *
danielebarchiesi@0 3676 * @return array
danielebarchiesi@0 3677 * A keyed array of tasks the profile will perform during the final stage of
danielebarchiesi@0 3678 * the installation. Each key represents the name of a function (usually a
danielebarchiesi@0 3679 * function defined by this profile, although that is not strictly required)
danielebarchiesi@0 3680 * that is called when that task is run. The values are associative arrays
danielebarchiesi@0 3681 * containing the following key-value pairs (all of which are optional):
danielebarchiesi@0 3682 * - display_name: The human-readable name of the task. This will be
danielebarchiesi@0 3683 * displayed to the user while the installer is running, along with a list
danielebarchiesi@0 3684 * of other tasks that are being run. Leave this unset to prevent the task
danielebarchiesi@0 3685 * from appearing in the list.
danielebarchiesi@0 3686 * - display: This is a boolean which can be used to provide finer-grained
danielebarchiesi@0 3687 * control over whether or not the task will display. This is mostly useful
danielebarchiesi@0 3688 * for tasks that are intended to display only under certain conditions;
danielebarchiesi@0 3689 * for these tasks, you can set 'display_name' to the name that you want to
danielebarchiesi@0 3690 * display, but then use this boolean to hide the task only when certain
danielebarchiesi@0 3691 * conditions apply.
danielebarchiesi@0 3692 * - type: A string representing the type of task. This parameter has three
danielebarchiesi@0 3693 * possible values:
danielebarchiesi@0 3694 * - normal: (default) This indicates that the task will be treated as a
danielebarchiesi@0 3695 * regular callback function, which does its processing and optionally
danielebarchiesi@0 3696 * returns HTML output.
danielebarchiesi@0 3697 * - batch: This indicates that the task function will return a batch API
danielebarchiesi@0 3698 * definition suitable for batch_set(). The installer will then take care
danielebarchiesi@0 3699 * of automatically running the task via batch processing.
danielebarchiesi@0 3700 * - form: This indicates that the task function will return a standard
danielebarchiesi@0 3701 * form API definition (and separately define validation and submit
danielebarchiesi@0 3702 * handlers, as appropriate). The installer will then take care of
danielebarchiesi@0 3703 * automatically directing the user through the form submission process.
danielebarchiesi@0 3704 * - run: A constant representing the manner in which the task will be run.
danielebarchiesi@0 3705 * This parameter has three possible values:
danielebarchiesi@0 3706 * - INSTALL_TASK_RUN_IF_NOT_COMPLETED: (default) This indicates that the
danielebarchiesi@0 3707 * task will run once during the installation of the profile.
danielebarchiesi@0 3708 * - INSTALL_TASK_SKIP: This indicates that the task will not run during
danielebarchiesi@0 3709 * the current installation page request. It can be used to skip running
danielebarchiesi@0 3710 * an installation task when certain conditions are met, even though the
danielebarchiesi@0 3711 * task may still show on the list of installation tasks presented to the
danielebarchiesi@0 3712 * user.
danielebarchiesi@0 3713 * - INSTALL_TASK_RUN_IF_REACHED: This indicates that the task will run on
danielebarchiesi@0 3714 * each installation page request that reaches it. This is rarely
danielebarchiesi@0 3715 * necessary for an installation profile to use; it is primarily used by
danielebarchiesi@0 3716 * the Drupal installer for bootstrap-related tasks.
danielebarchiesi@0 3717 * - function: Normally this does not need to be set, but it can be used to
danielebarchiesi@0 3718 * force the installer to call a different function when the task is run
danielebarchiesi@0 3719 * (rather than the function whose name is given by the array key). This
danielebarchiesi@0 3720 * could be used, for example, to allow the same function to be called by
danielebarchiesi@0 3721 * two different tasks.
danielebarchiesi@0 3722 *
danielebarchiesi@0 3723 * @see install_state_defaults()
danielebarchiesi@0 3724 * @see batch_set()
danielebarchiesi@0 3725 */
danielebarchiesi@0 3726 function hook_install_tasks(&$install_state) {
danielebarchiesi@0 3727 // Here, we define a variable to allow tasks to indicate that a particular,
danielebarchiesi@0 3728 // processor-intensive batch process needs to be triggered later on in the
danielebarchiesi@0 3729 // installation.
danielebarchiesi@0 3730 $myprofile_needs_batch_processing = variable_get('myprofile_needs_batch_processing', FALSE);
danielebarchiesi@0 3731 $tasks = array(
danielebarchiesi@0 3732 // This is an example of a task that defines a form which the user who is
danielebarchiesi@0 3733 // installing the site will be asked to fill out. To implement this task,
danielebarchiesi@0 3734 // your profile would define a function named myprofile_data_import_form()
danielebarchiesi@0 3735 // as a normal form API callback function, with associated validation and
danielebarchiesi@0 3736 // submit handlers. In the submit handler, in addition to saving whatever
danielebarchiesi@0 3737 // other data you have collected from the user, you might also call
danielebarchiesi@0 3738 // variable_set('myprofile_needs_batch_processing', TRUE) if the user has
danielebarchiesi@0 3739 // entered data which requires that batch processing will need to occur
danielebarchiesi@0 3740 // later on.
danielebarchiesi@0 3741 'myprofile_data_import_form' => array(
danielebarchiesi@0 3742 'display_name' => st('Data import options'),
danielebarchiesi@0 3743 'type' => 'form',
danielebarchiesi@0 3744 ),
danielebarchiesi@0 3745 // Similarly, to implement this task, your profile would define a function
danielebarchiesi@0 3746 // named myprofile_settings_form() with associated validation and submit
danielebarchiesi@0 3747 // handlers. This form might be used to collect and save additional
danielebarchiesi@0 3748 // information from the user that your profile needs. There are no extra
danielebarchiesi@0 3749 // steps required for your profile to act as an "installation wizard"; you
danielebarchiesi@0 3750 // can simply define as many tasks of type 'form' as you wish to execute,
danielebarchiesi@0 3751 // and the forms will be presented to the user, one after another.
danielebarchiesi@0 3752 'myprofile_settings_form' => array(
danielebarchiesi@0 3753 'display_name' => st('Additional options'),
danielebarchiesi@0 3754 'type' => 'form',
danielebarchiesi@0 3755 ),
danielebarchiesi@0 3756 // This is an example of a task that performs batch operations. To
danielebarchiesi@0 3757 // implement this task, your profile would define a function named
danielebarchiesi@0 3758 // myprofile_batch_processing() which returns a batch API array definition
danielebarchiesi@0 3759 // that the installer will use to execute your batch operations. Due to the
danielebarchiesi@0 3760 // 'myprofile_needs_batch_processing' variable used here, this task will be
danielebarchiesi@0 3761 // hidden and skipped unless your profile set it to TRUE in one of the
danielebarchiesi@0 3762 // previous tasks.
danielebarchiesi@0 3763 'myprofile_batch_processing' => array(
danielebarchiesi@0 3764 'display_name' => st('Import additional data'),
danielebarchiesi@0 3765 'display' => $myprofile_needs_batch_processing,
danielebarchiesi@0 3766 'type' => 'batch',
danielebarchiesi@0 3767 'run' => $myprofile_needs_batch_processing ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
danielebarchiesi@0 3768 ),
danielebarchiesi@0 3769 // This is an example of a task that will not be displayed in the list that
danielebarchiesi@0 3770 // the user sees. To implement this task, your profile would define a
danielebarchiesi@0 3771 // function named myprofile_final_site_setup(), in which additional,
danielebarchiesi@0 3772 // automated site setup operations would be performed. Since this is the
danielebarchiesi@0 3773 // last task defined by your profile, you should also use this function to
danielebarchiesi@0 3774 // call variable_del('myprofile_needs_batch_processing') and clean up the
danielebarchiesi@0 3775 // variable that was used above. If you want the user to pass to the final
danielebarchiesi@0 3776 // Drupal installation tasks uninterrupted, return no output from this
danielebarchiesi@0 3777 // function. Otherwise, return themed output that the user will see (for
danielebarchiesi@0 3778 // example, a confirmation page explaining that your profile's tasks are
danielebarchiesi@0 3779 // complete, with a link to reload the current page and therefore pass on
danielebarchiesi@0 3780 // to the final Drupal installation tasks when the user is ready to do so).
danielebarchiesi@0 3781 'myprofile_final_site_setup' => array(
danielebarchiesi@0 3782 ),
danielebarchiesi@0 3783 );
danielebarchiesi@0 3784 return $tasks;
danielebarchiesi@0 3785 }
danielebarchiesi@0 3786
danielebarchiesi@0 3787 /**
danielebarchiesi@0 3788 * Change the page the user is sent to by drupal_goto().
danielebarchiesi@0 3789 *
danielebarchiesi@0 3790 * @param $path
danielebarchiesi@0 3791 * A Drupal path or a full URL.
danielebarchiesi@0 3792 * @param $options
danielebarchiesi@0 3793 * An associative array of additional URL options to pass to url().
danielebarchiesi@0 3794 * @param $http_response_code
danielebarchiesi@0 3795 * The HTTP status code to use for the redirection. See drupal_goto() for more
danielebarchiesi@0 3796 * information.
danielebarchiesi@0 3797 */
danielebarchiesi@0 3798 function hook_drupal_goto_alter(&$path, &$options, &$http_response_code) {
danielebarchiesi@0 3799 // A good addition to misery module.
danielebarchiesi@0 3800 $http_response_code = 500;
danielebarchiesi@0 3801 }
danielebarchiesi@0 3802
danielebarchiesi@0 3803 /**
danielebarchiesi@0 3804 * Alter XHTML HEAD tags before they are rendered by drupal_get_html_head().
danielebarchiesi@0 3805 *
danielebarchiesi@0 3806 * Elements available to be altered are only those added using
danielebarchiesi@0 3807 * drupal_add_html_head_link() or drupal_add_html_head(). CSS and JS files
danielebarchiesi@0 3808 * are handled using drupal_add_css() and drupal_add_js(), so the head links
danielebarchiesi@0 3809 * for those files will not appear in the $head_elements array.
danielebarchiesi@0 3810 *
danielebarchiesi@0 3811 * @param $head_elements
danielebarchiesi@0 3812 * An array of renderable elements. Generally the values of the #attributes
danielebarchiesi@0 3813 * array will be the most likely target for changes.
danielebarchiesi@0 3814 */
danielebarchiesi@0 3815 function hook_html_head_alter(&$head_elements) {
danielebarchiesi@0 3816 foreach ($head_elements as $key => $element) {
danielebarchiesi@0 3817 if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') {
danielebarchiesi@0 3818 // I want a custom canonical URL.
danielebarchiesi@0 3819 $head_elements[$key]['#attributes']['href'] = mymodule_canonical_url();
danielebarchiesi@0 3820 }
danielebarchiesi@0 3821 }
danielebarchiesi@0 3822 }
danielebarchiesi@0 3823
danielebarchiesi@0 3824 /**
danielebarchiesi@0 3825 * Alter the full list of installation tasks.
danielebarchiesi@0 3826 *
danielebarchiesi@0 3827 * @param $tasks
danielebarchiesi@0 3828 * An array of all available installation tasks, including those provided by
danielebarchiesi@0 3829 * Drupal core. You can modify this array to change or replace any part of
danielebarchiesi@0 3830 * the Drupal installation process that occurs after the installation profile
danielebarchiesi@0 3831 * is selected.
danielebarchiesi@0 3832 * @param $install_state
danielebarchiesi@0 3833 * An array of information about the current installation state.
danielebarchiesi@0 3834 */
danielebarchiesi@0 3835 function hook_install_tasks_alter(&$tasks, $install_state) {
danielebarchiesi@0 3836 // Replace the "Choose language" installation task provided by Drupal core
danielebarchiesi@0 3837 // with a custom callback function defined by this installation profile.
danielebarchiesi@0 3838 $tasks['install_select_locale']['function'] = 'myprofile_locale_selection';
danielebarchiesi@0 3839 }
danielebarchiesi@0 3840
danielebarchiesi@0 3841 /**
danielebarchiesi@0 3842 * Alter MIME type mappings used to determine MIME type from a file extension.
danielebarchiesi@0 3843 *
danielebarchiesi@0 3844 * This hook is run when file_mimetype_mapping() is called. It is used to
danielebarchiesi@0 3845 * allow modules to add to or modify the default mapping from
danielebarchiesi@0 3846 * file_default_mimetype_mapping().
danielebarchiesi@0 3847 *
danielebarchiesi@0 3848 * @param $mapping
danielebarchiesi@0 3849 * An array of mimetypes correlated to the extensions that relate to them.
danielebarchiesi@0 3850 * The array has 'mimetypes' and 'extensions' elements, each of which is an
danielebarchiesi@0 3851 * array.
danielebarchiesi@0 3852 *
danielebarchiesi@0 3853 * @see file_default_mimetype_mapping()
danielebarchiesi@0 3854 */
danielebarchiesi@0 3855 function hook_file_mimetype_mapping_alter(&$mapping) {
danielebarchiesi@0 3856 // Add new MIME type 'drupal/info'.
danielebarchiesi@0 3857 $mapping['mimetypes']['example_info'] = 'drupal/info';
danielebarchiesi@0 3858 // Add new extension '.info' and map it to the 'drupal/info' MIME type.
danielebarchiesi@0 3859 $mapping['extensions']['info'] = 'example_info';
danielebarchiesi@0 3860 // Override existing extension mapping for '.ogg' files.
danielebarchiesi@0 3861 $mapping['extensions']['ogg'] = 189;
danielebarchiesi@0 3862 }
danielebarchiesi@0 3863
danielebarchiesi@0 3864 /**
danielebarchiesi@0 3865 * Declares information about actions.
danielebarchiesi@0 3866 *
danielebarchiesi@0 3867 * Any module can define actions, and then call actions_do() to make those
danielebarchiesi@0 3868 * actions happen in response to events. The trigger module provides a user
danielebarchiesi@0 3869 * interface for associating actions with module-defined triggers, and it makes
danielebarchiesi@0 3870 * sure the core triggers fire off actions when their events happen.
danielebarchiesi@0 3871 *
danielebarchiesi@0 3872 * An action consists of two or three parts:
danielebarchiesi@0 3873 * - an action definition (returned by this hook)
danielebarchiesi@0 3874 * - a function which performs the action (which by convention is named
danielebarchiesi@0 3875 * MODULE_description-of-function_action)
danielebarchiesi@0 3876 * - an optional form definition function that defines a configuration form
danielebarchiesi@0 3877 * (which has the name of the action function with '_form' appended to it.)
danielebarchiesi@0 3878 *
danielebarchiesi@0 3879 * The action function takes two to four arguments, which come from the input
danielebarchiesi@0 3880 * arguments to actions_do().
danielebarchiesi@0 3881 *
danielebarchiesi@0 3882 * @return
danielebarchiesi@0 3883 * An associative array of action descriptions. The keys of the array
danielebarchiesi@0 3884 * are the names of the action functions, and each corresponding value
danielebarchiesi@0 3885 * is an associative array with the following key-value pairs:
danielebarchiesi@0 3886 * - 'type': The type of object this action acts upon. Core actions have types
danielebarchiesi@0 3887 * 'node', 'user', 'comment', and 'system'.
danielebarchiesi@0 3888 * - 'label': The human-readable name of the action, which should be passed
danielebarchiesi@0 3889 * through the t() function for translation.
danielebarchiesi@0 3890 * - 'configurable': If FALSE, then the action doesn't require any extra
danielebarchiesi@0 3891 * configuration. If TRUE, then your module must define a form function with
danielebarchiesi@0 3892 * the same name as the action function with '_form' appended (e.g., the
danielebarchiesi@0 3893 * form for 'node_assign_owner_action' is 'node_assign_owner_action_form'.)
danielebarchiesi@0 3894 * This function takes $context as its only parameter, and is paired with
danielebarchiesi@0 3895 * the usual _submit function, and possibly a _validate function.
danielebarchiesi@0 3896 * - 'triggers': An array of the events (that is, hooks) that can trigger this
danielebarchiesi@0 3897 * action. For example: array('node_insert', 'user_update'). You can also
danielebarchiesi@0 3898 * declare support for any trigger by returning array('any') for this value.
danielebarchiesi@0 3899 * - 'behavior': (optional) A machine-readable array of behaviors of this
danielebarchiesi@0 3900 * action, used to signal additionally required actions that may need to be
danielebarchiesi@0 3901 * triggered. Currently recognized behaviors by Trigger module:
danielebarchiesi@0 3902 * - 'changes_property': If an action with this behavior is assigned to a
danielebarchiesi@0 3903 * trigger other than a "presave" hook, any save actions also assigned to
danielebarchiesi@0 3904 * this trigger are moved later in the list. If no save action is present,
danielebarchiesi@0 3905 * one will be added.
danielebarchiesi@0 3906 * Modules that are processing actions (like Trigger module) should take
danielebarchiesi@0 3907 * special care for the "presave" hook, in which case a dependent "save"
danielebarchiesi@0 3908 * action should NOT be invoked.
danielebarchiesi@0 3909 *
danielebarchiesi@0 3910 * @ingroup actions
danielebarchiesi@0 3911 */
danielebarchiesi@0 3912 function hook_action_info() {
danielebarchiesi@0 3913 return array(
danielebarchiesi@0 3914 'comment_unpublish_action' => array(
danielebarchiesi@0 3915 'type' => 'comment',
danielebarchiesi@0 3916 'label' => t('Unpublish comment'),
danielebarchiesi@0 3917 'configurable' => FALSE,
danielebarchiesi@0 3918 'behavior' => array('changes_property'),
danielebarchiesi@0 3919 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
danielebarchiesi@0 3920 ),
danielebarchiesi@0 3921 'comment_unpublish_by_keyword_action' => array(
danielebarchiesi@0 3922 'type' => 'comment',
danielebarchiesi@0 3923 'label' => t('Unpublish comment containing keyword(s)'),
danielebarchiesi@0 3924 'configurable' => TRUE,
danielebarchiesi@0 3925 'behavior' => array('changes_property'),
danielebarchiesi@0 3926 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
danielebarchiesi@0 3927 ),
danielebarchiesi@0 3928 'comment_save_action' => array(
danielebarchiesi@0 3929 'type' => 'comment',
danielebarchiesi@0 3930 'label' => t('Save comment'),
danielebarchiesi@0 3931 'configurable' => FALSE,
danielebarchiesi@0 3932 'triggers' => array('comment_insert', 'comment_update'),
danielebarchiesi@0 3933 ),
danielebarchiesi@0 3934 );
danielebarchiesi@0 3935 }
danielebarchiesi@0 3936
danielebarchiesi@0 3937 /**
danielebarchiesi@0 3938 * Executes code after an action is deleted.
danielebarchiesi@0 3939 *
danielebarchiesi@0 3940 * @param $aid
danielebarchiesi@0 3941 * The action ID.
danielebarchiesi@0 3942 */
danielebarchiesi@0 3943 function hook_actions_delete($aid) {
danielebarchiesi@0 3944 db_delete('actions_assignments')
danielebarchiesi@0 3945 ->condition('aid', $aid)
danielebarchiesi@0 3946 ->execute();
danielebarchiesi@0 3947 }
danielebarchiesi@0 3948
danielebarchiesi@0 3949 /**
danielebarchiesi@0 3950 * Alters the actions declared by another module.
danielebarchiesi@0 3951 *
danielebarchiesi@0 3952 * Called by actions_list() to allow modules to alter the return values from
danielebarchiesi@0 3953 * implementations of hook_action_info().
danielebarchiesi@0 3954 *
danielebarchiesi@0 3955 * @see trigger_example_action_info_alter()
danielebarchiesi@0 3956 */
danielebarchiesi@0 3957 function hook_action_info_alter(&$actions) {
danielebarchiesi@0 3958 $actions['node_unpublish_action']['label'] = t('Unpublish and remove from public view.');
danielebarchiesi@0 3959 }
danielebarchiesi@0 3960
danielebarchiesi@0 3961 /**
danielebarchiesi@0 3962 * Declare archivers to the system.
danielebarchiesi@0 3963 *
danielebarchiesi@0 3964 * An archiver is a class that is able to package and unpackage one or more files
danielebarchiesi@0 3965 * into a single possibly compressed file. Common examples of such files are
danielebarchiesi@0 3966 * zip files and tar.gz files. All archiver classes must implement
danielebarchiesi@0 3967 * ArchiverInterface.
danielebarchiesi@0 3968 *
danielebarchiesi@0 3969 * Each entry should be keyed on a unique value, and specify three
danielebarchiesi@0 3970 * additional keys:
danielebarchiesi@0 3971 * - class: The name of the PHP class for this archiver.
danielebarchiesi@0 3972 * - extensions: An array of file extensions that this archiver supports.
danielebarchiesi@0 3973 * - weight: This optional key specifies the weight of this archiver.
danielebarchiesi@0 3974 * When mapping file extensions to archivers, the first archiver by
danielebarchiesi@0 3975 * weight found that supports the requested extension will be used.
danielebarchiesi@0 3976 *
danielebarchiesi@0 3977 * @see hook_archiver_info_alter()
danielebarchiesi@0 3978 */
danielebarchiesi@0 3979 function hook_archiver_info() {
danielebarchiesi@0 3980 return array(
danielebarchiesi@0 3981 'tar' => array(
danielebarchiesi@0 3982 'class' => 'ArchiverTar',
danielebarchiesi@0 3983 'extensions' => array('tar', 'tar.gz', 'tar.bz2'),
danielebarchiesi@0 3984 ),
danielebarchiesi@0 3985 );
danielebarchiesi@0 3986 }
danielebarchiesi@0 3987
danielebarchiesi@0 3988 /**
danielebarchiesi@0 3989 * Alter archiver information declared by other modules.
danielebarchiesi@0 3990 *
danielebarchiesi@0 3991 * See hook_archiver_info() for a description of archivers and the archiver
danielebarchiesi@0 3992 * information structure.
danielebarchiesi@0 3993 *
danielebarchiesi@0 3994 * @param $info
danielebarchiesi@0 3995 * Archiver information to alter (return values from hook_archiver_info()).
danielebarchiesi@0 3996 */
danielebarchiesi@0 3997 function hook_archiver_info_alter(&$info) {
danielebarchiesi@0 3998 $info['tar']['extensions'][] = 'tgz';
danielebarchiesi@0 3999 }
danielebarchiesi@0 4000
danielebarchiesi@0 4001 /**
danielebarchiesi@0 4002 * Define additional date types.
danielebarchiesi@0 4003 *
danielebarchiesi@0 4004 * Next to the 'long', 'medium' and 'short' date types defined in core, any
danielebarchiesi@0 4005 * module can define additional types that can be used when displaying dates,
danielebarchiesi@0 4006 * by implementing this hook. A date type is basically just a name for a date
danielebarchiesi@0 4007 * format.
danielebarchiesi@0 4008 *
danielebarchiesi@0 4009 * Date types are used in the administration interface: a user can assign
danielebarchiesi@0 4010 * date format types defined in hook_date_formats() to date types defined in
danielebarchiesi@0 4011 * this hook. Once a format has been assigned by a user, the machine name of a
danielebarchiesi@0 4012 * type can be used in the format_date() function to format a date using the
danielebarchiesi@0 4013 * chosen formatting.
danielebarchiesi@0 4014 *
danielebarchiesi@0 4015 * To define a date type in a module and make sure a format has been assigned to
danielebarchiesi@0 4016 * it, without requiring a user to visit the administrative interface, use
danielebarchiesi@0 4017 * @code variable_set('date_format_' . $type, $format); @endcode
danielebarchiesi@0 4018 * where $type is the machine-readable name defined here, and $format is a PHP
danielebarchiesi@0 4019 * date format string.
danielebarchiesi@0 4020 *
danielebarchiesi@0 4021 * To avoid namespace collisions with date types defined by other modules, it is
danielebarchiesi@0 4022 * recommended that each date type starts with the module name. A date type
danielebarchiesi@0 4023 * can consist of letters, numbers and underscores.
danielebarchiesi@0 4024 *
danielebarchiesi@0 4025 * @return
danielebarchiesi@0 4026 * An array of date types where the keys are the machine-readable names and
danielebarchiesi@0 4027 * the values are the human-readable labels.
danielebarchiesi@0 4028 *
danielebarchiesi@0 4029 * @see hook_date_formats()
danielebarchiesi@0 4030 * @see format_date()
danielebarchiesi@0 4031 */
danielebarchiesi@0 4032 function hook_date_format_types() {
danielebarchiesi@0 4033 // Define the core date format types.
danielebarchiesi@0 4034 return array(
danielebarchiesi@0 4035 'long' => t('Long'),
danielebarchiesi@0 4036 'medium' => t('Medium'),
danielebarchiesi@0 4037 'short' => t('Short'),
danielebarchiesi@0 4038 );
danielebarchiesi@0 4039 }
danielebarchiesi@0 4040
danielebarchiesi@0 4041 /**
danielebarchiesi@0 4042 * Modify existing date types.
danielebarchiesi@0 4043 *
danielebarchiesi@0 4044 * Allows other modules to modify existing date types like 'long'. Called by
danielebarchiesi@0 4045 * _system_date_format_types_build(). For instance, A module may use this hook
danielebarchiesi@0 4046 * to apply settings across all date types, such as locking all date types so
danielebarchiesi@0 4047 * they appear to be provided by the system.
danielebarchiesi@0 4048 *
danielebarchiesi@0 4049 * @param $types
danielebarchiesi@0 4050 * A list of date types. Each date type is keyed by the machine-readable name
danielebarchiesi@0 4051 * and the values are associative arrays containing:
danielebarchiesi@0 4052 * - is_new: Set to FALSE to override previous settings.
danielebarchiesi@0 4053 * - module: The name of the module that created the date type.
danielebarchiesi@0 4054 * - type: The machine-readable date type name.
danielebarchiesi@0 4055 * - title: The human-readable date type name.
danielebarchiesi@0 4056 * - locked: Specifies that the date type is system-provided.
danielebarchiesi@0 4057 */
danielebarchiesi@0 4058 function hook_date_format_types_alter(&$types) {
danielebarchiesi@0 4059 foreach ($types as $name => $type) {
danielebarchiesi@0 4060 $types[$name]['locked'] = 1;
danielebarchiesi@0 4061 }
danielebarchiesi@0 4062 }
danielebarchiesi@0 4063
danielebarchiesi@0 4064 /**
danielebarchiesi@0 4065 * Define additional date formats.
danielebarchiesi@0 4066 *
danielebarchiesi@0 4067 * This hook is used to define the PHP date format strings that can be assigned
danielebarchiesi@0 4068 * to date types in the administrative interface. A module can provide date
danielebarchiesi@0 4069 * format strings for the core-provided date types ('long', 'medium', and
danielebarchiesi@0 4070 * 'short'), or for date types defined in hook_date_format_types() by itself
danielebarchiesi@0 4071 * or another module.
danielebarchiesi@0 4072 *
danielebarchiesi@0 4073 * Since date formats can be locale-specific, you can specify the locales that
danielebarchiesi@0 4074 * each date format string applies to. There may be more than one locale for a
danielebarchiesi@0 4075 * format. There may also be more than one format for the same locale. For
danielebarchiesi@0 4076 * example d/m/Y and Y/m/d work equally well in some locales. You may wish to
danielebarchiesi@0 4077 * define some additional date formats that aren't specific to any one locale,
danielebarchiesi@0 4078 * for example, "Y m". For these cases, the 'locales' component of the return
danielebarchiesi@0 4079 * value should be omitted.
danielebarchiesi@0 4080 *
danielebarchiesi@0 4081 * Providing a date format here does not normally assign the format to be
danielebarchiesi@0 4082 * used with the associated date type -- a user has to choose a format for each
danielebarchiesi@0 4083 * date type in the administrative interface. There is one exception: locale
danielebarchiesi@0 4084 * initialization chooses a locale-specific format for the three core-provided
danielebarchiesi@0 4085 * types (see locale_get_localized_date_format() for details). If your module
danielebarchiesi@0 4086 * needs to ensure that a date type it defines has a format associated with it,
danielebarchiesi@0 4087 * call @code variable_set('date_format_' . $type, $format); @endcode
danielebarchiesi@0 4088 * where $type is the machine-readable name defined in hook_date_format_types(),
danielebarchiesi@0 4089 * and $format is a PHP date format string.
danielebarchiesi@0 4090 *
danielebarchiesi@0 4091 * @return
danielebarchiesi@0 4092 * A list of date formats to offer as choices in the administrative
danielebarchiesi@0 4093 * interface. Each date format is a keyed array consisting of three elements:
danielebarchiesi@0 4094 * - 'type': The date type name that this format can be used with, as
danielebarchiesi@0 4095 * declared in an implementation of hook_date_format_types().
danielebarchiesi@0 4096 * - 'format': A PHP date format string to use when formatting dates. It
danielebarchiesi@0 4097 * can contain any of the formatting options described at
danielebarchiesi@0 4098 * http://php.net/manual/en/function.date.php
danielebarchiesi@0 4099 * - 'locales': (optional) An array of 2 and 5 character locale codes,
danielebarchiesi@0 4100 * defining which locales this format applies to (for example, 'en',
danielebarchiesi@0 4101 * 'en-us', etc.). If your date format is not language-specific, leave this
danielebarchiesi@0 4102 * array empty.
danielebarchiesi@0 4103 *
danielebarchiesi@0 4104 * @see hook_date_format_types()
danielebarchiesi@0 4105 */
danielebarchiesi@0 4106 function hook_date_formats() {
danielebarchiesi@0 4107 return array(
danielebarchiesi@0 4108 array(
danielebarchiesi@0 4109 'type' => 'mymodule_extra_long',
danielebarchiesi@0 4110 'format' => 'l jS F Y H:i:s e',
danielebarchiesi@0 4111 'locales' => array('en-ie'),
danielebarchiesi@0 4112 ),
danielebarchiesi@0 4113 array(
danielebarchiesi@0 4114 'type' => 'mymodule_extra_long',
danielebarchiesi@0 4115 'format' => 'l jS F Y h:i:sa',
danielebarchiesi@0 4116 'locales' => array('en', 'en-us'),
danielebarchiesi@0 4117 ),
danielebarchiesi@0 4118 array(
danielebarchiesi@0 4119 'type' => 'short',
danielebarchiesi@0 4120 'format' => 'F Y',
danielebarchiesi@0 4121 'locales' => array(),
danielebarchiesi@0 4122 ),
danielebarchiesi@0 4123 );
danielebarchiesi@0 4124 }
danielebarchiesi@0 4125
danielebarchiesi@0 4126 /**
danielebarchiesi@0 4127 * Alter date formats declared by another module.
danielebarchiesi@0 4128 *
danielebarchiesi@0 4129 * Called by _system_date_format_types_build() to allow modules to alter the
danielebarchiesi@0 4130 * return values from implementations of hook_date_formats().
danielebarchiesi@0 4131 */
danielebarchiesi@0 4132 function hook_date_formats_alter(&$formats) {
danielebarchiesi@0 4133 foreach ($formats as $id => $format) {
danielebarchiesi@0 4134 $formats[$id]['locales'][] = 'en-ca';
danielebarchiesi@0 4135 }
danielebarchiesi@0 4136 }
danielebarchiesi@0 4137
danielebarchiesi@0 4138 /**
danielebarchiesi@0 4139 * Alters the delivery callback used to send the result of the page callback to the browser.
danielebarchiesi@0 4140 *
danielebarchiesi@0 4141 * Called by drupal_deliver_page() to allow modules to alter how the
danielebarchiesi@0 4142 * page is delivered to the browser.
danielebarchiesi@0 4143 *
danielebarchiesi@0 4144 * This hook is intended for altering the delivery callback based on
danielebarchiesi@0 4145 * information unrelated to the path of the page accessed. For example,
danielebarchiesi@0 4146 * it can be used to set the delivery callback based on a HTTP request
danielebarchiesi@0 4147 * header (as shown in the code sample). To specify a delivery callback
danielebarchiesi@0 4148 * based on path information, use hook_menu() or hook_menu_alter().
danielebarchiesi@0 4149 *
danielebarchiesi@0 4150 * This hook can also be used as an API function that can be used to explicitly
danielebarchiesi@0 4151 * set the delivery callback from some other function. For example, for a module
danielebarchiesi@0 4152 * named MODULE:
danielebarchiesi@0 4153 * @code
danielebarchiesi@0 4154 * function MODULE_page_delivery_callback_alter(&$callback, $set = FALSE) {
danielebarchiesi@0 4155 * static $stored_callback;
danielebarchiesi@0 4156 * if ($set) {
danielebarchiesi@0 4157 * $stored_callback = $callback;
danielebarchiesi@0 4158 * }
danielebarchiesi@0 4159 * elseif (isset($stored_callback)) {
danielebarchiesi@0 4160 * $callback = $stored_callback;
danielebarchiesi@0 4161 * }
danielebarchiesi@0 4162 * }
danielebarchiesi@0 4163 * function SOMEWHERE_ELSE() {
danielebarchiesi@0 4164 * $desired_delivery_callback = 'foo';
danielebarchiesi@0 4165 * MODULE_page_delivery_callback_alter($desired_delivery_callback, TRUE);
danielebarchiesi@0 4166 * }
danielebarchiesi@0 4167 * @endcode
danielebarchiesi@0 4168 *
danielebarchiesi@0 4169 * @param $callback
danielebarchiesi@0 4170 * The name of a function.
danielebarchiesi@0 4171 *
danielebarchiesi@0 4172 * @see drupal_deliver_page()
danielebarchiesi@0 4173 */
danielebarchiesi@0 4174 function hook_page_delivery_callback_alter(&$callback) {
danielebarchiesi@0 4175 // jQuery sets a HTTP_X_REQUESTED_WITH header of 'XMLHttpRequest'.
danielebarchiesi@0 4176 // If a page would normally be delivered as an html page, and it is called
danielebarchiesi@0 4177 // from jQuery, deliver it instead as an Ajax response.
danielebarchiesi@0 4178 if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && $callback == 'drupal_deliver_html_page') {
danielebarchiesi@0 4179 $callback = 'ajax_deliver';
danielebarchiesi@0 4180 }
danielebarchiesi@0 4181 }
danielebarchiesi@0 4182
danielebarchiesi@0 4183 /**
danielebarchiesi@0 4184 * Alters theme operation links.
danielebarchiesi@0 4185 *
danielebarchiesi@0 4186 * @param $theme_groups
danielebarchiesi@0 4187 * An associative array containing groups of themes.
danielebarchiesi@0 4188 *
danielebarchiesi@0 4189 * @see system_themes_page()
danielebarchiesi@0 4190 */
danielebarchiesi@0 4191 function hook_system_themes_page_alter(&$theme_groups) {
danielebarchiesi@0 4192 foreach ($theme_groups as $state => &$group) {
danielebarchiesi@0 4193 foreach ($theme_groups[$state] as &$theme) {
danielebarchiesi@0 4194 // Add a foo link to each list of theme operations.
danielebarchiesi@0 4195 $theme->operations[] = array(
danielebarchiesi@0 4196 'title' => t('Foo'),
danielebarchiesi@0 4197 'href' => 'admin/appearance/foo',
danielebarchiesi@0 4198 'query' => array('theme' => $theme->name)
danielebarchiesi@0 4199 );
danielebarchiesi@0 4200 }
danielebarchiesi@0 4201 }
danielebarchiesi@0 4202 }
danielebarchiesi@0 4203
danielebarchiesi@0 4204 /**
danielebarchiesi@0 4205 * Alters inbound URL requests.
danielebarchiesi@0 4206 *
danielebarchiesi@0 4207 * @param $path
danielebarchiesi@0 4208 * The path being constructed, which, if a path alias, has been resolved to a
danielebarchiesi@0 4209 * Drupal path by the database, and which also may have been altered by other
danielebarchiesi@0 4210 * modules before this one.
danielebarchiesi@0 4211 * @param $original_path
danielebarchiesi@0 4212 * The original path, before being checked for path aliases or altered by any
danielebarchiesi@0 4213 * modules.
danielebarchiesi@0 4214 * @param $path_language
danielebarchiesi@0 4215 * The language of the path.
danielebarchiesi@0 4216 *
danielebarchiesi@0 4217 * @see drupal_get_normal_path()
danielebarchiesi@0 4218 */
danielebarchiesi@0 4219 function hook_url_inbound_alter(&$path, $original_path, $path_language) {
danielebarchiesi@0 4220 // Create the path user/me/edit, which allows a user to edit their account.
danielebarchiesi@0 4221 if (preg_match('|^user/me/edit(/.*)?|', $path, $matches)) {
danielebarchiesi@0 4222 global $user;
danielebarchiesi@0 4223 $path = 'user/' . $user->uid . '/edit' . $matches[1];
danielebarchiesi@0 4224 }
danielebarchiesi@0 4225 }
danielebarchiesi@0 4226
danielebarchiesi@0 4227 /**
danielebarchiesi@0 4228 * Alters outbound URLs.
danielebarchiesi@0 4229 *
danielebarchiesi@0 4230 * @param $path
danielebarchiesi@0 4231 * The outbound path to alter, not adjusted for path aliases yet. It won't be
danielebarchiesi@0 4232 * adjusted for path aliases until all modules are finished altering it, thus
danielebarchiesi@0 4233 * being consistent with hook_url_inbound_alter(), which adjusts for all path
danielebarchiesi@0 4234 * aliases before allowing modules to alter it. This may have been altered by
danielebarchiesi@0 4235 * other modules before this one.
danielebarchiesi@0 4236 * @param $options
danielebarchiesi@0 4237 * A set of URL options for the URL so elements such as a fragment or a query
danielebarchiesi@0 4238 * string can be added to the URL.
danielebarchiesi@0 4239 * @param $original_path
danielebarchiesi@0 4240 * The original path, before being altered by any modules.
danielebarchiesi@0 4241 *
danielebarchiesi@0 4242 * @see url()
danielebarchiesi@0 4243 */
danielebarchiesi@0 4244 function hook_url_outbound_alter(&$path, &$options, $original_path) {
danielebarchiesi@0 4245 // Use an external RSS feed rather than the Drupal one.
danielebarchiesi@0 4246 if ($path == 'rss.xml') {
danielebarchiesi@0 4247 $path = 'http://example.com/rss.xml';
danielebarchiesi@0 4248 $options['external'] = TRUE;
danielebarchiesi@0 4249 }
danielebarchiesi@0 4250
danielebarchiesi@0 4251 // Instead of pointing to user/[uid]/edit, point to user/me/edit.
danielebarchiesi@0 4252 if (preg_match('|^user/([0-9]*)/edit(/.*)?|', $path, $matches)) {
danielebarchiesi@0 4253 global $user;
danielebarchiesi@0 4254 if ($user->uid == $matches[1]) {
danielebarchiesi@0 4255 $path = 'user/me/edit' . $matches[2];
danielebarchiesi@0 4256 }
danielebarchiesi@0 4257 }
danielebarchiesi@0 4258 }
danielebarchiesi@0 4259
danielebarchiesi@0 4260 /**
danielebarchiesi@0 4261 * Alter the username that is displayed for a user.
danielebarchiesi@0 4262 *
danielebarchiesi@0 4263 * Called by format_username() to allow modules to alter the username that's
danielebarchiesi@0 4264 * displayed. Can be used to ensure user privacy in situations where
danielebarchiesi@0 4265 * $account->name is too revealing.
danielebarchiesi@0 4266 *
danielebarchiesi@0 4267 * @param $name
danielebarchiesi@0 4268 * The string that format_username() will return.
danielebarchiesi@0 4269 *
danielebarchiesi@0 4270 * @param $account
danielebarchiesi@0 4271 * The account object passed to format_username().
danielebarchiesi@0 4272 *
danielebarchiesi@0 4273 * @see format_username()
danielebarchiesi@0 4274 */
danielebarchiesi@0 4275 function hook_username_alter(&$name, $account) {
danielebarchiesi@0 4276 // Display the user's uid instead of name.
danielebarchiesi@0 4277 if (isset($account->uid)) {
danielebarchiesi@0 4278 $name = t('User !uid', array('!uid' => $account->uid));
danielebarchiesi@0 4279 }
danielebarchiesi@0 4280 }
danielebarchiesi@0 4281
danielebarchiesi@0 4282 /**
danielebarchiesi@0 4283 * Provide replacement values for placeholder tokens.
danielebarchiesi@0 4284 *
danielebarchiesi@0 4285 * This hook is invoked when someone calls token_replace(). That function first
danielebarchiesi@0 4286 * scans the text for [type:token] patterns, and splits the needed tokens into
danielebarchiesi@0 4287 * groups by type. Then hook_tokens() is invoked on each token-type group,
danielebarchiesi@0 4288 * allowing your module to respond by providing replacement text for any of
danielebarchiesi@0 4289 * the tokens in the group that your module knows how to process.
danielebarchiesi@0 4290 *
danielebarchiesi@0 4291 * A module implementing this hook should also implement hook_token_info() in
danielebarchiesi@0 4292 * order to list its available tokens on editing screens.
danielebarchiesi@0 4293 *
danielebarchiesi@0 4294 * @param $type
danielebarchiesi@0 4295 * The machine-readable name of the type (group) of token being replaced, such
danielebarchiesi@0 4296 * as 'node', 'user', or another type defined by a hook_token_info()
danielebarchiesi@0 4297 * implementation.
danielebarchiesi@0 4298 * @param $tokens
danielebarchiesi@0 4299 * An array of tokens to be replaced. The keys are the machine-readable token
danielebarchiesi@0 4300 * names, and the values are the raw [type:token] strings that appeared in the
danielebarchiesi@0 4301 * original text.
danielebarchiesi@0 4302 * @param $data
danielebarchiesi@0 4303 * (optional) An associative array of data objects to be used when generating
danielebarchiesi@0 4304 * replacement values, as supplied in the $data parameter to token_replace().
danielebarchiesi@0 4305 * @param $options
danielebarchiesi@0 4306 * (optional) An associative array of options for token replacement; see
danielebarchiesi@0 4307 * token_replace() for possible values.
danielebarchiesi@0 4308 *
danielebarchiesi@0 4309 * @return
danielebarchiesi@0 4310 * An associative array of replacement values, keyed by the raw [type:token]
danielebarchiesi@0 4311 * strings from the original text.
danielebarchiesi@0 4312 *
danielebarchiesi@0 4313 * @see hook_token_info()
danielebarchiesi@0 4314 * @see hook_tokens_alter()
danielebarchiesi@0 4315 */
danielebarchiesi@0 4316 function hook_tokens($type, $tokens, array $data = array(), array $options = array()) {
danielebarchiesi@0 4317 $url_options = array('absolute' => TRUE);
danielebarchiesi@0 4318 if (isset($options['language'])) {
danielebarchiesi@0 4319 $url_options['language'] = $options['language'];
danielebarchiesi@0 4320 $language_code = $options['language']->language;
danielebarchiesi@0 4321 }
danielebarchiesi@0 4322 else {
danielebarchiesi@0 4323 $language_code = NULL;
danielebarchiesi@0 4324 }
danielebarchiesi@0 4325 $sanitize = !empty($options['sanitize']);
danielebarchiesi@0 4326
danielebarchiesi@0 4327 $replacements = array();
danielebarchiesi@0 4328
danielebarchiesi@0 4329 if ($type == 'node' && !empty($data['node'])) {
danielebarchiesi@0 4330 $node = $data['node'];
danielebarchiesi@0 4331
danielebarchiesi@0 4332 foreach ($tokens as $name => $original) {
danielebarchiesi@0 4333 switch ($name) {
danielebarchiesi@0 4334 // Simple key values on the node.
danielebarchiesi@0 4335 case 'nid':
danielebarchiesi@0 4336 $replacements[$original] = $node->nid;
danielebarchiesi@0 4337 break;
danielebarchiesi@0 4338
danielebarchiesi@0 4339 case 'title':
danielebarchiesi@0 4340 $replacements[$original] = $sanitize ? check_plain($node->title) : $node->title;
danielebarchiesi@0 4341 break;
danielebarchiesi@0 4342
danielebarchiesi@0 4343 case 'edit-url':
danielebarchiesi@0 4344 $replacements[$original] = url('node/' . $node->nid . '/edit', $url_options);
danielebarchiesi@0 4345 break;
danielebarchiesi@0 4346
danielebarchiesi@0 4347 // Default values for the chained tokens handled below.
danielebarchiesi@0 4348 case 'author':
danielebarchiesi@0 4349 $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name;
danielebarchiesi@0 4350 $replacements[$original] = $sanitize ? filter_xss($name) : $name;
danielebarchiesi@0 4351 break;
danielebarchiesi@0 4352
danielebarchiesi@0 4353 case 'created':
danielebarchiesi@0 4354 $replacements[$original] = format_date($node->created, 'medium', '', NULL, $language_code);
danielebarchiesi@0 4355 break;
danielebarchiesi@0 4356 }
danielebarchiesi@0 4357 }
danielebarchiesi@0 4358
danielebarchiesi@0 4359 if ($author_tokens = token_find_with_prefix($tokens, 'author')) {
danielebarchiesi@0 4360 $author = user_load($node->uid);
danielebarchiesi@0 4361 $replacements += token_generate('user', $author_tokens, array('user' => $author), $options);
danielebarchiesi@0 4362 }
danielebarchiesi@0 4363
danielebarchiesi@0 4364 if ($created_tokens = token_find_with_prefix($tokens, 'created')) {
danielebarchiesi@0 4365 $replacements += token_generate('date', $created_tokens, array('date' => $node->created), $options);
danielebarchiesi@0 4366 }
danielebarchiesi@0 4367 }
danielebarchiesi@0 4368
danielebarchiesi@0 4369 return $replacements;
danielebarchiesi@0 4370 }
danielebarchiesi@0 4371
danielebarchiesi@0 4372 /**
danielebarchiesi@0 4373 * Alter replacement values for placeholder tokens.
danielebarchiesi@0 4374 *
danielebarchiesi@0 4375 * @param $replacements
danielebarchiesi@0 4376 * An associative array of replacements returned by hook_tokens().
danielebarchiesi@0 4377 * @param $context
danielebarchiesi@0 4378 * The context in which hook_tokens() was called. An associative array with
danielebarchiesi@0 4379 * the following keys, which have the same meaning as the corresponding
danielebarchiesi@0 4380 * parameters of hook_tokens():
danielebarchiesi@0 4381 * - 'type'
danielebarchiesi@0 4382 * - 'tokens'
danielebarchiesi@0 4383 * - 'data'
danielebarchiesi@0 4384 * - 'options'
danielebarchiesi@0 4385 *
danielebarchiesi@0 4386 * @see hook_tokens()
danielebarchiesi@0 4387 */
danielebarchiesi@0 4388 function hook_tokens_alter(array &$replacements, array $context) {
danielebarchiesi@0 4389 $options = $context['options'];
danielebarchiesi@0 4390
danielebarchiesi@0 4391 if (isset($options['language'])) {
danielebarchiesi@0 4392 $url_options['language'] = $options['language'];
danielebarchiesi@0 4393 $language_code = $options['language']->language;
danielebarchiesi@0 4394 }
danielebarchiesi@0 4395 else {
danielebarchiesi@0 4396 $language_code = NULL;
danielebarchiesi@0 4397 }
danielebarchiesi@0 4398 $sanitize = !empty($options['sanitize']);
danielebarchiesi@0 4399
danielebarchiesi@0 4400 if ($context['type'] == 'node' && !empty($context['data']['node'])) {
danielebarchiesi@0 4401 $node = $context['data']['node'];
danielebarchiesi@0 4402
danielebarchiesi@0 4403 // Alter the [node:title] token, and replace it with the rendered content
danielebarchiesi@0 4404 // of a field (field_title).
danielebarchiesi@0 4405 if (isset($context['tokens']['title'])) {
danielebarchiesi@0 4406 $title = field_view_field('node', $node, 'field_title', 'default', $language_code);
danielebarchiesi@0 4407 $replacements[$context['tokens']['title']] = drupal_render($title);
danielebarchiesi@0 4408 }
danielebarchiesi@0 4409 }
danielebarchiesi@0 4410 }
danielebarchiesi@0 4411
danielebarchiesi@0 4412 /**
danielebarchiesi@0 4413 * Provide information about available placeholder tokens and token types.
danielebarchiesi@0 4414 *
danielebarchiesi@0 4415 * Tokens are placeholders that can be put into text by using the syntax
danielebarchiesi@0 4416 * [type:token], where type is the machine-readable name of a token type, and
danielebarchiesi@0 4417 * token is the machine-readable name of a token within this group. This hook
danielebarchiesi@0 4418 * provides a list of types and tokens to be displayed on text editing screens,
danielebarchiesi@0 4419 * so that people editing text can see what their token options are.
danielebarchiesi@0 4420 *
danielebarchiesi@0 4421 * The actual token replacement is done by token_replace(), which invokes
danielebarchiesi@0 4422 * hook_tokens(). Your module will need to implement that hook in order to
danielebarchiesi@0 4423 * generate token replacements from the tokens defined here.
danielebarchiesi@0 4424 *
danielebarchiesi@0 4425 * @return
danielebarchiesi@0 4426 * An associative array of available tokens and token types. The outer array
danielebarchiesi@0 4427 * has two components:
danielebarchiesi@0 4428 * - types: An associative array of token types (groups). Each token type is
danielebarchiesi@0 4429 * an associative array with the following components:
danielebarchiesi@0 4430 * - name: The translated human-readable short name of the token type.
danielebarchiesi@0 4431 * - description: A translated longer description of the token type.
danielebarchiesi@0 4432 * - needs-data: The type of data that must be provided to token_replace()
danielebarchiesi@0 4433 * in the $data argument (i.e., the key name in $data) in order for tokens
danielebarchiesi@0 4434 * of this type to be used in the $text being processed. For instance, if
danielebarchiesi@0 4435 * the token needs a node object, 'needs-data' should be 'node', and to
danielebarchiesi@0 4436 * use this token in token_replace(), the caller needs to supply a node
danielebarchiesi@0 4437 * object as $data['node']. Some token data can also be supplied
danielebarchiesi@0 4438 * indirectly; for instance, a node object in $data supplies a user object
danielebarchiesi@0 4439 * (the author of the node), allowing user tokens to be used when only
danielebarchiesi@0 4440 * a node data object is supplied.
danielebarchiesi@0 4441 * - tokens: An associative array of tokens. The outer array is keyed by the
danielebarchiesi@0 4442 * group name (the same key as in the types array). Within each group of
danielebarchiesi@0 4443 * tokens, each token item is keyed by the machine name of the token, and
danielebarchiesi@0 4444 * each token item has the following components:
danielebarchiesi@0 4445 * - name: The translated human-readable short name of the token.
danielebarchiesi@0 4446 * - description: A translated longer description of the token.
danielebarchiesi@0 4447 * - type (optional): A 'needs-data' data type supplied by this token, which
danielebarchiesi@0 4448 * should match a 'needs-data' value from another token type. For example,
danielebarchiesi@0 4449 * the node author token provides a user object, which can then be used
danielebarchiesi@0 4450 * for token replacement data in token_replace() without having to supply
danielebarchiesi@0 4451 * a separate user object.
danielebarchiesi@0 4452 *
danielebarchiesi@0 4453 * @see hook_token_info_alter()
danielebarchiesi@0 4454 * @see hook_tokens()
danielebarchiesi@0 4455 */
danielebarchiesi@0 4456 function hook_token_info() {
danielebarchiesi@0 4457 $type = array(
danielebarchiesi@0 4458 'name' => t('Nodes'),
danielebarchiesi@0 4459 'description' => t('Tokens related to individual nodes.'),
danielebarchiesi@0 4460 'needs-data' => 'node',
danielebarchiesi@0 4461 );
danielebarchiesi@0 4462
danielebarchiesi@0 4463 // Core tokens for nodes.
danielebarchiesi@0 4464 $node['nid'] = array(
danielebarchiesi@0 4465 'name' => t("Node ID"),
danielebarchiesi@0 4466 'description' => t("The unique ID of the node."),
danielebarchiesi@0 4467 );
danielebarchiesi@0 4468 $node['title'] = array(
danielebarchiesi@0 4469 'name' => t("Title"),
danielebarchiesi@0 4470 'description' => t("The title of the node."),
danielebarchiesi@0 4471 );
danielebarchiesi@0 4472 $node['edit-url'] = array(
danielebarchiesi@0 4473 'name' => t("Edit URL"),
danielebarchiesi@0 4474 'description' => t("The URL of the node's edit page."),
danielebarchiesi@0 4475 );
danielebarchiesi@0 4476
danielebarchiesi@0 4477 // Chained tokens for nodes.
danielebarchiesi@0 4478 $node['created'] = array(
danielebarchiesi@0 4479 'name' => t("Date created"),
danielebarchiesi@0 4480 'description' => t("The date the node was posted."),
danielebarchiesi@0 4481 'type' => 'date',
danielebarchiesi@0 4482 );
danielebarchiesi@0 4483 $node['author'] = array(
danielebarchiesi@0 4484 'name' => t("Author"),
danielebarchiesi@0 4485 'description' => t("The author of the node."),
danielebarchiesi@0 4486 'type' => 'user',
danielebarchiesi@0 4487 );
danielebarchiesi@0 4488
danielebarchiesi@0 4489 return array(
danielebarchiesi@0 4490 'types' => array('node' => $type),
danielebarchiesi@0 4491 'tokens' => array('node' => $node),
danielebarchiesi@0 4492 );
danielebarchiesi@0 4493 }
danielebarchiesi@0 4494
danielebarchiesi@0 4495 /**
danielebarchiesi@0 4496 * Alter the metadata about available placeholder tokens and token types.
danielebarchiesi@0 4497 *
danielebarchiesi@0 4498 * @param $data
danielebarchiesi@0 4499 * The associative array of token definitions from hook_token_info().
danielebarchiesi@0 4500 *
danielebarchiesi@0 4501 * @see hook_token_info()
danielebarchiesi@0 4502 */
danielebarchiesi@0 4503 function hook_token_info_alter(&$data) {
danielebarchiesi@0 4504 // Modify description of node tokens for our site.
danielebarchiesi@0 4505 $data['tokens']['node']['nid'] = array(
danielebarchiesi@0 4506 'name' => t("Node ID"),
danielebarchiesi@0 4507 'description' => t("The unique ID of the article."),
danielebarchiesi@0 4508 );
danielebarchiesi@0 4509 $data['tokens']['node']['title'] = array(
danielebarchiesi@0 4510 'name' => t("Title"),
danielebarchiesi@0 4511 'description' => t("The title of the article."),
danielebarchiesi@0 4512 );
danielebarchiesi@0 4513
danielebarchiesi@0 4514 // Chained tokens for nodes.
danielebarchiesi@0 4515 $data['tokens']['node']['created'] = array(
danielebarchiesi@0 4516 'name' => t("Date created"),
danielebarchiesi@0 4517 'description' => t("The date the article was posted."),
danielebarchiesi@0 4518 'type' => 'date',
danielebarchiesi@0 4519 );
danielebarchiesi@0 4520 }
danielebarchiesi@0 4521
danielebarchiesi@0 4522 /**
danielebarchiesi@0 4523 * Alter batch information before a batch is processed.
danielebarchiesi@0 4524 *
danielebarchiesi@0 4525 * Called by batch_process() to allow modules to alter a batch before it is
danielebarchiesi@0 4526 * processed.
danielebarchiesi@0 4527 *
danielebarchiesi@0 4528 * @param $batch
danielebarchiesi@0 4529 * The associative array of batch information. See batch_set() for details on
danielebarchiesi@0 4530 * what this could contain.
danielebarchiesi@0 4531 *
danielebarchiesi@0 4532 * @see batch_set()
danielebarchiesi@0 4533 * @see batch_process()
danielebarchiesi@0 4534 *
danielebarchiesi@0 4535 * @ingroup batch
danielebarchiesi@0 4536 */
danielebarchiesi@0 4537 function hook_batch_alter(&$batch) {
danielebarchiesi@0 4538 // If the current page request is inside the overlay, add ?render=overlay to
danielebarchiesi@0 4539 // the success callback URL, so that it appears correctly within the overlay.
danielebarchiesi@0 4540 if (overlay_get_mode() == 'child') {
danielebarchiesi@0 4541 if (isset($batch['url_options']['query'])) {
danielebarchiesi@0 4542 $batch['url_options']['query']['render'] = 'overlay';
danielebarchiesi@0 4543 }
danielebarchiesi@0 4544 else {
danielebarchiesi@0 4545 $batch['url_options']['query'] = array('render' => 'overlay');
danielebarchiesi@0 4546 }
danielebarchiesi@0 4547 }
danielebarchiesi@0 4548 }
danielebarchiesi@0 4549
danielebarchiesi@0 4550 /**
danielebarchiesi@0 4551 * Provide information on Updaters (classes that can update Drupal).
danielebarchiesi@0 4552 *
danielebarchiesi@0 4553 * An Updater is a class that knows how to update various parts of the Drupal
danielebarchiesi@0 4554 * file system, for example to update modules that have newer releases, or to
danielebarchiesi@0 4555 * install a new theme.
danielebarchiesi@0 4556 *
danielebarchiesi@0 4557 * @return
danielebarchiesi@0 4558 * An associative array of information about the updater(s) being provided.
danielebarchiesi@0 4559 * This array is keyed by a unique identifier for each updater, and the
danielebarchiesi@0 4560 * values are subarrays that can contain the following keys:
danielebarchiesi@0 4561 * - class: The name of the PHP class which implements this updater.
danielebarchiesi@0 4562 * - name: Human-readable name of this updater.
danielebarchiesi@0 4563 * - weight: Controls what order the Updater classes are consulted to decide
danielebarchiesi@0 4564 * which one should handle a given task. When an update task is being run,
danielebarchiesi@0 4565 * the system will loop through all the Updater classes defined in this
danielebarchiesi@0 4566 * registry in weight order and let each class respond to the task and
danielebarchiesi@0 4567 * decide if each Updater wants to handle the task. In general, this
danielebarchiesi@0 4568 * doesn't matter, but if you need to override an existing Updater, make
danielebarchiesi@0 4569 * sure your Updater has a lighter weight so that it comes first.
danielebarchiesi@0 4570 *
danielebarchiesi@0 4571 * @see drupal_get_updaters()
danielebarchiesi@0 4572 * @see hook_updater_info_alter()
danielebarchiesi@0 4573 */
danielebarchiesi@0 4574 function hook_updater_info() {
danielebarchiesi@0 4575 return array(
danielebarchiesi@0 4576 'module' => array(
danielebarchiesi@0 4577 'class' => 'ModuleUpdater',
danielebarchiesi@0 4578 'name' => t('Update modules'),
danielebarchiesi@0 4579 'weight' => 0,
danielebarchiesi@0 4580 ),
danielebarchiesi@0 4581 'theme' => array(
danielebarchiesi@0 4582 'class' => 'ThemeUpdater',
danielebarchiesi@0 4583 'name' => t('Update themes'),
danielebarchiesi@0 4584 'weight' => 0,
danielebarchiesi@0 4585 ),
danielebarchiesi@0 4586 );
danielebarchiesi@0 4587 }
danielebarchiesi@0 4588
danielebarchiesi@0 4589 /**
danielebarchiesi@0 4590 * Alter the Updater information array.
danielebarchiesi@0 4591 *
danielebarchiesi@0 4592 * An Updater is a class that knows how to update various parts of the Drupal
danielebarchiesi@0 4593 * file system, for example to update modules that have newer releases, or to
danielebarchiesi@0 4594 * install a new theme.
danielebarchiesi@0 4595 *
danielebarchiesi@0 4596 * @param array $updaters
danielebarchiesi@0 4597 * Associative array of updaters as defined through hook_updater_info().
danielebarchiesi@0 4598 * Alter this array directly.
danielebarchiesi@0 4599 *
danielebarchiesi@0 4600 * @see drupal_get_updaters()
danielebarchiesi@0 4601 * @see hook_updater_info()
danielebarchiesi@0 4602 */
danielebarchiesi@0 4603 function hook_updater_info_alter(&$updaters) {
danielebarchiesi@0 4604 // Adjust weight so that the theme Updater gets a chance to handle a given
danielebarchiesi@0 4605 // update task before module updaters.
danielebarchiesi@0 4606 $updaters['theme']['weight'] = -1;
danielebarchiesi@0 4607 }
danielebarchiesi@0 4608
danielebarchiesi@0 4609 /**
danielebarchiesi@0 4610 * Alter the default country list.
danielebarchiesi@0 4611 *
danielebarchiesi@0 4612 * @param $countries
danielebarchiesi@0 4613 * The associative array of countries keyed by ISO 3166-1 country code.
danielebarchiesi@0 4614 *
danielebarchiesi@0 4615 * @see country_get_list()
danielebarchiesi@0 4616 * @see _country_get_predefined_list()
danielebarchiesi@0 4617 */
danielebarchiesi@0 4618 function hook_countries_alter(&$countries) {
danielebarchiesi@0 4619 // Elbonia is now independent, so add it to the country list.
danielebarchiesi@0 4620 $countries['EB'] = 'Elbonia';
danielebarchiesi@0 4621 }
danielebarchiesi@0 4622
danielebarchiesi@0 4623 /**
danielebarchiesi@0 4624 * Control site status before menu dispatching.
danielebarchiesi@0 4625 *
danielebarchiesi@0 4626 * The hook is called after checking whether the site is offline but before
danielebarchiesi@0 4627 * the current router item is retrieved and executed by
danielebarchiesi@0 4628 * menu_execute_active_handler(). If the site is in offline mode,
danielebarchiesi@0 4629 * $menu_site_status is set to MENU_SITE_OFFLINE.
danielebarchiesi@0 4630 *
danielebarchiesi@0 4631 * @param $menu_site_status
danielebarchiesi@0 4632 * Supported values are MENU_SITE_OFFLINE, MENU_ACCESS_DENIED,
danielebarchiesi@0 4633 * MENU_NOT_FOUND and MENU_SITE_ONLINE. Any other value than
danielebarchiesi@0 4634 * MENU_SITE_ONLINE will skip the default menu handling system and be passed
danielebarchiesi@0 4635 * for delivery to drupal_deliver_page() with a NULL
danielebarchiesi@0 4636 * $default_delivery_callback.
danielebarchiesi@0 4637 * @param $path
danielebarchiesi@0 4638 * Contains the system path that is going to be loaded. This is read only,
danielebarchiesi@0 4639 * use hook_url_inbound_alter() to change the path.
danielebarchiesi@0 4640 */
danielebarchiesi@0 4641 function hook_menu_site_status_alter(&$menu_site_status, $path) {
danielebarchiesi@0 4642 // Allow access to my_module/authentication even if site is in offline mode.
danielebarchiesi@0 4643 if ($menu_site_status == MENU_SITE_OFFLINE && user_is_anonymous() && $path == 'my_module/authentication') {
danielebarchiesi@0 4644 $menu_site_status = MENU_SITE_ONLINE;
danielebarchiesi@0 4645 }
danielebarchiesi@0 4646 }
danielebarchiesi@0 4647
danielebarchiesi@0 4648 /**
danielebarchiesi@0 4649 * Register information about FileTransfer classes provided by a module.
danielebarchiesi@0 4650 *
danielebarchiesi@0 4651 * The FileTransfer class allows transferring files over a specific type of
danielebarchiesi@0 4652 * connection. Core provides classes for FTP and SSH. Contributed modules are
danielebarchiesi@0 4653 * free to extend the FileTransfer base class to add other connection types,
danielebarchiesi@0 4654 * and if these classes are registered via hook_filetransfer_info(), those
danielebarchiesi@0 4655 * connection types will be available to site administrators using the Update
danielebarchiesi@0 4656 * manager when they are redirected to the authorize.php script to authorize
danielebarchiesi@0 4657 * the file operations.
danielebarchiesi@0 4658 *
danielebarchiesi@0 4659 * @return array
danielebarchiesi@0 4660 * Nested array of information about FileTransfer classes. Each key is a
danielebarchiesi@0 4661 * FileTransfer type (not human readable, used for form elements and
danielebarchiesi@0 4662 * variable names, etc), and the values are subarrays that define properties
danielebarchiesi@0 4663 * of that type. The keys in each subarray are:
danielebarchiesi@0 4664 * - 'title': Required. The human-readable name of the connection type.
danielebarchiesi@0 4665 * - 'class': Required. The name of the FileTransfer class. The constructor
danielebarchiesi@0 4666 * will always be passed the full path to the root of the site that should
danielebarchiesi@0 4667 * be used to restrict where file transfer operations can occur (the $jail)
danielebarchiesi@0 4668 * and an array of settings values returned by the settings form.
danielebarchiesi@0 4669 * - 'file': Required. The include file containing the FileTransfer class.
danielebarchiesi@0 4670 * This should be a separate .inc file, not just the .module file, so that
danielebarchiesi@0 4671 * the minimum possible code is loaded when authorize.php is running.
danielebarchiesi@0 4672 * - 'file path': Optional. The directory (relative to the Drupal root)
danielebarchiesi@0 4673 * where the include file lives. If not defined, defaults to the base
danielebarchiesi@0 4674 * directory of the module implementing the hook.
danielebarchiesi@0 4675 * - 'weight': Optional. Integer weight used for sorting connection types on
danielebarchiesi@0 4676 * the authorize.php form.
danielebarchiesi@0 4677 *
danielebarchiesi@0 4678 * @see FileTransfer
danielebarchiesi@0 4679 * @see authorize.php
danielebarchiesi@0 4680 * @see hook_filetransfer_info_alter()
danielebarchiesi@0 4681 * @see drupal_get_filetransfer_info()
danielebarchiesi@0 4682 */
danielebarchiesi@0 4683 function hook_filetransfer_info() {
danielebarchiesi@0 4684 $info['sftp'] = array(
danielebarchiesi@0 4685 'title' => t('SFTP (Secure FTP)'),
danielebarchiesi@0 4686 'file' => 'sftp.filetransfer.inc',
danielebarchiesi@0 4687 'class' => 'FileTransferSFTP',
danielebarchiesi@0 4688 'weight' => 10,
danielebarchiesi@0 4689 );
danielebarchiesi@0 4690 return $info;
danielebarchiesi@0 4691 }
danielebarchiesi@0 4692
danielebarchiesi@0 4693 /**
danielebarchiesi@0 4694 * Alter the FileTransfer class registry.
danielebarchiesi@0 4695 *
danielebarchiesi@0 4696 * @param array $filetransfer_info
danielebarchiesi@0 4697 * Reference to a nested array containing information about the FileTransfer
danielebarchiesi@0 4698 * class registry.
danielebarchiesi@0 4699 *
danielebarchiesi@0 4700 * @see hook_filetransfer_info()
danielebarchiesi@0 4701 */
danielebarchiesi@0 4702 function hook_filetransfer_info_alter(&$filetransfer_info) {
danielebarchiesi@0 4703 if (variable_get('paranoia', FALSE)) {
danielebarchiesi@0 4704 // Remove the FTP option entirely.
danielebarchiesi@0 4705 unset($filetransfer_info['ftp']);
danielebarchiesi@0 4706 // Make sure the SSH option is listed first.
danielebarchiesi@0 4707 $filetransfer_info['ssh']['weight'] = -10;
danielebarchiesi@0 4708 }
danielebarchiesi@0 4709 }
danielebarchiesi@0 4710
danielebarchiesi@0 4711 /**
danielebarchiesi@0 4712 * @} End of "addtogroup hooks".
danielebarchiesi@0 4713 */
danielebarchiesi@0 4714
danielebarchiesi@0 4715 /**
danielebarchiesi@0 4716 * @addtogroup callbacks
danielebarchiesi@0 4717 * @{
danielebarchiesi@0 4718 */
danielebarchiesi@0 4719
danielebarchiesi@0 4720 /**
danielebarchiesi@0 4721 * Return the URI for an entity.
danielebarchiesi@0 4722 *
danielebarchiesi@0 4723 * Callback for hook_entity_info().
danielebarchiesi@0 4724 *
danielebarchiesi@0 4725 * @param $entity
danielebarchiesi@0 4726 * The entity to return the URI for.
danielebarchiesi@0 4727 *
danielebarchiesi@0 4728 * @return
danielebarchiesi@0 4729 * An associative array with the following elements:
danielebarchiesi@0 4730 * - 'path': The URL path for the entity.
danielebarchiesi@0 4731 * - 'options': (optional) An array of options for the url() function.
danielebarchiesi@0 4732 * The actual entity URI can be constructed by passing these elements to
danielebarchiesi@0 4733 * url().
danielebarchiesi@0 4734 */
danielebarchiesi@0 4735 function callback_entity_info_uri($entity) {
danielebarchiesi@0 4736 return array(
danielebarchiesi@0 4737 'path' => 'node/' . $entity->nid,
danielebarchiesi@0 4738 );
danielebarchiesi@0 4739 }
danielebarchiesi@0 4740
danielebarchiesi@0 4741 /**
danielebarchiesi@0 4742 * Return the label of an entity.
danielebarchiesi@0 4743 *
danielebarchiesi@0 4744 * Callback for hook_entity_info().
danielebarchiesi@0 4745 *
danielebarchiesi@0 4746 * @param $entity
danielebarchiesi@0 4747 * The entity for which to generate the label.
danielebarchiesi@0 4748 * @param $entity_type
danielebarchiesi@0 4749 * The entity type; e.g., 'node' or 'user'.
danielebarchiesi@0 4750 *
danielebarchiesi@0 4751 * @return
danielebarchiesi@0 4752 * An unsanitized string with the label of the entity.
danielebarchiesi@0 4753 *
danielebarchiesi@0 4754 * @see entity_label()
danielebarchiesi@0 4755 */
danielebarchiesi@0 4756 function callback_entity_info_label($entity, $entity_type) {
danielebarchiesi@0 4757 return empty($entity->title) ? 'Untitled entity' : $entity->title;
danielebarchiesi@0 4758 }
danielebarchiesi@0 4759
danielebarchiesi@0 4760 /**
danielebarchiesi@0 4761 * Return the language code of the entity.
danielebarchiesi@0 4762 *
danielebarchiesi@0 4763 * Callback for hook_entity_info().
danielebarchiesi@0 4764 *
danielebarchiesi@0 4765 * The language callback is meant to be used primarily for temporary alterations
danielebarchiesi@0 4766 * of the property value.
danielebarchiesi@0 4767 *
danielebarchiesi@0 4768 * @param $entity
danielebarchiesi@0 4769 * The entity for which to return the language.
danielebarchiesi@0 4770 * @param $entity_type
danielebarchiesi@0 4771 * The entity type; e.g., 'node' or 'user'.
danielebarchiesi@0 4772 *
danielebarchiesi@0 4773 * @return
danielebarchiesi@0 4774 * The language code for the language of the entity.
danielebarchiesi@0 4775 *
danielebarchiesi@0 4776 * @see entity_language()
danielebarchiesi@0 4777 */
danielebarchiesi@0 4778 function callback_entity_info_language($entity, $entity_type) {
danielebarchiesi@0 4779 return $entity->language;
danielebarchiesi@0 4780 }
danielebarchiesi@0 4781
danielebarchiesi@0 4782 /**
danielebarchiesi@0 4783 * @} End of "addtogroup callbacks".
danielebarchiesi@0 4784 */
danielebarchiesi@0 4785
danielebarchiesi@0 4786 /**
danielebarchiesi@0 4787 * @defgroup update_api Update versions of API functions
danielebarchiesi@0 4788 * @{
danielebarchiesi@0 4789 * Functions that are similar to normal API functions, but do not invoke hooks.
danielebarchiesi@0 4790 *
danielebarchiesi@0 4791 * These simplified versions of core API functions are provided for use by
danielebarchiesi@0 4792 * update functions (hook_update_N() implementations).
danielebarchiesi@0 4793 *
danielebarchiesi@0 4794 * During database updates the schema of any module could be out of date. For
danielebarchiesi@0 4795 * this reason, caution is needed when using any API function within an update
danielebarchiesi@0 4796 * function - particularly CRUD functions, functions that depend on the schema
danielebarchiesi@0 4797 * (for example by using drupal_write_record()), and any functions that invoke
danielebarchiesi@0 4798 * hooks.
danielebarchiesi@0 4799 *
danielebarchiesi@0 4800 * Instead, a simplified utility function should be used. If a utility version
danielebarchiesi@0 4801 * of the API function you require does not already exist, then you should
danielebarchiesi@0 4802 * create a new function. The new utility function should be named
danielebarchiesi@0 4803 * _update_N_mymodule_my_function(). N is the schema version the function acts
danielebarchiesi@0 4804 * on (the schema version is the number N from the hook_update_N()
danielebarchiesi@0 4805 * implementation where this schema was introduced, or a number following the
danielebarchiesi@0 4806 * same numbering scheme), and mymodule_my_function is the name of the original
danielebarchiesi@0 4807 * API function including the module's name.
danielebarchiesi@0 4808 *
danielebarchiesi@0 4809 * Examples:
danielebarchiesi@0 4810 * - _update_6000_mymodule_save(): This function performs a save operation
danielebarchiesi@0 4811 * without invoking any hooks using the 6.x schema.
danielebarchiesi@0 4812 * - _update_7000_mymodule_save(): This function performs the same save
danielebarchiesi@0 4813 * operation using the 7.x schema.
danielebarchiesi@0 4814 *
danielebarchiesi@0 4815 * The utility function should not invoke any hooks, and should perform database
danielebarchiesi@0 4816 * operations using functions from the
danielebarchiesi@0 4817 * @link database Database abstraction layer, @endlink
danielebarchiesi@0 4818 * like db_insert(), db_update(), db_delete(), db_query(), and so on.
danielebarchiesi@0 4819 *
danielebarchiesi@0 4820 * If a change to the schema necessitates a change to the utility function, a
danielebarchiesi@0 4821 * new function should be created with a name based on the version of the schema
danielebarchiesi@0 4822 * it acts on. See _update_7000_bar_get_types() and _update_7001_bar_get_types()
danielebarchiesi@0 4823 * in the code examples that follow.
danielebarchiesi@0 4824 *
danielebarchiesi@0 4825 * For example, foo.install could contain:
danielebarchiesi@0 4826 * @code
danielebarchiesi@0 4827 * function foo_update_dependencies() {
danielebarchiesi@0 4828 * // foo_update_7010() needs to run after bar_update_7000().
danielebarchiesi@0 4829 * $dependencies['foo'][7010] = array(
danielebarchiesi@0 4830 * 'bar' => 7000,
danielebarchiesi@0 4831 * );
danielebarchiesi@0 4832 *
danielebarchiesi@0 4833 * // foo_update_7036() needs to run after bar_update_7001().
danielebarchiesi@0 4834 * $dependencies['foo'][7036] = array(
danielebarchiesi@0 4835 * 'bar' => 7001,
danielebarchiesi@0 4836 * );
danielebarchiesi@0 4837 *
danielebarchiesi@0 4838 * return $dependencies;
danielebarchiesi@0 4839 * }
danielebarchiesi@0 4840 *
danielebarchiesi@0 4841 * function foo_update_7000() {
danielebarchiesi@0 4842 * // No updates have been run on the {bar_types} table yet, so this needs
danielebarchiesi@0 4843 * // to work with the 6.x schema.
danielebarchiesi@0 4844 * foreach (_update_6000_bar_get_types() as $type) {
danielebarchiesi@0 4845 * // Rename a variable.
danielebarchiesi@0 4846 * }
danielebarchiesi@0 4847 * }
danielebarchiesi@0 4848 *
danielebarchiesi@0 4849 * function foo_update_7010() {
danielebarchiesi@0 4850 * // Since foo_update_7010() is going to run after bar_update_7000(), it
danielebarchiesi@0 4851 * // needs to operate on the new schema, not the old one.
danielebarchiesi@0 4852 * foreach (_update_7000_bar_get_types() as $type) {
danielebarchiesi@0 4853 * // Rename a different variable.
danielebarchiesi@0 4854 * }
danielebarchiesi@0 4855 * }
danielebarchiesi@0 4856 *
danielebarchiesi@0 4857 * function foo_update_7036() {
danielebarchiesi@0 4858 * // This update will run after bar_update_7001().
danielebarchiesi@0 4859 * foreach (_update_7001_bar_get_types() as $type) {
danielebarchiesi@0 4860 * }
danielebarchiesi@0 4861 * }
danielebarchiesi@0 4862 * @endcode
danielebarchiesi@0 4863 *
danielebarchiesi@0 4864 * And bar.install could contain:
danielebarchiesi@0 4865 * @code
danielebarchiesi@0 4866 * function bar_update_7000() {
danielebarchiesi@0 4867 * // Type and bundle are confusing, so we renamed the table.
danielebarchiesi@0 4868 * db_rename_table('bar_types', 'bar_bundles');
danielebarchiesi@0 4869 * }
danielebarchiesi@0 4870 *
danielebarchiesi@0 4871 * function bar_update_7001() {
danielebarchiesi@0 4872 * // Database table names should be singular when possible.
danielebarchiesi@0 4873 * db_rename_table('bar_bundles', 'bar_bundle');
danielebarchiesi@0 4874 * }
danielebarchiesi@0 4875 *
danielebarchiesi@0 4876 * function _update_6000_bar_get_types() {
danielebarchiesi@0 4877 * db_query('SELECT * FROM {bar_types}')->fetchAll();
danielebarchiesi@0 4878 * }
danielebarchiesi@0 4879 *
danielebarchiesi@0 4880 * function _update_7000_bar_get_types() {
danielebarchiesi@0 4881 * db_query('SELECT * FROM {bar_bundles'})->fetchAll();
danielebarchiesi@0 4882 * }
danielebarchiesi@0 4883 *
danielebarchiesi@0 4884 * function _update_7001_bar_get_types() {
danielebarchiesi@0 4885 * db_query('SELECT * FROM {bar_bundle}')->fetchAll();
danielebarchiesi@0 4886 * }
danielebarchiesi@0 4887 * @endcode
danielebarchiesi@0 4888 *
danielebarchiesi@0 4889 * @see hook_update_N()
danielebarchiesi@0 4890 * @see hook_update_dependencies()
danielebarchiesi@0 4891 */
danielebarchiesi@0 4892
danielebarchiesi@0 4893 /**
danielebarchiesi@0 4894 * @} End of "defgroup update_api".
danielebarchiesi@0 4895 */