uc_store.api.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Store module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Allows modules to alter the TAPIr table after the rows are populated.
  12. *
  13. * The example below adds a value for the custom 'designer' column to the table
  14. * rows. Each table row has a numeric key in $table and these keys can be
  15. * accessed using element_children() from the Form API.
  16. *
  17. * @param $table
  18. * Table declaration containing header and populated rows.
  19. * @param $table_id
  20. * Table ID. Also the function called to build the table declaration.
  21. */
  22. function hook_tapir_table_alter(&$table, $table_id) {
  23. if ($table_id == 'uc_product_table') {
  24. foreach (element_children($table) as $key) {
  25. $node = node_load($table['#parameters'][1][$key]);
  26. $table[$key]['designer'] = array(
  27. '#markup' => l($node->designer, 'collections/' . $node->designer_tid),
  28. '#cell_attributes' => array('class' => array('designer')),
  29. );
  30. }
  31. }
  32. }
  33. /**
  34. * Allows modules to modify forms before Drupal invokes hook_form_alter().
  35. *
  36. * This hook will normally be used by core modules so any form modifications
  37. * they make can be further modified by contrib modules using a normal
  38. * hook_form_alter(). At this point, drupal_prepare_form() has not been called,
  39. * so none of the automatic form data (e.g.: #parameters, #build_id, etc.) has
  40. * been added yet.
  41. *
  42. * @see hook_form_alter()
  43. */
  44. function hook_uc_form_alter(&$form, &$form_state, $form_id) {
  45. // If the node has a product list, add attributes to them
  46. if (isset($form['products']) && count(element_children($form['products']))) {
  47. foreach (element_children($form['products']) as $key) {
  48. $form['products'][$key]['attributes'] = _uc_attribute_alter_form(node_load($key));
  49. if (is_array($form['products'][$key]['attributes'])) {
  50. $form['products'][$key]['attributes']['#tree'] = TRUE;
  51. $form['products'][$key]['#type'] = 'fieldset';
  52. }
  53. }
  54. }
  55. // If not, add attributes to the node.
  56. else {
  57. $form['attributes'] = _uc_attribute_alter_form($node);
  58. if (is_array($form['attributes'])) {
  59. $form['attributes']['#tree'] = TRUE;
  60. $form['attributes']['#weight'] = -1;
  61. }
  62. }
  63. }
  64. /**
  65. * Convenience function to display large blocks of text in several places.
  66. *
  67. * There are many instances where Ubercart modules have configurable blocks of
  68. * text. These usually come with default messages, like e-mail templates for new
  69. * orders. Because of the way default values are normally set, you're then stuck
  70. * having to copy and paste a large chunk of text in at least two different
  71. * places in the module (when you're wanting to use the variable or to display
  72. * the settings form with the default value). To cut down code clutter, this
  73. * hook was introduced. It lets you put your messages in one place and use the
  74. * function uc_get_message() to retrieve the default value at any time (and from
  75. * any module).
  76. *
  77. * The function is very simple, expecting no arguments and returning a basic
  78. * associative array with keys being message IDs and their values being the
  79. * default message. When you call uc_get_message(), use the message ID you set
  80. * here to refer to the message you want.
  81. *
  82. * Note: When using t(), you must not pass it a concatenated string! So our
  83. * example has no line breaks in the message even though it is much wider than
  84. * 80 characters. Using concatenation breaks translation.
  85. *
  86. * @return
  87. * An array of messages.
  88. */
  89. function hook_uc_message() {
  90. $messages['configurable_message_example'] = t('This block of text represents a configurable message such as a set of instructions or an e-mail template. Using hook_uc_message to handle the default values for these is so easy even your grandma can do it!');
  91. return $messages;
  92. }
  93. /**
  94. * Adds status messages to the "Store administration" page.
  95. *
  96. * This hook is used to add items to the store status table on the main store
  97. * administration screen. Each item gets a row in the table that consists of a
  98. * status icon, title, and description. These items should be used to give
  99. * special instructions, notifications, or indicators for components of the cart
  100. * enabled by the modules. At a glance, a store owner should be able to look
  101. * here and see if a critical component of your module is not functioning
  102. * properly.
  103. *
  104. * For example, if the catalog module is installed and it cannot find the
  105. * catalog taxonomy vocabulary, it will show an error message here to alert the
  106. * store administrator.
  107. *
  108. * @return
  109. * An array of store status items which are arrays with the following keys:
  110. * - status: "ok", "warning", or "error" depending on the message.
  111. * - title: The title of the status message or module that defines it.
  112. * - desc: The description; can be any message, including links to pages and
  113. * forms that deal with the issue being reported.
  114. */
  115. function hook_uc_store_status() {
  116. if ($key = uc_credit_encryption_key()) {
  117. $statuses[] = array(
  118. 'status' => 'ok',
  119. 'title' => t('Credit card encryption'),
  120. 'desc' => t('Credit card data in the database is currently being encrypted.'),
  121. );
  122. }
  123. return $statuses;
  124. }
  125. /**
  126. * @} End of "addtogroup hooks".
  127. */