node_export.api.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /**
  3. * @file
  4. * Documents Node export's hooks for api reference.
  5. */
  6. /**
  7. * Override export access on a node.
  8. *
  9. * Let other modules alter this - for example to only allow some users to
  10. * export specific nodes or types.
  11. *
  12. * @param &$access
  13. * Boolean access value for current user.
  14. * @param $node
  15. * The node to determine access for.
  16. */
  17. function hook_node_export_access_export_alter(&$access, $node) {
  18. // no example code
  19. }
  20. /**
  21. * Override import access on a node.
  22. *
  23. * Let other modules alter this - for example to only allow some users to
  24. * import specific nodes or types.
  25. *
  26. * @param &$access
  27. * Boolean access value for current user.
  28. * @param $node
  29. * The node to determine access for.
  30. */
  31. function hook_node_export_access_import_alter(&$access, $node) {
  32. // no example code
  33. }
  34. /**
  35. * Override one line of the export code output.
  36. *
  37. * @param &$out
  38. * The line of output.
  39. * @param $tab
  40. * The $tab variable from node_export_node_encode().
  41. * @param $key
  42. * The $key variable from node_export_node_encode().
  43. * @param $value
  44. * The $value variable from node_export_node_encode().
  45. * @param $iteration
  46. * The $iteration variable from node_export_node_encode().
  47. */
  48. function hook_node_export_node_encode_line_alter(&$out, $tab, $key, $value, $iteration) {
  49. // Start with something like this, and work on it:
  50. $out = $tab . " '" . $key . "' => " . node_export_node_encode($value, $iteration) . ",\n";
  51. }
  52. /**
  53. * Manipulate a node on export.
  54. *
  55. * @param &$node
  56. * The node to alter.
  57. * @param $original_node
  58. * The unaltered node.
  59. */
  60. function hook_node_export_node_alter(&$node, $original_node) {
  61. // no example code
  62. }
  63. /**
  64. * Manipulate a node on import.
  65. *
  66. * @param &$node
  67. * The node to alter.
  68. * @param $original_node
  69. * The unaltered node.
  70. * @param $save
  71. * Whether the node will be saved by node_export_import().
  72. */
  73. function hook_node_export_node_import_alter(&$node, $original_node, $save) {
  74. // no example code
  75. }
  76. /**
  77. * Manipulate node array before export.
  78. *
  79. * The purpose of this is to allow a module to check nodes in the array for
  80. * two or more nodes that must retain a relationship, and to add/remove other
  81. * data to the array to assist with maintaining dependencies, relationships,
  82. * references, and additional data required by the nodes.
  83. *
  84. * @param &$nodes
  85. * The array of nodes to alter.
  86. * @param $format
  87. * The format of node code being used.
  88. */
  89. function hook_node_export_alter(&$nodes, $format) {
  90. // no example code
  91. }
  92. /**
  93. * Manipulate node array before import.
  94. *
  95. * The purpose of this is to allow a module to check nodes in the array for
  96. * two or more nodes that must retain a relationship, and to add/remove other
  97. * data to the array to assist with maintaining dependencies, relationships,
  98. * references, and additional data required by the nodes.
  99. *
  100. * @param &$nodes
  101. * The array of nodes to alter.
  102. * @param $format
  103. * The format of node code being used.
  104. * @param $save
  105. * Whether the nodes will be saved by node_export_import().
  106. */
  107. function hook_node_export_import_alter(&$nodes, $format, $save) {
  108. // no example code
  109. }
  110. /**
  111. * Manipulate node array after import.
  112. *
  113. * The purpose of this is to allow a module to check nodes in the array for
  114. * two or more nodes that must retain a relationship, and to add/remove other
  115. * data to the array to assist with maintaining dependencies, relationships,
  116. * references, and additional data required by the nodes.
  117. *
  118. * @param &$nodes
  119. * The array of nodes to alter - IMPORTANT: keyed by node id.
  120. * @param $format
  121. * The format of node code being used.
  122. * @param $save
  123. * Whether the nodes were saved by node_export_import().
  124. */
  125. function hook_node_export_after_import_alter(&$nodes, $format, $save) {
  126. // no example code
  127. }
  128. /**
  129. * Manipulate the code string before import.
  130. *
  131. * @param &$code_string
  132. * The export code.
  133. */
  134. function hook_node_export_decode_alter(&$code_string) {
  135. // no example code
  136. }
  137. /**
  138. * Manipulate the code string upon export.
  139. *
  140. * @param &$code_string
  141. * The Node export code. Leave as FALSE for no change.
  142. * @param $nodes
  143. * The node.
  144. * @param $format
  145. * A string indicating what the export format is, and whether to do anything.
  146. */
  147. function hook_node_export_encode_alter(&$code_string, $nodes, $format) {
  148. // no example code
  149. }
  150. /**
  151. * Register a format handler.
  152. *
  153. * @return
  154. * An array keyed by format names containing an array with keys:
  155. * #title - the translated display name of the format
  156. * #module - the module that implements it.
  157. * #description - the translated description, please include links to docs that
  158. * give more info about the format.
  159. * #file - if a file is to be included for callbacks to work, give full path
  160. * here. This is optional.
  161. * #mime - to override the default text/plain mime type for the downloaded
  162. * file set this to the desired mime type string. This is optional.
  163. * #settings_callback - the function name of the settings callback, this is a
  164. * function that takes two params $form and $form_state, and returns an
  165. * array of form elements to append to the $form['basic'] area. The form
  166. * uses system_settings_form() so values will be automatically saved into
  167. * variables, but be sure your module deletes these variables upon
  168. * uninstall. This is optional.
  169. * #export_callback - the function name of the export callback, this is a
  170. * function that takes two params $nodes and $format, where $nodes is an array
  171. * of nodes and $format is the name of the format (in case same function used
  172. * for multiple formats).
  173. * #import_callback - the function name of the import callback, this is a
  174. * function that takes one parameter $code_string, and will be called of all
  175. * formats when an import is being performed, and should return:
  176. * The array of nodes, or nothing if code_string not handled by this
  177. * function.
  178. * If there is a problem with the supplied code return an array like so:
  179. * array(
  180. * 'success' => FALSE,
  181. * 'output' => array("error msg 1", "error msg 2", etc...),
  182. * )
  183. * Note: Do not use the t() function on error msgs, and don't mix the error
  184. * message with dynamic variables/content, at least not in the first message
  185. * so it can be translated properly and used as the main message. See the
  186. * XML implementation for malformed XML imports for an example that combines
  187. * information for the user followed by generated errors from PHP.
  188. */
  189. function hook_node_export_format_handlers() {
  190. return array(
  191. // Note: format_short_name should NOT contain the string 'node_export'.
  192. // Example from DSV format.
  193. 'dsv' => array(
  194. '#title' => t('DSV'),
  195. '#module' => 'node_export',
  196. '#file' => drupal_get_path('module', 'node_export') . '/formats/dsv.inc',
  197. '#description' => t(
  198. 'Configurable <a href="!dsv">Delimiter-separated values</a> code. Export and import sites must be configured the same.',
  199. array(
  200. '!dsv' => 'http://en.wikipedia.org/wiki/Delimiter-separated_values'
  201. )
  202. ),
  203. '#settings_callback' => 'node_export_dsv_settings',
  204. '#export_callback' => 'node_export_dsv_export',
  205. '#import_callback' => 'node_export_dsv_import',
  206. ),
  207. );
  208. }