system.api.php

Hooks provided by Drupal core and the System module.

File

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

Functions

Namesort descending Description
callback_entity_info_label Return the label of an entity.
callback_entity_info_language Return the language code of the entity.
callback_entity_info_uri Return the URI for an entity.
hook_actions_delete Executes code after an action is deleted.
hook_action_info Declares information about actions.
hook_action_info_alter Alters the actions declared by another module.
hook_admin_paths Define administrative paths.
hook_admin_paths_alter Redefine administrative paths defined by other modules.
hook_ajax_render_alter Alter the commands that are sent to the user through the Ajax framework.
hook_archiver_info Declare archivers to the system.
hook_archiver_info_alter Alter archiver information declared by other modules.
hook_batch_alter Alter batch information before a batch is processed.
hook_boot Perform setup tasks for all page requests.
hook_countries_alter Alter the default country list.
hook_cron Perform periodic actions.
hook_cron_queue_info Declare queues holding items that need to be run periodically.
hook_cron_queue_info_alter Alter cron queue information before cron runs.
hook_css_alter Alter CSS files before they are output on the page.
hook_custom_theme Return the machine-readable name of the theme to use for the current page.
hook_date_formats Define additional date formats.
hook_date_formats_alter Alter date formats declared by another module.
hook_date_format_types Define additional date types.
hook_date_format_types_alter Modify existing date types.
hook_disable Perform necessary actions before module is disabled.
hook_drupal_goto_alter Change the page the user is sent to by drupal_goto().
hook_element_info Allows modules to declare their own Form API element types and specify their default values.
hook_element_info_alter Alter the element type information returned from modules.
hook_enable Perform necessary actions after module is enabled.
hook_entity_delete Act on entities when deleted.
hook_entity_info Inform the base system and the Field API about one or more entity types.
hook_entity_info_alter Alter the entity info.
hook_entity_insert Act on entities when inserted.
hook_entity_load Act on entities when loaded.
hook_entity_prepare_view Act on entities as they are being prepared for view.
hook_entity_presave Act on an entity before it is about to be created or updated.
hook_entity_query_alter Alter or execute an EntityFieldQuery.
hook_entity_update Act on entities when updated.
hook_entity_view Act on entities being assembled before rendering.
hook_entity_view_alter Alter the results of ENTITY_view().
hook_entity_view_mode_alter Change the view mode of an entity that is being displayed.
hook_exit Perform cleanup tasks.
hook_filetransfer_info Register information about FileTransfer classes provided by a module.
hook_filetransfer_info_alter Alter the FileTransfer class registry.
hook_file_copy Respond to a file that has been copied.
hook_file_delete Respond to a file being deleted.
hook_file_download Control access to private file downloads and specify HTTP headers.
hook_file_insert Respond to a file being added.
hook_file_load Load additional information into file objects.
hook_file_mimetype_mapping_alter Alter MIME type mappings used to determine MIME type from a file extension.
hook_file_move Respond to a file that has been moved.
hook_file_presave Act on a file being inserted or updated.
hook_file_update Respond to a file being updated.
hook_file_url_alter Alter the URL to a file.
hook_file_validate Check that files meet a given criteria.
hook_flush_caches Add a list of cache tables to be cleared.
hook_forms Map form_ids to form builder functions.
hook_form_alter Perform alterations before a form is rendered.
hook_form_BASE_FORM_ID_alter Provide a form-specific alteration for shared ('base') forms.
hook_form_FORM_ID_alter Provide a form-specific alteration instead of the global hook_form_alter().
hook_hook_info Defines one or more hooks that are exposed by a module.
hook_hook_info_alter Alter information from hook_hook_info().
hook_html_head_alter Alter XHTML HEAD tags before they are rendered by drupal_get_html_head().
hook_image_toolkits Define image toolkits provided by this module.
hook_init Perform setup tasks for non-cached page requests.
hook_install Perform setup tasks when the module is installed.
hook_install_tasks Return an array of tasks to be performed by an installation profile.
hook_install_tasks_alter Alter the full list of installation tasks.
hook_js_alter Perform necessary alterations to the JavaScript before it is presented on the page.
hook_library Registers JavaScript/CSS libraries associated with a module.
hook_library_alter Alters the JavaScript/CSS library registry.
hook_mail Prepare a message based on parameters; called from drupal_mail().
hook_mail_alter Alter an email message created with the drupal_mail() function.
hook_menu Define menu items and page callbacks.
hook_menu_alter Alter the data being saved to the {menu_router} table after hook_menu is invoked.
hook_menu_breadcrumb_alter Alter links in the active trail before it is rendered as the breadcrumb.
hook_menu_contextual_links_alter Alter contextual links before they are rendered.
hook_menu_get_item_alter Alter a menu router item right after it has been retrieved from the database or cache.
hook_menu_link_alter Alter the data being saved to the {menu_links} table by menu_link_save().
hook_menu_link_delete Inform modules that a menu link has been deleted.
hook_menu_link_insert Inform modules that a menu link has been created.
hook_menu_link_update Inform modules that a menu link has been updated.
hook_menu_local_tasks_alter Alter tabs and actions displayed on the page before they are rendered.
hook_menu_site_status_alter Control site status before menu dispatching.
hook_modules_disabled Perform necessary actions after modules are disabled.
hook_modules_enabled Perform necessary actions after modules are enabled.
hook_modules_installed Perform necessary actions after modules are installed.
hook_modules_uninstalled Perform necessary actions after modules are uninstalled.
hook_module_implements_alter Alter the registry of modules implementing a hook.
hook_page_alter Perform alterations before a page is rendered.
hook_page_build Add elements to a page before it is rendered.
hook_page_delivery_callback_alter Alters the delivery callback used to send the result of the page callback to the browser.
hook_permission Define user permissions.
hook_query_alter Perform alterations to a structured query.
hook_query_TAG_alter Perform alterations to a structured query for a given tag.
hook_registry_files_alter Perform necessary alterations to the list of files parsed by the registry.
hook_requirements Check installation requirements and do status reporting.
hook_schema Define the current version of the database schema.
hook_schema_alter Perform alterations to existing database schemas.
hook_stream_wrappers Registers PHP stream wrapper implementations associated with a module.
hook_stream_wrappers_alter Alters the list of PHP stream wrapper implementations.
hook_system_info_alter Alter the information parsed from module and theme .info files
hook_system_themes_page_alter Alters theme operation links.
hook_system_theme_info Return additional themes provided by modules.
hook_theme Register a module (or theme's) theme implementations.
hook_theme_registry_alter Alter the theme registry information returned from hook_theme().
hook_tokens Provide replacement values for placeholder tokens.
hook_tokens_alter Alter replacement values for placeholder tokens.
hook_token_info Provide information about available placeholder tokens and token types.
hook_token_info_alter Alter the metadata about available placeholder tokens and token types.
hook_translated_menu_link_alter Alter a menu link after it has been translated and before it is rendered.
hook_uninstall Remove any information that the module sets.
hook_updater_info Provide information on Updaters (classes that can update Drupal).
hook_updater_info_alter Alter the Updater information array.
hook_update_dependencies Return an array of information about module update dependencies.
hook_update_last_removed Return a number which is no longer available as hook_update_N().
hook_update_N Perform a single update.
hook_url_inbound_alter Alters inbound URL requests.
hook_url_outbound_alter Alters outbound URLs.
hook_username_alter Alter the username that is displayed for a user.
hook_watchdog Log an event message.
hook_xmlrpc Register XML-RPC callbacks.
hook_xmlrpc_alter Alters the definition of XML-RPC methods before they are called.