Projet

Général

Profil

Paste
Télécharger (7,38 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / node_export / node_export.api.php @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Documents Node export's hooks for api reference.
6
 */
7

    
8
/**
9
 * Override export access on a node.
10
 *
11
 * Let other modules alter this - for example to only allow some users to
12
 * export specific nodes or types.
13
 *
14
 * @param &$access
15
 *   Boolean access value for current user.
16
 * @param $node
17
 *   The node to determine access for.
18
 */
19
function hook_node_export_access_export_alter(&$access, $node) {
20
  // no example code
21
}
22

    
23
/**
24
 * Override import access on a node.
25
 *
26
 * Let other modules alter this - for example to only allow some users to
27
 * import specific nodes or types.
28
 *
29
 * @param &$access
30
 *   Boolean access value for current user.
31
 * @param $node
32
 *   The node to determine access for.
33
 */
34
function hook_node_export_access_import_alter(&$access, $node) {
35
  // no example code
36
}
37

    
38
/**
39
 * Override one line of the export code output.
40
 *
41
 * @param &$out
42
 *   The line of output.
43
 * @param $tab
44
 *   The $tab variable from node_export_node_encode().
45
 * @param $key
46
 *   The $key variable from node_export_node_encode().
47
 * @param $value
48
 *   The $value variable from node_export_node_encode().
49
 * @param $iteration
50
 *   The $iteration variable from node_export_node_encode().
51
 */
52
function hook_node_export_node_encode_line_alter(&$out, $tab, $key, $value, $iteration) {
53
  // Start with something like this, and work on it:
54
  $out = $tab . "  '" . $key . "' => " . node_export_node_encode($value, $iteration) . ",\n";
55
}
56

    
57
/**
58
 * Manipulate a node on export.
59
 *
60
 * @param &$node
61
 *   The node to alter.
62
 * @param $original_node
63
 *   The unaltered node.
64
 */
65
function hook_node_export_node_alter(&$node, $original_node) {
66
  // no example code
67
}
68

    
69
/**
70
 * Manipulate a node on import.
71
 *
72
 * @param &$node
73
 *   The node to alter.
74
 * @param $original_node
75
 *   The unaltered node.
76
 * @param $save
77
 *   Whether the node will be saved by node_export_import().
78
 */
79
function hook_node_export_node_import_alter(&$node, $original_node, $save) {
80
  // no example code
81
}
82

    
83
/**
84
 * Manipulate node array before export.
85
 *
86
 * The purpose of this is to allow a module to check nodes in the array for
87
 * two or more nodes that must retain a relationship, and to add/remove other
88
 * data to the array to assist with maintaining dependencies, relationships,
89
 * references, and additional data required by the nodes.
90
 *
91
 * @param &$nodes
92
 *   The array of nodes to alter.
93
 * @param $format
94
 *   The format of node code being used.
95
 */
96
function hook_node_export_alter(&$nodes, $format) {
97
  // no example code
98
}
99

    
100
/**
101
 * Manipulate node array before import.
102
 *
103
 * The purpose of this is to allow a module to check nodes in the array for
104
 * two or more nodes that must retain a relationship, and to add/remove other
105
 * data to the array to assist with maintaining dependencies, relationships,
106
 * references, and additional data required by the nodes.
107
 *
108
 * @param &$nodes
109
 *   The array of nodes to alter.
110
 * @param $format
111
 *   The format of node code being used.
112
 * @param $save
113
 *   Whether the nodes will be saved by node_export_import().
114
 */
115
function hook_node_export_import_alter(&$nodes, $format, $save) {
116
  // no example code
117
}
118

    
119
/**
120
 * Manipulate node array after import.
121
 *
122
 * The purpose of this is to allow a module to check nodes in the array for
123
 * two or more nodes that must retain a relationship, and to add/remove other
124
 * data to the array to assist with maintaining dependencies, relationships,
125
 * references, and additional data required by the nodes.
126
 *
127
 * @param &$nodes
128
 *   The array of nodes to alter - IMPORTANT: keyed by node id.
129
 * @param $format
130
 *   The format of node code being used.
131
 * @param $save
132
 *   Whether the nodes were saved by node_export_import().
133
 */
134
function hook_node_export_after_import_alter(&$nodes, $format, $save) {
135
  // no example code
136
}
137

    
138
/**
139
 * Manipulate the code string before import.
140
 *
141
 * @param &$code_string
142
 *   The export code.
143
 */
144
function hook_node_export_decode_alter(&$code_string) {
145
  // no example code
146
}
147

    
148
/**
149
 * Manipulate the code string upon export.
150
 *
151
 * @param &$code_string
152
 *   The Node export code.  Leave as FALSE for no change.
153
 * @param $nodes
154
 *   The node.
155
 * @param $format
156
 *   A string indicating what the export format is, and whether to do anything.
157
 */
158
function hook_node_export_encode_alter(&$code_string, $nodes, $format) {
159
  // no example code
160
}
161

    
162
/**
163
 * Register a format handler.
164
 *
165
 * @return
166
 *   An array keyed by format names containing an array with keys:
167
 *   #title - the translated display name of the format
168
 *   #module - the module that implements it.
169
 *   #description - the translated description, please include links to docs that
170
 *   give more info about the format.
171
 *   #file - if a file is to be included for callbacks to work, give full path
172
 *     here. This is optional.
173
 *   #mime - to override the default text/plain mime type for the downloaded
174
 *     file set this to the desired mime type string.  This is optional.
175
 *   #settings_callback - the function name of the settings callback, this is a
176
 *     function that takes two params $form and $form_state, and returns an
177
 *     array of form elements to append to the $form['basic'] area.  The form
178
 *     uses system_settings_form() so values will be automatically saved into
179
 *     variables, but be sure your module deletes these variables upon
180
 *     uninstall. This is optional.
181
 *   #export_callback - the function name of the export callback, this is a
182
 *     function that takes two params $nodes and $format, where $nodes is an array
183
 *     of nodes and $format is the name of the format (in case same function used
184
 *     for multiple formats).
185
 *   #import_callback - the function name of the import callback, this is a
186
 *     function that takes one parameter $code_string, and will be called of all
187
 *     formats when an import is being performed, and should return:
188
 *       The array of nodes, or nothing if code_string not handled by this
189
 *       function.
190
 *       If there is a problem with the supplied code return an array like so:
191
 *         array(
192
 *           'success' => FALSE,
193
 *           'output' => array("error msg 1", "error msg 2", etc...),
194
 *         )
195
 *       Note: Do not use the t() function on error msgs, and don't mix the error
196
 *       message with dynamic variables/content, at least not in the first message
197
 *       so it can be translated properly and used as the main message.  See the
198
 *       XML implementation for malformed XML imports for an example that combines
199
 *       information for the user followed by generated errors from PHP.
200
 */
201
function hook_node_export_format_handlers() {
202
  return array(
203
    // Note: format_short_name should NOT contain the string 'node_export'.
204
    // Example from DSV format.
205
    'dsv' => array(
206
      '#title' => t('DSV'),
207
      '#module' => 'node_export',
208
      '#file' => drupal_get_path('module', 'node_export') . '/formats/dsv.inc',
209
      '#description' => t(
210
        'Configurable <a href="!dsv">Delimiter-separated values</a> code. Export and import sites must be configured the same.',
211
        array(
212
          '!dsv' => 'http://en.wikipedia.org/wiki/Delimiter-separated_values'
213
        )
214
      ),
215
      '#settings_callback' => 'node_export_dsv_settings',
216
      '#export_callback' => 'node_export_dsv_export',
217
      '#import_callback' => 'node_export_dsv_import',
218
    ),
219
  );
220
}