feedback.api.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Feedback module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Act on an array of feedback entry objects when loaded from the database.
  12. *
  13. * @param $entries
  14. * An array of feedback entry objects, indexed by fid.
  15. */
  16. function hook_feedback_load($entries) {
  17. $result = db_query('SELECT * FROM {my_table} WHERE fid IN (:fids)', array(':fids' => array_keys($entries)));
  18. foreach ($result as $record) {
  19. $entries[$record->fid]->foo = $result->foo;
  20. }
  21. }
  22. /**
  23. * Act on a feedback entry before it is saved.
  24. *
  25. * Modules implementing this hook can act on the feedback entry object before it
  26. * is inserted or updated.
  27. *
  28. * @param $entry
  29. * The feedback entry object.
  30. */
  31. function hook_feedback_presave($entry) {
  32. $entry->foo = 'bar';
  33. }
  34. /**
  35. * Respond to creation of a new feedback entry.
  36. *
  37. * @param $entry
  38. * The feedback entry object.
  39. *
  40. * @see hook_feedback_update()
  41. */
  42. function hook_feedback_insert($entry) {
  43. db_insert('mytable')
  44. ->fields(array(
  45. 'fid' => $entry->fid,
  46. 'extra' => $entry->extra,
  47. ))
  48. ->execute();
  49. }
  50. /**
  51. * Respond to updates to a feedback entry.
  52. *
  53. * @param $entry
  54. * The feedback entry object.
  55. *
  56. * @see hook_feedback_insert()
  57. */
  58. function hook_feedback_update($entry) {
  59. db_update('mytable')
  60. ->fields(array('extra' => $entry->extra))
  61. ->condition('fid', $entry->fid)
  62. ->execute();
  63. }
  64. /**
  65. * Respond to deletion of a feedback entry.
  66. *
  67. * @param $entry
  68. * The feedback entry object.
  69. *
  70. * @see feedback_delete_multiple()
  71. */
  72. function hook_feedback_delete($entry) {
  73. db_delete('mytable')
  74. ->condition('fid', $entry->fid)
  75. ->execute();
  76. }
  77. /**
  78. * The feedback entry is being displayed.
  79. *
  80. * The module should format its custom additions for display and add them to the
  81. * $entry->content array.
  82. *
  83. * @param $entry
  84. * The feedback entry object.
  85. * @param $view_mode
  86. * View mode, e.g. 'full'.
  87. * @param $langcode
  88. * The language code used for rendering.
  89. *
  90. * @see hook_feedback_view_alter()
  91. * @see hook_entity_view()
  92. */
  93. function hook_feedback_view($entry, $view_mode, $langcode) {
  94. $entry->content['foo'] = array(
  95. '#markup' => t('Bar'),
  96. );
  97. }
  98. /**
  99. * The feedback entry was built; the module may modify the structured content.
  100. *
  101. * This hook is called after the content has been assembled in a structured
  102. * array and may be used for doing processing which requires that the complete
  103. * content structure has been built.
  104. *
  105. * @param $build
  106. * A renderable array representing the feedback entry.
  107. *
  108. * @see feedback_view()
  109. * @see hook_entity_view_alter()
  110. */
  111. function hook_feedback_view_alter(&$build) {
  112. // Check for the existence of a field added by another module.
  113. if (isset($build['an_additional_field'])) {
  114. // Change its weight.
  115. $build['an_additional_field']['#weight'] = -10;
  116. }
  117. // Add a #post_render callback to act on the rendered HTML of the entry.
  118. $build['#post_render'][] = 'my_module_feedback_post_render';
  119. }
  120. /**
  121. * @} End of "addtogroup hooks".
  122. */