PageRenderTime 37ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/system/system.api.php

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