redirect.api.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Redirect module.
  5. */
  6. /**
  7. * @defgroup redirect_api_hooks Redirect API Hooks
  8. * @{
  9. * During redirect operations (create, update, view, delete, etc.), there are
  10. * several sets of hooks that get invoked to allow modules to modify the
  11. * redirect operation:
  12. * - All-module hooks: Generic hooks for "redirect" operations. These are
  13. * always invoked on all modules.
  14. * - Entity hooks: Generic hooks for "entity" operations. These are always
  15. * invoked on all modules.
  16. *
  17. * Here is a list of the redirect and entity hooks that are invoked, and other
  18. * steps that take place during redirect operations:
  19. * - Creating a new redirect (calling redirect_save() on a new redirect):
  20. * - hook_redirect_presave() (all)
  21. * - Redirect written to the database
  22. * - hook_redirect_insert() (all)
  23. * - hook_entity_insert() (all)
  24. * - Updating an existing redirect (calling redirect_save() on an existing redirect):
  25. * - hook_redirect_presave() (all)
  26. * - Redirect written to the database
  27. * - hook_redirect_update() (all)
  28. * - hook_entity_update() (all)
  29. * - Loading a redirect (calling redirect_load(), redirect_load_multiple(), or
  30. * entity_load() with $entity_type of 'redirect'):
  31. * - Redirect information is read from database.
  32. * - hook_entity_load() (all)
  33. * - hook_redirect_load() (all)
  34. * - Deleting a redirect (calling redirect_delete() or redirect_delete_multiple()):
  35. * - Redirect is loaded (see Loading section above)
  36. * - Redirect information is deleted from database
  37. * - hook_redirect_delete() (all)
  38. * - hook_entity_delete() (all)
  39. * - Preparing a redirect for editing (note that if it's
  40. * an existing redirect, it will already be loaded; see the Loading section
  41. * above):
  42. * - hook_redirect_prepare() (all)
  43. * - Validating a redirect during editing form submit (calling
  44. * redirect_form_validate()):
  45. * - hook_redirect_validate() (all)
  46. * @}
  47. */
  48. /**
  49. * @addtogroup hooks
  50. * @{
  51. */
  52. /**
  53. * Act on redirects being loaded from the database.
  54. *
  55. * This hook is invoked during redirect loading, which is handled by
  56. * entity_load(), via classes RedirectController and
  57. * DrupalDefaultEntityController. After the redirect information is read from
  58. * the database or the entity cache, hook_entity_load() is invoked on all
  59. * implementing modules, and then hook_redirect_load() is invoked on all
  60. * implementing modules.
  61. *
  62. * This hook should only be used to add information that is not in the redirect
  63. * table, not to replace information that is in that table (which could
  64. * interfere with the entity cache). For performance reasons, information for
  65. * all available redirects should be loaded in a single query where possible.
  66. *
  67. * The $types parameter allows for your module to have an early return (for
  68. * efficiency) if your module only supports certain redirect types.
  69. *
  70. * @param $redirects
  71. * An array of the redirects being loaded, keyed by rid.
  72. * @param $types
  73. * An array containing the types of the redirects.
  74. *
  75. * @ingroup redirect_api_hooks
  76. */
  77. function hook_redirect_load(array &$redirects, $types) {
  78. }
  79. /**
  80. * Alter the list of redirects matching a certain source.
  81. *
  82. * @param $redirects
  83. * An array of redirect objects.
  84. * @param $source
  85. * The source request path.
  86. * @param $context
  87. * An array with the following key/value pairs:
  88. * - language: The language code of the source request.
  89. * - query: An array of the source request query string.
  90. *
  91. * @see redirect_load_by_source()
  92. * @ingroup redirect_api_hooks
  93. */
  94. function hook_redirect_load_by_source_alter(array &$redirects, $source, array $context) {
  95. foreach ($redirects as $rid => $redirect) {
  96. if ($redirect->source !== $source) {
  97. // If the redirects to do not exactly match $source (e.g. case
  98. // insensitive matches), then remove them from the results.
  99. unset($redirects[$rid]);
  100. }
  101. }
  102. }
  103. /**
  104. * Act on a redirect object about to be shown on the add/edit form.
  105. *
  106. * This hook is invoked from redirect_create().
  107. *
  108. * @param $redirect
  109. * The redirect that is about to be shown on the add/edit form.
  110. *
  111. * @ingroup redirect_api_hooks
  112. */
  113. function hook_redirect_prepare($redirect) {
  114. }
  115. /**
  116. * Act on a redirect being redirected.
  117. *
  118. * This hook is invoked from redirect_redirect() before the redirect callback
  119. * is invoked.
  120. *
  121. * @param $redirect
  122. * The redirect that is being used for the redirect.
  123. *
  124. * @see redirect_redirect()
  125. * @see drupal_page_is_cacheable()
  126. * @ingroup redirect_api_hooks
  127. */
  128. function hook_redirect_alter($redirect) {
  129. }
  130. /**
  131. * @} End of "addtogroup hooks".
  132. */