Passed
Pull Request — master (#2712)
by Christian
13:50 queued 06:33
created
sites/default/boinc/modules/contrib/cck/includes/content.node_form.inc 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
  * chosen widget.
10 10
  */
11 11
 function content_form(&$form, &$form_state) {
12
-  $type = content_types($form['type']['#value']);
13
-  foreach ($type['fields'] as $field_name => $field) {
12
+    $type = content_types($form['type']['#value']);
13
+    foreach ($type['fields'] as $field_name => $field) {
14 14
     $form['#field_info'][$field['field_name']] = $field;
15 15
     $form += (array) content_field_form($form, $form_state, $field);
16
-  }
17
-  return $form;
16
+    }
17
+    return $form;
18 18
 }
19 19
 
20 20
 /**
@@ -36,18 +36,18 @@  discard block
 block discarded – undo
36 36
  *   function will return the entire $field form element.
37 37
  */
38 38
 function content_field_form(&$form, &$form_state, $field, $get_delta = NULL) {
39
-  $form['#cache'] = FALSE;
40
-  $node = $form['#node'];
41
-  $addition = array();
42
-  $form_element = array();
43
-  $field_name = $field['field_name'];
44
-
45
-  $items = array();
46
-
47
-  // TODO: is the "if (function_exists($function)) {" needed ?
48
-  // defining the $function here makes it unclear where it is actually called
49
-  $function = $field['widget']['module'] .'_widget';
50
-  if (function_exists($function)) {
39
+    $form['#cache'] = FALSE;
40
+    $node = $form['#node'];
41
+    $addition = array();
42
+    $form_element = array();
43
+    $field_name = $field['field_name'];
44
+
45
+    $items = array();
46
+
47
+    // TODO: is the "if (function_exists($function)) {" needed ?
48
+    // defining the $function here makes it unclear where it is actually called
49
+    $function = $field['widget']['module'] .'_widget';
50
+    if (function_exists($function)) {
51 51
     // Prepare the values to be filled in the widget.
52 52
     // We look in the following places:
53 53
     // - Form submitted values
@@ -55,88 +55,88 @@  discard block
 block discarded – undo
55 55
     //   creating a new node translation)
56 56
     // - Default values set for the field (when creating a new node).
57 57
     if (!empty($form_state['values'][$field['field_name']])) {
58
-      $items = $form_state['values'][$field['field_name']];
59
-      // If there was an AHAH add more button in this field, don't save it.
60
-      unset($items[$field['field_name'] .'_add_more']);
58
+        $items = $form_state['values'][$field['field_name']];
59
+        // If there was an AHAH add more button in this field, don't save it.
60
+        unset($items[$field['field_name'] .'_add_more']);
61 61
     }
62 62
     elseif (!empty($node->$field['field_name'])) {
63
-      $items = $node->$field['field_name'];
63
+        $items = $node->$field['field_name'];
64 64
     }
65 65
     elseif (empty($node->nid)) {
66
-      if (content_callback('widget', 'default value', $field) != CONTENT_CALLBACK_NONE) {
66
+        if (content_callback('widget', 'default value', $field) != CONTENT_CALLBACK_NONE) {
67 67
         // If a module wants to insert custom default values here,
68 68
         // it should provide a hook_default_value() function to call,
69 69
         // otherwise the content module's content_default_value() function
70 70
         // will be used.
71 71
         $callback = content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_CUSTOM ? $field['widget']['module'] .'_default_value' : 'content_default_value';
72 72
         if (function_exists($callback)) {
73
-          $items = $callback($form, $form_state, $field, 0);
73
+            $items = $callback($form, $form_state, $field, 0);
74
+        }
74 75
         }
75
-      }
76 76
     }
77 77
 
78 78
     // See if access to this form element is restricted,
79 79
     // if so, skip widget processing and just set the value.
80 80
     $access = content_access('edit', $field, NULL, $node);
81 81
     if (!$access) {
82
-      $addition[$field_name] = array(
82
+        $addition[$field_name] = array(
83 83
         '#access' => $access,
84 84
         '#type' => 'value',
85 85
         '#value' => $items,
86
-      );
87
-      return $addition;
86
+        );
87
+        return $addition;
88 88
     }
89 89
 
90 90
     // If content module handles multiple values for this form element,
91 91
     // and not selecting an individual $delta, process the multiple value form.
92 92
     if (!isset($get_delta) && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) {
93
-      $form_element = content_multiple_value_form($form, $form_state, $field, $items);
93
+        $form_element = content_multiple_value_form($form, $form_state, $field, $items);
94 94
     }
95 95
     // If the widget is handling multiple values (e.g optionwidgets),
96 96
     // or selecting an individual element, just get a single form
97 97
     // element and make it the $delta value.
98 98
     else {
99
-      $delta = isset($get_delta) ? $get_delta : 0;
100
-      if ($element = $function($form, $form_state, $field, $items, $delta)) {
99
+        $delta = isset($get_delta) ? $get_delta : 0;
100
+        if ($element = $function($form, $form_state, $field, $items, $delta)) {
101 101
         $title = check_plain(t($field['widget']['label']));
102 102
         $description = content_filter_xss(t($field['widget']['description']));
103 103
         $defaults = array(
104
-          '#required' => $get_delta > 0 ? FALSE : $field['required'],
105
-          '#columns'  => array_keys($field['columns']),
106
-          '#title' => $title,
107
-          '#description' => $description,
108
-          '#delta' => $delta,
109
-          '#field_name' => $field['field_name'],
110
-          '#type_name' => $field['type_name'],
104
+            '#required' => $get_delta > 0 ? FALSE : $field['required'],
105
+            '#columns'  => array_keys($field['columns']),
106
+            '#title' => $title,
107
+            '#description' => $description,
108
+            '#delta' => $delta,
109
+            '#field_name' => $field['field_name'],
110
+            '#type_name' => $field['type_name'],
111 111
         );
112 112
         // If we're processing a specific delta value for a field where the
113 113
         // content module handles multiples, set the delta in the result.
114 114
         // For fields that handle their own processing, we can't make assumptions
115 115
         // about how the field is structured, just merge in the returned value.
116 116
         if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) {
117
-          $form_element[$delta] = array_merge($element, $defaults);
117
+            $form_element[$delta] = array_merge($element, $defaults);
118 118
         }
119 119
         else {
120
-          $form_element = array_merge($element, $defaults);
120
+            $form_element = array_merge($element, $defaults);
121
+        }
121 122
         }
122
-      }
123 123
     }
124 124
 
125 125
     // Field name is needed at top level as well as the individual elements
126 126
     // so the multiple values or other field level theme or processing can find it.
127 127
     if ($form_element) {
128
-      $defaults = array(
128
+        $defaults = array(
129 129
         '#field_name' => $field['field_name'],
130 130
         '#tree' => TRUE,
131 131
         '#weight' => $field['widget']['weight'],
132 132
         '#access' => $access,
133 133
         // TODO: what's the need for #count ? does not seem to be used anywhere ?
134 134
         '#count' => count($form_element),
135
-      );
136
-      $addition[$field['field_name']] = array_merge($form_element, $defaults);
135
+        );
136
+        $addition[$field['field_name']] = array_merge($form_element, $defaults);
137
+    }
137 138
     }
138
-  }
139
-  return $addition;
139
+    return $addition;
140 140
 }
141 141
 
142 142
 /**
@@ -148,42 +148,42 @@  discard block
 block discarded – undo
148 148
  * - drag-n-drop value reordering
149 149
  */
150 150
 function content_multiple_value_form(&$form, &$form_state, $field, $items) {
151
-  $field_name = $field['field_name'];
151
+    $field_name = $field['field_name'];
152 152
 
153
-  switch ($field['multiple']) {
153
+    switch ($field['multiple']) {
154 154
     case 0:
155 155
       $max = 0;
156
-      break;
156
+        break;
157 157
     case 1:
158 158
       $filled_items = content_set_empty($field, $items);
159
-      $current_item_count = isset($form_state['item_count'][$field_name])
159
+        $current_item_count = isset($form_state['item_count'][$field_name])
160 160
                             ? $form_state['item_count'][$field_name]
161 161
                             : count($items);
162
-      // We always want at least one empty icon for the user to fill in.
163
-      $max = ($current_item_count > count($filled_items))
162
+        // We always want at least one empty icon for the user to fill in.
163
+        $max = ($current_item_count > count($filled_items))
164 164
               ? $current_item_count - 1
165 165
               : $current_item_count;
166 166
 
167
-      break;
167
+        break;
168 168
     default:
169 169
       $max = $field['multiple'] - 1;
170
-      break;
171
-  }
170
+        break;
171
+    }
172 172
 
173
-  $title = check_plain(t($field['widget']['label']));
174
-  $description = content_filter_xss(t($field['widget']['description']));
173
+    $title = check_plain(t($field['widget']['label']));
174
+    $description = content_filter_xss(t($field['widget']['description']));
175 175
 
176
-  $form_element = array(
176
+    $form_element = array(
177 177
     '#theme' => 'content_multiple_values',
178 178
     '#title' => $title,
179 179
     '#required' => $field['required'],
180 180
     '#description' => $description,
181
-  );
182
-  $function = $field['widget']['module'] .'_widget';
181
+    );
182
+    $function = $field['widget']['module'] .'_widget';
183 183
 
184
-  for ($delta = 0; $delta <= $max; $delta++) {
184
+    for ($delta = 0; $delta <= $max; $delta++) {
185 185
     if ($element = $function($form, $form_state, $field, $items, $delta)) {
186
-      $defaults = array(
186
+        $defaults = array(
187 187
         '#title' => ($field['multiple'] >= 1) ? '' : $title,
188 188
         '#description' => ($field['multiple'] >= 1) ? '' : $description,
189 189
         '#required' => $delta == 0 && $field['required'],
@@ -192,51 +192,51 @@  discard block
 block discarded – undo
192 192
         '#columns' => array_keys($field['columns']),
193 193
         '#field_name' => $field_name,
194 194
         '#type_name' => $field['type_name'],
195
-      );
195
+        );
196 196
 
197
-      // Add an input field for the delta (drag-n-drop reordering), which will
198
-      // be hidden by tabledrag js behavior.
199
-      if ($field['multiple'] >= 1) {
197
+        // Add an input field for the delta (drag-n-drop reordering), which will
198
+        // be hidden by tabledrag js behavior.
199
+        if ($field['multiple'] >= 1) {
200 200
         // We name the element '_weight' to avoid clashing with column names
201 201
         // defined by field modules.
202 202
         $element['_weight'] = array(
203
-          '#type' => 'weight',
204
-          '#delta' => $max, // this 'delta' is the 'weight' element's property
205
-          '#default_value' => isset($items[$delta]['_weight']) ? $items[$delta]['_weight'] : $delta,
206
-          '#weight' => 100,
203
+            '#type' => 'weight',
204
+            '#delta' => $max, // this 'delta' is the 'weight' element's property
205
+            '#default_value' => isset($items[$delta]['_weight']) ? $items[$delta]['_weight'] : $delta,
206
+            '#weight' => 100,
207 207
         );
208
-      }
208
+        }
209 209
 
210
-      $form_element[$delta] = array_merge($element, $defaults);
210
+        $form_element[$delta] = array_merge($element, $defaults);
211
+    }
211 212
     }
212
-  }
213 213
 
214
-  // Add AHAH add more button, if not working with a programmed form.
215
-  if ($field['multiple'] == 1 && empty($form['#programmed'])) {
214
+    // Add AHAH add more button, if not working with a programmed form.
215
+    if ($field['multiple'] == 1 && empty($form['#programmed'])) {
216 216
     // Make sure the form is cached so ahah can work.
217 217
     $form['#cache'] = TRUE;
218 218
     $content_type = content_types($field['type_name']);
219 219
     $field_name_css = str_replace('_', '-', $field_name);
220 220
 
221 221
     $form_element[$field_name .'_add_more'] = array(
222
-      '#type' => 'submit',
223
-      '#name' => $field_name .'_add_more',
224
-      '#value' => t('Add another item'),
225
-      '#weight' => $field['widget']['weight'] + $max + 1,
226
-      // Submit callback for disabled JavaScript. drupal_get_form() might get
227
-      // the form from the cache, so we can't rely on content_form_alter()
228
-      // including this file. Therefore, call a proxy function to do this.
229
-      '#submit' => array('content_add_more_submit_proxy'),
230
-      '#ahah' => array(
222
+        '#type' => 'submit',
223
+        '#name' => $field_name .'_add_more',
224
+        '#value' => t('Add another item'),
225
+        '#weight' => $field['widget']['weight'] + $max + 1,
226
+        // Submit callback for disabled JavaScript. drupal_get_form() might get
227
+        // the form from the cache, so we can't rely on content_form_alter()
228
+        // including this file. Therefore, call a proxy function to do this.
229
+        '#submit' => array('content_add_more_submit_proxy'),
230
+        '#ahah' => array(
231 231
         'path' => 'content/js_add_more/'. $content_type['url_str'] .'/'. $field_name,
232 232
         'wrapper' => $field_name_css .'-items',
233 233
         'method' => 'replace',
234 234
         'effect' => 'fade',
235
-      ),
236
-      // When JS is disabled, the content_add_more_submit handler will find
237
-      // the relevant field using these entries.
238
-      '#field_name' => $field_name,
239
-      '#type_name' => $field['type_name'],
235
+        ),
236
+        // When JS is disabled, the content_add_more_submit handler will find
237
+        // the relevant field using these entries.
238
+        '#field_name' => $field_name,
239
+        '#type_name' => $field['type_name'],
240 240
     );
241 241
 
242 242
     // Add wrappers for the fields and 'more' button.
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
     $form_element['#suffix'] = '</div>';
245 245
     $form_element[$field_name .'_add_more']['#prefix'] = '<div class="content-add-more clear-block">';
246 246
     $form_element[$field_name .'_add_more']['#suffix'] = '</div>';
247
-  }
248
-  return $form_element;
247
+    }
248
+    return $form_element;
249 249
 }
250 250
 
251 251
 /**
@@ -254,127 +254,127 @@  discard block
 block discarded – undo
254 254
  * entire form is rebuilt during the page reload.
255 255
  */
256 256
 function content_add_more_submit($form, &$form_state) {
257
-  // Set the form to rebuild and run submit handlers.
258
-  node_form_submit_build_node($form, $form_state);
259
-  $field_name = $form_state['clicked_button']['#field_name'];
260
-  $type_name = $form_state['clicked_button']['#type_name'];
257
+    // Set the form to rebuild and run submit handlers.
258
+    node_form_submit_build_node($form, $form_state);
259
+    $field_name = $form_state['clicked_button']['#field_name'];
260
+    $type_name = $form_state['clicked_button']['#type_name'];
261 261
 
262
-  // Make the changes we want to the form state.
263
-  if ($form_state['values'][$field_name][$field_name .'_add_more']) {
262
+    // Make the changes we want to the form state.
263
+    if ($form_state['values'][$field_name][$field_name .'_add_more']) {
264 264
     $form_state['item_count'][$field_name] = count($form_state['values'][$field_name]);
265
-  }
265
+    }
266 266
 }
267 267
 
268 268
 /**
269 269
  * Menu callback for AHAH addition of new empty widgets.
270 270
  */
271 271
 function content_add_more_js($type_name_url, $field_name) {
272
-  $type = content_types($type_name_url);
273
-  $field = content_fields($field_name, $type['type']);
272
+    $type = content_types($type_name_url);
273
+    $field = content_fields($field_name, $type['type']);
274 274
 
275
-  if (($field['multiple'] != 1) || empty($_POST['form_build_id'])) {
275
+    if (($field['multiple'] != 1) || empty($_POST['form_build_id'])) {
276 276
     // Invalid request.
277 277
     drupal_json(array('data' => ''));
278 278
     exit;
279
-  }
279
+    }
280 280
 
281
-  // Retrieve the cached form.
282
-  $form_state = array('submitted' => FALSE);
283
-  $form_build_id = $_POST['form_build_id'];
284
-  $form = form_get_cache($form_build_id, $form_state);
285
-  if (!$form) {
281
+    // Retrieve the cached form.
282
+    $form_state = array('submitted' => FALSE);
283
+    $form_build_id = $_POST['form_build_id'];
284
+    $form = form_get_cache($form_build_id, $form_state);
285
+    if (!$form) {
286 286
     // Invalid form_build_id.
287 287
     drupal_json(array('data' => ''));
288 288
     exit;
289
-  }
290
-
291
-  // We don't simply return a new empty widget to append to existing ones, because
292
-  // - ahah.js won't simply let us add a new row to a table
293
-  // - attaching the 'draggable' behavior won't be easy
294
-  // So we resort to rebuilding the whole table of widgets including the existing ones,
295
-  // which makes us jump through a few hoops.
296
-
297
-  // The form that we get from the cache is unbuilt. We need to build it so that
298
-  // _value callbacks can be executed and $form_state['values'] populated.
299
-  // We only want to affect $form_state['values'], not the $form itself
300
-  // (built forms aren't supposed to enter the cache) nor the rest of $form_data,
301
-  // so we use copies of $form and $form_data.
302
-  $form_copy = $form;
303
-  $form_state_copy = $form_state;
304
-  $form_copy['#post'] = array();
305
-  form_builder($_POST['form_id'], $form_copy, $form_state_copy);
306
-  // Just grab the data we need.
307
-  $form_state['values'] = $form_state_copy['values'];
308
-  // Reset cached ids, so that they don't affect the actual form we output.
309
-  form_clean_id(NULL, TRUE);
310
-
311
-  // Sort the $form_state['values'] we just built *and* the incoming $_POST data
312
-  // according to d-n-d reordering.
313
-  unset($form_state['values'][$field_name][$field['field_name'] .'_add_more']);
314
-  foreach ($_POST[$field_name] as $delta => $item) {
289
+    }
290
+
291
+    // We don't simply return a new empty widget to append to existing ones, because
292
+    // - ahah.js won't simply let us add a new row to a table
293
+    // - attaching the 'draggable' behavior won't be easy
294
+    // So we resort to rebuilding the whole table of widgets including the existing ones,
295
+    // which makes us jump through a few hoops.
296
+
297
+    // The form that we get from the cache is unbuilt. We need to build it so that
298
+    // _value callbacks can be executed and $form_state['values'] populated.
299
+    // We only want to affect $form_state['values'], not the $form itself
300
+    // (built forms aren't supposed to enter the cache) nor the rest of $form_data,
301
+    // so we use copies of $form and $form_data.
302
+    $form_copy = $form;
303
+    $form_state_copy = $form_state;
304
+    $form_copy['#post'] = array();
305
+    form_builder($_POST['form_id'], $form_copy, $form_state_copy);
306
+    // Just grab the data we need.
307
+    $form_state['values'] = $form_state_copy['values'];
308
+    // Reset cached ids, so that they don't affect the actual form we output.
309
+    form_clean_id(NULL, TRUE);
310
+
311
+    // Sort the $form_state['values'] we just built *and* the incoming $_POST data
312
+    // according to d-n-d reordering.
313
+    unset($form_state['values'][$field_name][$field['field_name'] .'_add_more']);
314
+    foreach ($_POST[$field_name] as $delta => $item) {
315 315
     $form_state['values'][$field_name][$delta]['_weight'] = $item['_weight'];
316
-  }
317
-  $form_state['values'][$field_name] = _content_sort_items($field, $form_state['values'][$field_name]);
318
-  $_POST[$field_name] = _content_sort_items($field, $_POST[$field_name]);
319
-
320
-  // Build our new form element for the whole field, asking for one more element.
321
-  $form_state['item_count'] = array($field_name => count($_POST[$field_name]) + 1);
322
-  $form_element = content_field_form($form, $form_state, $field);
323
-  // Let other modules alter it.
324
-  // We pass an empty array as hook_form_alter's usual 'form_state' parameter,
325
-  // instead of $form_state (for reasons we may never remember).
326
-  // However, this argument is still expected to be passed by-reference
327
-  // (and PHP5.3 will throw an error if it isn't.) This leads to:
328
-  $data = &$form_element;
329
-  $empty_form_state = array();
330
-  $data['__drupal_alter_by_ref'] = array(&$empty_form_state);
331
-  drupal_alter('form', $data, 'content_add_more_js');
332
-
333
-  // Add the new element at the right place in the (original, unbuilt) form.
334
-  if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type['type'], $field_name))) {
316
+    }
317
+    $form_state['values'][$field_name] = _content_sort_items($field, $form_state['values'][$field_name]);
318
+    $_POST[$field_name] = _content_sort_items($field, $_POST[$field_name]);
319
+
320
+    // Build our new form element for the whole field, asking for one more element.
321
+    $form_state['item_count'] = array($field_name => count($_POST[$field_name]) + 1);
322
+    $form_element = content_field_form($form, $form_state, $field);
323
+    // Let other modules alter it.
324
+    // We pass an empty array as hook_form_alter's usual 'form_state' parameter,
325
+    // instead of $form_state (for reasons we may never remember).
326
+    // However, this argument is still expected to be passed by-reference
327
+    // (and PHP5.3 will throw an error if it isn't.) This leads to:
328
+    $data = &$form_element;
329
+    $empty_form_state = array();
330
+    $data['__drupal_alter_by_ref'] = array(&$empty_form_state);
331
+    drupal_alter('form', $data, 'content_add_more_js');
332
+
333
+    // Add the new element at the right place in the (original, unbuilt) form.
334
+    if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type['type'], $field_name))) {
335 335
     $form[$group_name][$field_name] = $form_element[$field_name];
336
-  }
337
-  else {
336
+    }
337
+    else {
338 338
     $form[$field_name] = $form_element[$field_name];
339
-  }
340
-
341
-  // Save the new definition of the form.
342
-  $form_state['values'] = array();
343
-  form_set_cache($form_build_id, $form, $form_state);
344
-
345
-  // Build the new form against the incoming $_POST values so that we can
346
-  // render the new element.
347
-  $delta = max(array_keys($_POST[$field_name])) + 1;
348
-  $_POST[$field_name][$delta]['_weight'] = $delta;
349
-  $form_state = array('submitted' => FALSE);
350
-  $form += array(
339
+    }
340
+
341
+    // Save the new definition of the form.
342
+    $form_state['values'] = array();
343
+    form_set_cache($form_build_id, $form, $form_state);
344
+
345
+    // Build the new form against the incoming $_POST values so that we can
346
+    // render the new element.
347
+    $delta = max(array_keys($_POST[$field_name])) + 1;
348
+    $_POST[$field_name][$delta]['_weight'] = $delta;
349
+    $form_state = array('submitted' => FALSE);
350
+    $form += array(
351 351
     '#post' => $_POST,
352 352
     '#programmed' => FALSE,
353
-  );
354
-  $form = form_builder($_POST['form_id'], $form, $form_state);
355
-
356
-  // Render the new output.
357
-  $field_form = (!empty($group_name)) ? $form[$group_name][$field_name] : $form[$field_name];
358
-  // We add a div around the new content to receive the ahah effect.
359
-  $field_form[$delta]['#prefix'] = '<div class="ahah-new-content">'. (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : '');
360
-  $field_form[$delta]['#suffix'] = (isset($field_form[$delta]['#suffix']) ? $field_form[$delta]['#suffix'] : '') .'</div>';
361
-  // Prevent duplicate wrapper.
362
-  unset($field_form['#prefix'], $field_form['#suffix']);
363
-
364
-  // If a newly inserted widget contains AHAH behaviors, they normally won't
365
-  // work because AHAH doesn't know about those - it just attaches to the exact
366
-  // form elements that were initially specified in the Drupal.settings object.
367
-  // The new ones didn't exist then, so we need to update Drupal.settings
368
-  // by ourselves in order to let AHAH know about those new form elements.
369
-  $javascript = drupal_add_js(NULL, NULL);
370
-  $output_js = isset($javascript['setting']) ? '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');</script>' : '';
371
-
372
-  $output = theme('status_messages') . drupal_render($field_form) . $output_js;
373
-
374
-  // Using drupal_json() breaks filefield's file upload, because the jQuery
375
-  // Form plugin handles file uploads in a way that is not compatible with
376
-  // 'text/javascript' response type.
377
-  $GLOBALS['devel_shutdown'] =  FALSE;
378
-  print drupal_to_js(array('status' => TRUE, 'data' => $output));
379
-  exit;
353
+    );
354
+    $form = form_builder($_POST['form_id'], $form, $form_state);
355
+
356
+    // Render the new output.
357
+    $field_form = (!empty($group_name)) ? $form[$group_name][$field_name] : $form[$field_name];
358
+    // We add a div around the new content to receive the ahah effect.
359
+    $field_form[$delta]['#prefix'] = '<div class="ahah-new-content">'. (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : '');
360
+    $field_form[$delta]['#suffix'] = (isset($field_form[$delta]['#suffix']) ? $field_form[$delta]['#suffix'] : '') .'</div>';
361
+    // Prevent duplicate wrapper.
362
+    unset($field_form['#prefix'], $field_form['#suffix']);
363
+
364
+    // If a newly inserted widget contains AHAH behaviors, they normally won't
365
+    // work because AHAH doesn't know about those - it just attaches to the exact
366
+    // form elements that were initially specified in the Drupal.settings object.
367
+    // The new ones didn't exist then, so we need to update Drupal.settings
368
+    // by ourselves in order to let AHAH know about those new form elements.
369
+    $javascript = drupal_add_js(NULL, NULL);
370
+    $output_js = isset($javascript['setting']) ? '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');</script>' : '';
371
+
372
+    $output = theme('status_messages') . drupal_render($field_form) . $output_js;
373
+
374
+    // Using drupal_json() breaks filefield's file upload, because the jQuery
375
+    // Form plugin handles file uploads in a way that is not compatible with
376
+    // 'text/javascript' response type.
377
+    $GLOBALS['devel_shutdown'] =  FALSE;
378
+    print drupal_to_js(array('status' => TRUE, 'data' => $output));
379
+    exit;
380 380
 }
Please login to merge, or discard this patch.
drupal/sites/default/boinc/modules/contrib/cck/includes/content.devel.inc 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -19,48 +19,48 @@  discard block
 block discarded – undo
19 19
  * information in each of its CCK fields.
20 20
  **/
21 21
 function content_generate_fields(&$node, $field) {
22
-  $type_name = $node->type;
23
-  $type = content_types($type_name);
24
-  $field_types = _content_field_types();
22
+    $type_name = $node->type;
23
+    $type = content_types($type_name);
24
+    $field_types = _content_field_types();
25 25
 
26
-  if (!empty($type['fields'])) {
26
+    if (!empty($type['fields'])) {
27 27
     foreach ($type['fields'] as $field) {
28
-      $node_field = array();
29
-      // If module handles own multiples, then only call its hook once.
30
-      if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) {
28
+        $node_field = array();
29
+        // If module handles own multiples, then only call its hook once.
30
+        if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) {
31 31
         $max = 0;
32
-      }
33
-      else {
32
+        }
33
+        else {
34 34
         switch ($field['multiple']) {
35
-          case 0:
35
+            case 0:
36 36
             $max = 0;
37 37
             break;
38
-          case 1:
38
+            case 1:
39 39
             $max = rand(0, 3); //just an arbitrary number for 'unlimited'
40 40
             break;
41
-          default:
41
+            default:
42 42
             $max = $field['multiple'];
43 43
             break;
44 44
         }
45
-      }
46
-      for ($i = 0; $i <= $max; $i++) {
45
+        }
46
+        for ($i = 0; $i <= $max; $i++) {
47 47
         $module = $field_types[$field['type']]['module'];
48 48
         $function = $module .'_content_generate';
49 49
         if (function_exists($function)) {
50
-          $result = $function($node, $field); // $items, $teaser, $page
51
-          if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) {
50
+            $result = $function($node, $field); // $items, $teaser, $page
51
+            if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) {
52 52
             // Fields that handle their own multiples will add their own deltas.
53 53
             $node_field = $result;
54
-          }
55
-          else {
54
+            }
55
+            else {
56 56
             // When multiples are handled by the content module, add a delta for each result.
57 57
             $node_field[$i] = $result;
58
-          }
58
+            }
59 59
         }
60
-      }
61
-      $node->{$field['field_name']} = $node_field;
60
+        }
61
+        $node->{$field['field_name']} = $node_field;
62
+    }
62 63
     }
63
-  }
64 64
 }
65 65
 
66 66
 /**
@@ -70,149 +70,149 @@  discard block
 block discarded – undo
70 70
  * a random number of times and compile the results into a node array.
71 71
  */
72 72
 function content_devel_multiple($function, $node, $field) {
73
-  $node_field = array();
74
-  if (function_exists($function)) {
73
+    $node_field = array();
74
+    if (function_exists($function)) {
75 75
     switch ($field['multiple']) {
76
-      case 0:
76
+        case 0:
77 77
         $max = 0;
78 78
         break;
79
-      case 1:
79
+        case 1:
80 80
         $max = rand(0, 3); //just an arbitrary number for 'unlimited'
81 81
         break;
82
-      default:
82
+        default:
83 83
         $max = $field['multiple'];
84 84
         break;
85 85
     }
86 86
     for ($i = 0; $i <= $max; $i++) {
87
-      $node_field[$i] = $function($node, $field);
87
+        $node_field[$i] = $function($node, $field);
88
+    }
88 89
     }
89
-  }
90
-  return $node_field;
90
+    return $node_field;
91 91
 }
92 92
 
93 93
 if (module_exists('text')) {
94
-  function text_content_generate($node, $field) {
94
+    function text_content_generate($node, $field) {
95 95
     if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) {
96
-      return content_devel_multiple('_text_content_generate', $node, $field);
96
+        return content_devel_multiple('_text_content_generate', $node, $field);
97 97
     }
98 98
     else {
99
-      return _text_content_generate($node, $field);
99
+        return _text_content_generate($node, $field);
100
+    }
100 101
     }
101
-  }
102 102
 
103
-  function _text_content_generate($node, $field) {
103
+    function _text_content_generate($node, $field) {
104 104
     $node_field = array();
105 105
     if ($field['widget']['type'] == 'text_textarea') {
106
-      $format = $field['text_processing'] ? rand(0, 3) : 0;
107
-      $node_field['value'] = devel_create_content($format);
108
-      $node_field['format'] = $format;
106
+        $format = $field['text_processing'] ? rand(0, 3) : 0;
107
+        $node_field['value'] = devel_create_content($format);
108
+        $node_field['format'] = $format;
109 109
     }
110 110
     else {
111
-      $allowed_values = content_allowed_values($field);
112
-      if (!empty($allowed_values)) {
111
+        $allowed_values = content_allowed_values($field);
112
+        if (!empty($allowed_values)) {
113 113
         // Just pick one of the specified allowed values.
114 114
         $node_field['value'] = array_rand($allowed_values);
115
-      }
116
-      else {
115
+        }
116
+        else {
117 117
         // Generate a value that respects max_length.
118 118
         if (empty($field['max_length'])) {
119
-          $field['max_length'] = 12;
119
+            $field['max_length'] = 12;
120 120
         }
121 121
         $node_field['value'] = user_password($field['max_length']);
122
-      }
122
+        }
123 123
     }
124 124
     return $node_field;
125
-  }
125
+    }
126 126
 }
127 127
 
128 128
 if (module_exists('number')) {
129
-  function number_content_generate($node, $field) {
129
+    function number_content_generate($node, $field) {
130 130
     if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) {
131
-      return content_devel_multiple('_number_content_generate', $node, $field);
131
+        return content_devel_multiple('_number_content_generate', $node, $field);
132 132
     }
133 133
     else {
134
-      return _number_content_generate($node, $field);
134
+        return _number_content_generate($node, $field);
135
+    }
135 136
     }
136
-  }
137 137
 
138
-  function _number_content_generate($node, $field) {
138
+    function _number_content_generate($node, $field) {
139 139
     $node_field = array();
140 140
     $allowed_values = content_allowed_values($field);
141 141
     if (!empty($allowed_values)) {
142
-      // Just pick one of the specified allowed values.
143
-      $node_field['value'] = array_rand($allowed_values);
142
+        // Just pick one of the specified allowed values.
143
+        $node_field['value'] = array_rand($allowed_values);
144 144
     }
145 145
     else {
146
-      $min = is_numeric($field['min']) ? $field['min'] : 0;
147
-      switch ($field['type']) {
146
+        $min = is_numeric($field['min']) ? $field['min'] : 0;
147
+        switch ($field['type']) {
148 148
         case 'number_integer':
149 149
           $max = is_numeric($field['max']) ? $field['max'] : 10000;
150
-          $decimal = 0;
151
-          $scale = 0;
152
-          break;
150
+            $decimal = 0;
151
+            $scale = 0;
152
+            break;
153 153
 
154 154
         case 'number_decimal':
155 155
           $precision = is_numeric($field['precision']) ? $field['precision'] : 10;
156
-          $scale = is_numeric($field['scale']) ? $field['scale'] : 2;
157
-          $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale));
158
-          $decimal = rand(0, (10 * $scale)) / 100;
159
-          break;
156
+            $scale = is_numeric($field['scale']) ? $field['scale'] : 2;
157
+            $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale));
158
+            $decimal = rand(0, (10 * $scale)) / 100;
159
+            break;
160 160
 
161 161
         case 'number_float':
162 162
           $precision = rand(10, 32);
163
-          $scale = rand(0, 2);
164
-          $decimal = rand(0, (10 * $scale)) / 100;
165
-          $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale));
166
-          break;
167
-      }
168
-      $node_field['value'] = round((rand($min, $max) + $decimal), $scale);
163
+            $scale = rand(0, 2);
164
+            $decimal = rand(0, (10 * $scale)) / 100;
165
+            $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale));
166
+            break;
167
+        }
168
+        $node_field['value'] = round((rand($min, $max) + $decimal), $scale);
169 169
     }
170 170
     return $node_field;
171
-  }
171
+    }
172 172
 }
173 173
 
174 174
 if (module_exists('nodereference')) {
175
-  function nodereference_content_generate($node, $field) {
175
+    function nodereference_content_generate($node, $field) {
176 176
     if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) {
177
-      return content_devel_multiple('_nodereference_content_generate', $node, $field);
177
+        return content_devel_multiple('_nodereference_content_generate', $node, $field);
178 178
     }
179 179
     else {
180
-      return _nodereference_content_generate($node, $field);
180
+        return _nodereference_content_generate($node, $field);
181
+    }
181 182
     }
182
-  }
183 183
 
184
-  function _nodereference_content_generate($node, $field) {
184
+    function _nodereference_content_generate($node, $field) {
185 185
     $node_field = array();
186 186
     $allowed_values = nodereference_allowed_values($field);
187 187
     unset($allowed_values[0]);
188 188
     if (!empty($allowed_values)) {
189
-      // Just pick one of the specified allowed values.
190
-      $node_field['nid'] = array_rand($allowed_values);
189
+        // Just pick one of the specified allowed values.
190
+        $node_field['nid'] = array_rand($allowed_values);
191 191
     }
192 192
     return $node_field;
193
-  }
193
+    }
194 194
 }
195 195
 
196 196
 if (module_exists('userreference')) {
197
-  function userreference_content_generate($node, $field) {
197
+    function userreference_content_generate($node, $field) {
198 198
     if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) {
199
-      return content_devel_multiple('_userreference_content_generate', $node, $field);
199
+        return content_devel_multiple('_userreference_content_generate', $node, $field);
200 200
     }
201 201
     else {
202
-      return _userreference_content_generate($node, $field);
202
+        return _userreference_content_generate($node, $field);
203
+    }
203 204
     }
204
-  }
205 205
 
206
-  function _userreference_content_generate($node, $field) {
206
+    function _userreference_content_generate($node, $field) {
207 207
     $node_field = array();
208 208
     $allowed_values = userreference_allowed_values($field);
209 209
     if (isset($allowed_values['none'])) {
210
-      unset($allowed_values['none']);
210
+        unset($allowed_values['none']);
211 211
     }
212 212
     if (!empty($allowed_values)) {
213
-      // Just pick one of the specified allowed values.
214
-      $node_field['uid'] = array_rand($allowed_values);
213
+        // Just pick one of the specified allowed values.
214
+        $node_field['uid'] = array_rand($allowed_values);
215 215
     }
216 216
     return $node_field;
217
-  }
217
+    }
218 218
 }
219 219
\ No newline at end of file
Please login to merge, or discard this patch.
drupal/sites/default/boinc/modules/contrib/cck/includes/content.token.inc 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -7,181 +7,181 @@
 block discarded – undo
7 7
  * (on behalf of token.module)
8 8
  */
9 9
 function token_content_build_modes() {
10
-  return array(
10
+    return array(
11 11
     'token' => array(
12
-      'title' => t('Token'),
13
-      'build modes' => array(
12
+        'title' => t('Token'),
13
+        'build modes' => array(
14 14
         'token' => array(
15
-          'title' => t('Token'),
16
-          'views style' => FALSE,
15
+            'title' => t('Token'),
16
+            'views style' => FALSE,
17
+        ),
17 18
         ),
18
-      ),
19 19
     ),
20
-  );
20
+    );
21 21
 }
22 22
 
23 23
 // Two helper functions that generate appropriate tokens for CCK-added fields.
24 24
 function content_token_values($type, $object = NULL, $options = array()) {
25
-  $tokens = array();
26
-  if ($type == 'node') {
25
+    $tokens = array();
26
+    if ($type == 'node') {
27 27
     // Prevent against invalid 'nodes' built by broken 3rd party code.
28 28
     if (isset($object->type)) {
29
-      // Let PHP free the $node object when we are done. Working directly on the
30
-      // incoming $object causes memory leak issues on long-running scripts such
31
-      // as migrations. See http://drupal.org/node/736440.
32
-      $node = drupal_clone($object);
33
-      $content_type = content_types($node->type);
34
-      $node->build_mode = 'token';
35
-      $node->content = array();
36
-      content_view($node);
37
-      // The formatted values will only be known after the content has been rendered.
38
-      drupal_render($node->content);
39
-      content_alter($node);
40
-
41
-      $field_types = _content_field_types();
42
-      foreach ($content_type['fields'] as $field_name => $field) {
29
+        // Let PHP free the $node object when we are done. Working directly on the
30
+        // incoming $object causes memory leak issues on long-running scripts such
31
+        // as migrations. See http://drupal.org/node/736440.
32
+        $node = drupal_clone($object);
33
+        $content_type = content_types($node->type);
34
+        $node->build_mode = 'token';
35
+        $node->content = array();
36
+        content_view($node);
37
+        // The formatted values will only be known after the content has been rendered.
38
+        drupal_render($node->content);
39
+        content_alter($node);
40
+
41
+        $field_types = _content_field_types();
42
+        foreach ($content_type['fields'] as $field_name => $field) {
43 43
         $items = isset($node->{$field_name}) ? $node->{$field_name} : array();
44 44
         $function = $field_types[$field['type']]['module'] . '_token_values';
45 45
         if (!empty($items) && function_exists($function)) {
46
-          $token_values = (array) $function('field', $items, $options);
47
-          foreach ($token_values as $token => $value) {
46
+            $token_values = (array) $function('field', $items, $options);
47
+            foreach ($token_values as $token => $value) {
48 48
             $tokens[$field_name .'-'. $token] = $value;
49
-          }
49
+            }
50
+        }
50 51
         }
51
-      }
52 52
     }
53
-  }
54
-  return $tokens;
53
+    }
54
+    return $tokens;
55 55
 }
56 56
 
57 57
 function content_token_list($type = 'all') {
58
-  if ($type == 'node' || $type == 'all') {
58
+    if ($type == 'node' || $type == 'all') {
59 59
     $list = array();
60 60
     $field_types = _content_field_types();
61 61
 
62 62
     foreach (content_fields() as $field) {
63
-      $sub_list = array();
64
-      $function = $field_types[$field['type']]['module'] . '_token_list';
65
-      if (function_exists($function)) {
63
+        $sub_list = array();
64
+        $function = $field_types[$field['type']]['module'] . '_token_list';
65
+        if (function_exists($function)) {
66 66
         $sub_list = $function('field');
67 67
         foreach ($sub_list as $category => $token_list) {
68
-          foreach ($token_list as $token => $description) {
68
+            foreach ($token_list as $token => $description) {
69 69
             $list['CCK '. $category][$field['field_name'] .'-'. $token] = $description;
70
-          }
70
+            }
71
+        }
71 72
         }
72
-      }
73 73
     }
74 74
 
75 75
     return $list;
76
-  }
76
+    }
77 77
 }
78 78
 
79 79
 if (module_exists('nodereference')) {
80
-  function nodereference_token_list($type = 'all') {
80
+    function nodereference_token_list($type = 'all') {
81 81
     if ($type == 'field' || $type == 'all') {
82
-      $tokens = array();
82
+        $tokens = array();
83 83
 
84
-      $tokens['node reference']['nid']   = t('Referenced node ID');
85
-      $tokens['node reference']['title'] = t('Referenced node title');
86
-      $tokens['node reference']['title-raw'] = t('Referenced node unfiltered title. WARNING - raw user input.');
87
-      $tokens['node reference']['link']  = t("Formatted html link to the referenced node.");
88
-      $tokens['node reference']['path']  = t("Relative path alias to the referenced node.");
89
-      $tokens['node reference']['url']  = t("Absolute path alias to the referenced node.");
84
+        $tokens['node reference']['nid']   = t('Referenced node ID');
85
+        $tokens['node reference']['title'] = t('Referenced node title');
86
+        $tokens['node reference']['title-raw'] = t('Referenced node unfiltered title. WARNING - raw user input.');
87
+        $tokens['node reference']['link']  = t("Formatted html link to the referenced node.");
88
+        $tokens['node reference']['path']  = t("Relative path alias to the referenced node.");
89
+        $tokens['node reference']['url']  = t("Absolute path alias to the referenced node.");
90 90
 
91
-      return $tokens;
91
+        return $tokens;
92
+    }
92 93
     }
93
-  }
94 94
 
95
-  function nodereference_token_values($type, $object = NULL, $options = array()) {
95
+    function nodereference_token_values($type, $object = NULL, $options = array()) {
96 96
     if ($type == 'field') {
97
-      $item = $object[0];
97
+        $item = $object[0];
98 98
 
99
-      $title = is_numeric($item['nid']) ? _nodereference_titles($item['nid']) : '';
100
-      $tokens['nid']   = $item['nid'];
101
-      $tokens['title'] = $title ? check_plain($title) : '';
102
-      $tokens['title-raw'] = $title;
103
-      $tokens['link']  = isset($item['view']) ? $item['view'] : '';
104
-      $tokens['path'] = is_numeric($item['nid']) ? url('node/' . $item['nid']) : '';
105
-      $tokens['url'] = is_numeric($item['nid']) ? url('node/' . $item['nid'], array('absolute' => TRUE)) : '';
99
+        $title = is_numeric($item['nid']) ? _nodereference_titles($item['nid']) : '';
100
+        $tokens['nid']   = $item['nid'];
101
+        $tokens['title'] = $title ? check_plain($title) : '';
102
+        $tokens['title-raw'] = $title;
103
+        $tokens['link']  = isset($item['view']) ? $item['view'] : '';
104
+        $tokens['path'] = is_numeric($item['nid']) ? url('node/' . $item['nid']) : '';
105
+        $tokens['url'] = is_numeric($item['nid']) ? url('node/' . $item['nid'], array('absolute' => TRUE)) : '';
106 106
 
107
-      return $tokens;
107
+        return $tokens;
108
+    }
108 109
     }
109
-  }
110 110
 }
111 111
 
112 112
 if (module_exists('number')) {
113
-  function number_token_list($type = 'all') {
113
+    function number_token_list($type = 'all') {
114 114
     if ($type == 'field' || $type == 'all') {
115
-      $tokens = array();
115
+        $tokens = array();
116 116
 
117
-      $tokens['number']['raw']       = t('Raw number value');
118
-      $tokens['number']['formatted'] = t('Formatted number value');
117
+        $tokens['number']['raw']       = t('Raw number value');
118
+        $tokens['number']['formatted'] = t('Formatted number value');
119 119
 
120
-      return $tokens;
120
+        return $tokens;
121
+    }
121 122
     }
122
-  }
123 123
 
124
-  function number_token_values($type, $object = NULL, $options = array()) {
124
+    function number_token_values($type, $object = NULL, $options = array()) {
125 125
     if ($type == 'field') {
126
-      $item = $object[0];
126
+        $item = $object[0];
127 127
 
128
-      $tokens['raw']       = $item['value'];
129
-      $tokens['formatted'] = isset($item['view']) ? $item['view'] : '';
128
+        $tokens['raw']       = $item['value'];
129
+        $tokens['formatted'] = isset($item['view']) ? $item['view'] : '';
130 130
 
131
-      return $tokens;
131
+        return $tokens;
132
+    }
132 133
     }
133
-  }
134 134
 }
135 135
 
136 136
 if (module_exists('text')) {
137
-  function text_token_list($type = 'all') {
137
+    function text_token_list($type = 'all') {
138 138
     if ($type == 'field' || $type == 'all') {
139
-      $tokens = array();
139
+        $tokens = array();
140 140
 
141
-      $tokens['text']['raw']       = t('Raw, unfiltered text');
142
-      $tokens['text']['formatted'] = t('Formatted and filtered text');
141
+        $tokens['text']['raw']       = t('Raw, unfiltered text');
142
+        $tokens['text']['formatted'] = t('Formatted and filtered text');
143 143
 
144
-      return $tokens;
144
+        return $tokens;
145
+    }
145 146
     }
146
-  }
147 147
 
148
-  function text_token_values($type, $object = NULL, $options = array()) {
148
+    function text_token_values($type, $object = NULL, $options = array()) {
149 149
     if ($type == 'field') {
150
-      $item = $object[0];
150
+        $item = $object[0];
151 151
 
152
-      $tokens['raw']  = $item['value'];
153
-      $tokens['formatted'] = isset($item['view']) ? $item['view'] : '';
154
-      return $tokens;
152
+        $tokens['raw']  = $item['value'];
153
+        $tokens['formatted'] = isset($item['view']) ? $item['view'] : '';
154
+        return $tokens;
155
+    }
155 156
     }
156
-  }
157 157
 }
158 158
 
159 159
 if (module_exists('userreference')) {
160
-  function userreference_token_list($type = 'all') {
160
+    function userreference_token_list($type = 'all') {
161 161
     if ($type == 'field' || $type == 'all') {
162
-      $tokens = array();
162
+        $tokens = array();
163 163
 
164
-      $tokens['user reference']['uid']   = t('Referenced user ID');
165
-      $tokens['user reference']['name']  = t('Referenced user name');
166
-      $tokens['user reference']['link']  = t('Formatted HTML link to referenced user');
167
-      $tokens['user reference']['path']  = t("Relative path alias to the referenced user.");
168
-      $tokens['user reference']['url']  = t("Absolute path alias to the referenced user.");
164
+        $tokens['user reference']['uid']   = t('Referenced user ID');
165
+        $tokens['user reference']['name']  = t('Referenced user name');
166
+        $tokens['user reference']['link']  = t('Formatted HTML link to referenced user');
167
+        $tokens['user reference']['path']  = t("Relative path alias to the referenced user.");
168
+        $tokens['user reference']['url']  = t("Absolute path alias to the referenced user.");
169 169
 
170
-      return $tokens;
170
+        return $tokens;
171
+    }
171 172
     }
172
-  }
173 173
 
174
-  function userreference_token_values($type, $object = NULL, $options = array()) {
174
+    function userreference_token_values($type, $object = NULL, $options = array()) {
175 175
     if ($type == 'field') {
176
-      $item = $object[0];
176
+        $item = $object[0];
177 177
 
178
-      $tokens['uid']   = $item['uid'];
179
-      $tokens['name']  = isset($item['view']) ? strip_tags($item['view']) : '';
180
-      $tokens['link']  = isset($item['view']) ? $item['view'] : '';
181
-      $tokens['path'] = is_numeric($item['uid']) ? url('user/' . $item['uid']) : '';
182
-      $tokens['url'] = is_numeric($item['uid']) ? url('user/' . $item['uid'], array('absolute' => TRUE)) : '';
178
+        $tokens['uid']   = $item['uid'];
179
+        $tokens['name']  = isset($item['view']) ? strip_tags($item['view']) : '';
180
+        $tokens['link']  = isset($item['view']) ? $item['view'] : '';
181
+        $tokens['path'] = is_numeric($item['uid']) ? url('user/' . $item['uid']) : '';
182
+        $tokens['url'] = is_numeric($item['uid']) ? url('user/' . $item['uid'], array('absolute' => TRUE)) : '';
183 183
 
184
-      return $tokens;
184
+        return $tokens;
185
+    }
185 186
     }
186
-  }
187 187
 }
Please login to merge, or discard this patch.
drupal/sites/default/boinc/modules/contrib/cck/includes/content.rules.inc 1 patch
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -10,34 +10,34 @@  discard block
 block discarded – undo
10 10
  * Implementation of hook_rules_action_info().
11 11
  */
12 12
 function content_rules_action_info() {
13
-  $info = array();
14
-  $info['content_rules_action_populate_field'] = array(
13
+    $info = array();
14
+    $info['content_rules_action_populate_field'] = array(
15 15
     'label' => t('Populate a field'),
16 16
     'arguments' => array(
17
-      'node' => array(
17
+        'node' => array(
18 18
         'type' => 'node',
19 19
         'label' => t('Content'),
20
-      ),
20
+        ),
21 21
     ),
22 22
     'eval input' => array('code'),
23 23
     'help' => t('You should make sure that the used field exists in the given content type.'),
24 24
     'module' => 'CCK',
25
-  );
26
-  return $info;
25
+    );
26
+    return $info;
27 27
 }
28 28
 
29 29
 /**
30 30
  * Action: populate a field.
31 31
  */
32 32
 function content_rules_action_populate_field($node, $settings, $element, &$state) {
33
-  // Get information about the field.
34
-  $field = content_fields($settings['field_name'], $node->type);
35
-  $value = _content_rules_get_field_value($settings, $state);
33
+    // Get information about the field.
34
+    $field = content_fields($settings['field_name'], $node->type);
35
+    $value = _content_rules_get_field_value($settings, $state);
36 36
 
37
-  if (!empty($field) && is_array($value)) {
37
+    if (!empty($field) && is_array($value)) {
38 38
     $node->$settings['field_name'] = $value;
39 39
     return array('node' => $node);
40
-  }
40
+    }
41 41
 }
42 42
 
43 43
 
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
  * This is a multistep form!
47 47
  */
48 48
 function content_rules_action_populate_field_form($settings, &$form, &$form_state) {
49
-  $settings += array('field_name' => '', 'code' => '', 'value' => NULL);
50
-  if (empty($settings['field_name'])) {
49
+    $settings += array('field_name' => '', 'code' => '', 'value' => NULL);
50
+    if (empty($settings['field_name'])) {
51 51
     $form['settings']['field_name'] = array(
52
-      '#type' => 'select',
53
-      '#title' => t('Field'),
54
-      '#options' => content_rules_get_field_names_by_type(),
55
-      '#default_value' => $settings['field_name'],
56
-      '#description' => t('Select the machine-name of the field.'),
57
-      '#required' => TRUE,
52
+        '#type' => 'select',
53
+        '#title' => t('Field'),
54
+        '#options' => content_rules_get_field_names_by_type(),
55
+        '#default_value' => $settings['field_name'],
56
+        '#description' => t('Select the machine-name of the field.'),
57
+        '#required' => TRUE,
58 58
     );
59 59
     // Hide some form elements in the first step.
60 60
     $form['negate']['#access'] = FALSE;
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
     // Replace the usual submit handlers with a own handler.
65 65
     $form['submit']['#submit'] = array('content_rules_action_populate_field_form_step_submit');
66 66
     $form['submit']['#value'] = t('Continue');
67
-  }
68
-  else {
67
+    }
68
+    else {
69 69
     // Show the fields form here.
70 70
     module_load_include('inc', 'content', 'includes/content.node_form');
71 71
     $field = content_fields($settings['field_name']);
@@ -78,111 +78,111 @@  discard block
 block discarded – undo
78 78
 
79 79
     unset($form['#cache']);
80 80
 
81
-      // Advanced: PHP code.
81
+        // Advanced: PHP code.
82 82
     $form['advanced_options'] = array(
83
-      '#type' => 'fieldset',
84
-      '#title' => t('Advanced: Specify the fields value with PHP code'),
85
-      '#collapsible' => TRUE,
86
-      '#collapsed' => empty($settings['code']),
87
-      '#weight' => 5,
83
+        '#type' => 'fieldset',
84
+        '#title' => t('Advanced: Specify the fields value with PHP code'),
85
+        '#collapsible' => TRUE,
86
+        '#collapsed' => empty($settings['code']),
87
+        '#weight' => 5,
88 88
     );
89 89
 
90 90
     $db_info = content_database_info($field);
91 91
     $columns = array_keys($db_info['columns']);
92 92
     foreach ($columns as $key => $column) {
93
-      $columns[$key] = t("'@column' => value for @column", array('@column' => $column));
93
+        $columns[$key] = t("'@column' => value for @column", array('@column' => $column));
94 94
     }
95 95
     $sample = t("return array(\n  0 => array(@columns),\n  // You'll usually want to stop here. Provide more values\n  // if you want your 'default value' to be multi-valued:\n  1 => array(@columns),\n  2 => ...\n);", array('@columns' => implode(', ', $columns)));
96 96
 
97 97
     $form['advanced_options']['code'] = array(
98
-      '#type' => 'textarea',
99
-      '#title' => t('Code'),
100
-      '#default_value' => $settings['code'],
101
-      '#rows' => 6,
102
-      '#description' => t('Advanced usage only: PHP code that returns the value to set. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format: <pre>!sample</pre>Using <a href="@link_devel">devel.module\'s</a> \'devel load\' tab on a content page might help you figure out the expected format.', array(
98
+        '#type' => 'textarea',
99
+        '#title' => t('Code'),
100
+        '#default_value' => $settings['code'],
101
+        '#rows' => 6,
102
+        '#description' => t('Advanced usage only: PHP code that returns the value to set. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format: <pre>!sample</pre>Using <a href="@link_devel">devel.module\'s</a> \'devel load\' tab on a content page might help you figure out the expected format.', array(
103 103
         '!sample' => $sample,
104 104
         '@link_devel' => 'http://www.drupal.org/project/devel',
105
-      )),
105
+        )),
106 106
     );
107 107
 
108 108
     // Add this file to be included when the form is built by rules
109 109
     // as it's needed by CCKs add more button.
110 110
     // See rules_after_build_include_files().
111 111
     $form['#includes'][] = './'. drupal_get_path('module', 'node') .'/node.pages.inc';
112
-  }
112
+    }
113 113
 }
114 114
 
115 115
 function content_rules_action_populate_field_form_step_submit($form, &$form_state) {
116
-  $form_state['element']['#settings']['field_name'] = $form_state['values']['settings']['field_name'];
116
+    $form_state['element']['#settings']['field_name'] = $form_state['values']['settings']['field_name'];
117 117
 }
118 118
 
119 119
 /**
120 120
  * Validate the chosen value or php code.
121 121
  */
122 122
 function content_rules_action_populate_field_validate($form, &$form_state) {
123
-  if (!isset($form_state['element']['#settings']['field_name'])) {
123
+    if (!isset($form_state['element']['#settings']['field_name'])) {
124 124
     //Just validate the last step.
125 125
     return;
126
-  }
126
+    }
127 127
 
128
-  if (isset($form_state['values']['code']) && ($php = $form_state['values']['code'])) {
128
+    if (isset($form_state['values']['code']) && ($php = $form_state['values']['code'])) {
129 129
     if (strpos($php, 'return') === FALSE) {
130
-      form_set_error('code', t('You have to return the default value in the expected format.'));
130
+        form_set_error('code', t('You have to return the default value in the expected format.'));
131 131
     }
132
-  }
133
-  else {
132
+    }
133
+    else {
134 134
     // Validate the field.
135 135
     $settings = $form_state['element']['#settings'];
136 136
     $field = content_fields($settings['field_name']);
137 137
     $field_types = _content_field_types();
138 138
     $function = $field_types[$field['type']]['module'] .'_field';
139 139
     if (function_exists($function)) {
140
-      $form['#node'] = (object)array('type' => '', $settings['field_name'] => $form_state['values'][$settings['field_name']]);
141
-      $items = isset($form['#node']->$field['field_name']) ? $form['#node']->$field['field_name'] : array();
140
+        $form['#node'] = (object)array('type' => '', $settings['field_name'] => $form_state['values'][$settings['field_name']]);
141
+        $items = isset($form['#node']->$field['field_name']) ? $form['#node']->$field['field_name'] : array();
142 142
 
143
-      //Make sure AHAH 'add more' button isn't sent to the fields
144
-      // for processing.
145
-      unset($items[$field['field_name'] .'_add_more']);
143
+        //Make sure AHAH 'add more' button isn't sent to the fields
144
+        // for processing.
145
+        unset($items[$field['field_name'] .'_add_more']);
146 146
 
147
-      $function('validate', $form['#node'], $field, $items, $form, NULL);
148
-      content_field('validate', $form['#node'], $field, $items, $form, NULL);
147
+        $function('validate', $form['#node'], $field, $items, $form, NULL);
148
+        content_field('validate', $form['#node'], $field, $items, $form, NULL);
149
+    }
149 150
     }
150
-  }
151 151
 }
152 152
 
153 153
 function content_rules_action_populate_field_submit(&$settings, $form, &$form_state) {
154
-  // Take over field values and filter out private properties added by CCK
155
-  $settings['value'] = array_filter($form_state['values'][$settings['field_name']], 'is_array');
154
+    // Take over field values and filter out private properties added by CCK
155
+    $settings['value'] = array_filter($form_state['values'][$settings['field_name']], 'is_array');
156 156
 
157
-  foreach ($settings['value'] as $key => $data) {
157
+    foreach ($settings['value'] as $key => $data) {
158 158
     foreach (array_filter(array_keys($data)) as $col) {
159
-      if ($col[0] == '_') {
159
+        if ($col[0] == '_') {
160 160
         unset($settings['value'][$key][$col]);
161
-      }
161
+        }
162 162
     }
163 163
     if ($key && count(array_filter($settings['value'][$key])) == 0) {
164
-      // For multi-valued fields don't check for any additional empty values.
165
-      unset($settings['value'][$key]);
164
+        // For multi-valued fields don't check for any additional empty values.
165
+        unset($settings['value'][$key]);
166
+    }
166 167
     }
167
-  }
168 168
 
169
-  $settings['code'] = $form_state['values']['code'];
169
+    $settings['code'] = $form_state['values']['code'];
170 170
 
171
-  if (function_exists('rules_action_custom_php_submit')) {
171
+    if (function_exists('rules_action_custom_php_submit')) {
172 172
     // Support adding variables to the php code, if php module is present.
173 173
     rules_action_custom_php_submit($settings, $form, $form_state);
174
-  }
174
+    }
175 175
 
176
-  // Add all values to the input evaluator, so that textfields / textares can
177
-  // make use of it.
178
-  $names = array('code');
176
+    // Add all values to the input evaluator, so that textfields / textares can
177
+    // make use of it.
178
+    $names = array('code');
179 179
 
180
-  foreach ($settings['value'] as $key => $data) {
180
+    foreach ($settings['value'] as $key => $data) {
181 181
     foreach (array_filter($data, 'is_string') as $col => $value) {
182
-      $names[] = "value|$key|$col";
182
+        $names[] = "value|$key|$col";
183
+    }
183 184
     }
184
-  }
185
-  $form_state['element']['#info']['eval input'] = $names;
185
+    $form_state['element']['#info']['eval input'] = $names;
186 186
 }
187 187
 
188 188
 
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
  * Label callback: Improve the label of the action.
191 191
  */
192 192
 function content_rules_action_populate_field_label($settings, $argument_labels) {
193
-  return t("Populate @node's field '@field'", array('@field' => $settings['field_name']) + $argument_labels);
193
+    return t("Populate @node's field '@field'", array('@field' => $settings['field_name']) + $argument_labels);
194 194
 }
195 195
 
196 196
 function workflow_ng_action_populate_field_upgrade(&$element) {
197
-  $element['#name'] = 'content_rules_action_populate_field';
198
-  $element['#settings']['code'] = $element['#settings']['default_value_php'];
199
-  $element['#settings'][$element['#settings']['field_name']] = array();
200
-  unset($element['#settings']['default_value_php']);
197
+    $element['#name'] = 'content_rules_action_populate_field';
198
+    $element['#settings']['code'] = $element['#settings']['default_value_php'];
199
+    $element['#settings'][$element['#settings']['field_name']] = array();
200
+    unset($element['#settings']['default_value_php']);
201 201
 }
202 202
 
203 203
 
@@ -205,84 +205,84 @@  discard block
 block discarded – undo
205 205
  * Implementation of hook_rules_condition_info().
206 206
  */
207 207
 function content_rules_condition_info() {
208
-  $info = array();
209
-  $info['content_rules_field_has_value'] = array(
208
+    $info = array();
209
+    $info['content_rules_field_has_value'] = array(
210 210
     'label' => t('Field has value'),
211 211
     'arguments' => array(
212
-      'node' => array('type' => 'node', 'label' => t('Content')),
212
+        'node' => array('type' => 'node', 'label' => t('Content')),
213 213
     ),
214 214
     'eval input' => array('code'),
215 215
     'help' => t('You should make sure that the used field exists in the given content type. The condition returns TRUE, if the selected field has the given value.'),
216 216
     'module' => 'CCK',
217
-  );
218
-  $info['content_rules_field_changed'] = array(
217
+    );
218
+    $info['content_rules_field_changed'] = array(
219 219
     'label' => t('Field has changed'),
220 220
     'arguments' => array(
221
-      'node' => array('type' => 'node', 'label' => t('Content containing changes')),
222
-      'node_unchanged' => array('type' => 'node', 'label' => t('Content not containing changes')),
221
+        'node' => array('type' => 'node', 'label' => t('Content containing changes')),
222
+        'node_unchanged' => array('type' => 'node', 'label' => t('Content not containing changes')),
223 223
     ),
224 224
     'help' => t('You should make sure that the used field exists in the given content type.'),
225 225
     'module' => 'CCK',
226
-  );
227
-  return $info;
226
+    );
227
+    return $info;
228 228
 }
229 229
 
230 230
 /**
231 231
  * Condition: Check the value of a field.
232 232
  */
233 233
 function content_rules_field_has_value($node, $settings) {
234
-  // Get information about the field.
235
-  $field = content_fields($settings['field_name'], $node->type);
236
-  $value = _content_rules_get_field_value($settings, $state);
234
+    // Get information about the field.
235
+    $field = content_fields($settings['field_name'], $node->type);
236
+    $value = _content_rules_get_field_value($settings, $state);
237 237
 
238
-  if (empty($field) || !is_array($value)) {
238
+    if (empty($field) || !is_array($value)) {
239 239
     return FALSE;
240
-  }
240
+    }
241 241
 
242
-  return _content_rules_field_has_value($node->$settings['field_name'], $value);
242
+    return _content_rules_field_has_value($node->$settings['field_name'], $value);
243 243
 }
244 244
 
245 245
 /**
246 246
  * Use the same configuration form as the "populate field" action.
247 247
  */
248 248
 function content_rules_field_has_value_form($settings, &$form, &$form_state) {
249
-  content_rules_action_populate_field_form($settings, $form, $form_state);
249
+    content_rules_action_populate_field_form($settings, $form, $form_state);
250 250
 }
251 251
 function content_rules_field_has_value_validate($form, &$form_state) {
252
-  content_rules_action_populate_field_validate($form, $form_state);
252
+    content_rules_action_populate_field_validate($form, $form_state);
253 253
 }
254 254
 function content_rules_field_has_value_submit(&$settings, $form, &$form_state) {
255
-  content_rules_action_populate_field_submit($settings, $form, $form_state);
255
+    content_rules_action_populate_field_submit($settings, $form, $form_state);
256 256
 }
257 257
 
258 258
 function content_rules_field_has_value_label($settings, $argument_labels) {
259
-  return t("@node's field '@field' has value", array('@field' => $settings['field_name']) + $argument_labels);
259
+    return t("@node's field '@field' has value", array('@field' => $settings['field_name']) + $argument_labels);
260 260
 }
261 261
 
262 262
 /**
263 263
  * Condition: Check if the field has changed.
264 264
  */
265 265
 function content_rules_field_changed($node1, $node2, $settings) {
266
-  // Get information about the field.
267
-  $field = content_fields($settings['field_name'], $node1->type);
266
+    // Get information about the field.
267
+    $field = content_fields($settings['field_name'], $node1->type);
268 268
 
269
-  return !empty($field) && !_content_rules_field_has_value($node1->$settings['field_name'], $node2->$settings['field_name']);
269
+    return !empty($field) && !_content_rules_field_has_value($node1->$settings['field_name'], $node2->$settings['field_name']);
270 270
 }
271 271
 
272 272
 function content_rules_field_changed_form($settings, &$form, &$form_state) {
273
-  $settings += array('field_name' => '');
274
-  $form['settings']['field_name'] = array(
273
+    $settings += array('field_name' => '');
274
+    $form['settings']['field_name'] = array(
275 275
     '#type' => 'select',
276 276
     '#title' => t('Field'),
277 277
     '#options' => content_rules_get_field_names_by_type(),
278 278
     '#default_value' => $settings['field_name'],
279 279
     '#description' => t('Select the machine-name of the field to look at.'),
280 280
     '#required' => TRUE,
281
-  );
281
+    );
282 282
 }
283 283
 
284 284
 function content_rules_field_changed_label($settings, $argument_labels) {
285
-  return t("@node's field '@field' has been changed", array('@field' => $settings['field_name']) + $argument_labels);
285
+    return t("@node's field '@field' has been changed", array('@field' => $settings['field_name']) + $argument_labels);
286 286
 }
287 287
 
288 288
 
@@ -291,32 +291,32 @@  discard block
 block discarded – undo
291 291
  * Suitable for using it with #options.
292 292
  */
293 293
 function content_rules_get_field_names_by_type($type = NULL) {
294
-  $fields = array();
295
-  foreach (content_fields() as $field) {
294
+    $fields = array();
295
+    foreach (content_fields() as $field) {
296 296
     if (!isset($type) || $field['type'] == $type) {
297
-      $fields[$field['field_name']] = $field['field_name'];
297
+        $fields[$field['field_name']] = $field['field_name'];
298
+    }
298 299
     }
299
-  }
300
-  asort($fields);
301
-  return $fields;
300
+    asort($fields);
301
+    return $fields;
302 302
 }
303 303
 
304 304
 function _content_rules_get_field_value($settings, &$state) {
305
-  if ($settings['code']) {
305
+    if ($settings['code']) {
306 306
     if (function_exists('rules_input_evaluator_php_apply')) {
307
-      // Support adding variables to the php code, if php module is present.
308
-      $value = rules_input_evaluator_php_apply($settings['code'], $settings['vars'], $state, FALSE);
307
+        // Support adding variables to the php code, if php module is present.
308
+        $value = rules_input_evaluator_php_apply($settings['code'], $settings['vars'], $state, FALSE);
309 309
     }
310 310
     else {
311
-      ob_start();
312
-      $value = eval($settings['code']);
313
-      ob_end_clean();
311
+        ob_start();
312
+        $value = eval($settings['code']);
313
+        ob_end_clean();
314 314
     }
315
-  }
316
-  else {
315
+    }
316
+    else {
317 317
     $value = $settings['value'];
318
-  }
319
-  return $value;
318
+    }
319
+    return $value;
320 320
 }
321 321
 
322 322
 /**
@@ -329,20 +329,20 @@  discard block
 block discarded – undo
329 329
  * @param $value The value to check for.
330 330
  */
331 331
 function _content_rules_field_has_value($node_value, $value) {
332
-  if (count($value) != count($node_value)) {
332
+    if (count($value) != count($node_value)) {
333 333
     return FALSE;
334
-  }
335
-  // Loop over multiple fields
336
-  foreach ($value as $delta => $sub_value) {
334
+    }
335
+    // Loop over multiple fields
336
+    foreach ($value as $delta => $sub_value) {
337 337
     // Check if all properties of the value are there in the node value too
338 338
     if (is_array($sub_value) && is_array($node_value[$delta])) {
339
-      if (count(array_diff_assoc($sub_value, $node_value[$delta])) != 0) {
339
+        if (count(array_diff_assoc($sub_value, $node_value[$delta])) != 0) {
340 340
         return FALSE;
341
-      }
341
+        }
342 342
     }
343 343
     elseif ($sub_value !== $node_value[$delta]) {
344
-      return FALSE;
344
+        return FALSE;
345
+    }
345 346
     }
346
-  }
347
-  return TRUE;
347
+    return TRUE;
348 348
 }
Please login to merge, or discard this patch.
contrib/cck/modules/fieldgroup/panels/content_types/content_fieldgroup.inc 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -10,155 +10,155 @@
 block discarded – undo
10 10
  * Callback function to supply a list of content types.
11 11
  */
12 12
 function fieldgroup_content_fieldgroup_ctools_content_types() {
13
-  return array(
13
+    return array(
14 14
     'title' => t('Content fieldgroup'),
15 15
     'defaults' => array('label' => 'hidden', 'format' => 'simple', 'empty' => ''),
16
-  );
16
+    );
17 17
 }
18 18
 
19 19
 /**
20 20
  * Return all fieldgroup content types available.
21 21
  */
22 22
 function fieldgroup_content_fieldgroup_content_type_content_types() {
23
-  // This will hold all the individual fieldgroup content types.
24
-  $types = array();
23
+    // This will hold all the individual fieldgroup content types.
24
+    $types = array();
25 25
 
26
-  // The outer loop goes through each node type with groups.
27
-  foreach (fieldgroup_groups() as $node_type_groups) {
26
+    // The outer loop goes through each node type with groups.
27
+    foreach (fieldgroup_groups() as $node_type_groups) {
28 28
     // The inner loop gives us each fieldgroup on each node type with groups.
29 29
     foreach ($node_type_groups as $group) {
30
-      // Skip field groups that are not of standard type.
31
-      if ($group['group_type'] != 'standard') {
30
+        // Skip field groups that are not of standard type.
31
+        if ($group['group_type'] != 'standard') {
32 32
         continue;
33
-      }
33
+        }
34 34
 
35
-      // Name the content type a combination of fieldgroup and node type names.
36
-      $content_type_name = $group['type_name'] . ':' . $group['group_name'];
35
+        // Name the content type a combination of fieldgroup and node type names.
36
+        $content_type_name = $group['type_name'] . ':' . $group['group_name'];
37 37
 
38
-      // Assemble the information about the content type.
39
-      $info = array(
38
+        // Assemble the information about the content type.
39
+        $info = array(
40 40
         'category' => t('Node'),
41 41
         'icon' => 'icon_cck_field_group.png',
42 42
         'title' => t('Field group: @group in @type', array(
43
-          '@group' => t($group['label']),
44
-          '@type' => node_get_types('name', $group['type_name']),
43
+            '@group' => t($group['label']),
44
+            '@type' => node_get_types('name', $group['type_name']),
45 45
         )),
46 46
         'description' => t('All fields from this field group on the referenced node.'),
47 47
         'required context' => new ctools_context_required(t('Node'), 'node', array('type' => array($group['type_name']))),
48
-      );
48
+        );
49 49
 
50
-      $types[$content_type_name] = $info;
50
+        $types[$content_type_name] = $info;
51
+    }
51 52
     }
52
-  }
53 53
 
54
-  return $types;
54
+    return $types;
55 55
 }
56 56
 
57 57
 /**
58 58
  * Output function for the 'fieldgroup' content type.
59 59
  */
60 60
 function fieldgroup_content_fieldgroup_content_type_render($subtype, $conf, $panel_args, $context) {
61
-  if (!isset($context->data)) {
61
+    if (!isset($context->data)) {
62 62
     return;
63
-  }
64
-  $node = drupal_clone($context->data);
63
+    }
64
+    $node = drupal_clone($context->data);
65 65
 
66
-  // Make sure old data doesn't cause problems:
67
-  if (empty($conf['label'])) {
66
+    // Make sure old data doesn't cause problems:
67
+    if (empty($conf['label'])) {
68 68
     $conf['label'] = 'hidden';
69
-  }
70
-  if (empty($conf['format'])) {
69
+    }
70
+    if (empty($conf['format'])) {
71 71
     $conf['format'] = 'simple';
72
-  }
72
+    }
73 73
 
74
-  // Extract the node type and fieldgroup name from the subtype.
75
-  list($node_type, $group_name) = explode(':', $subtype, 2);
74
+    // Extract the node type and fieldgroup name from the subtype.
75
+    list($node_type, $group_name) = explode(':', $subtype, 2);
76 76
 
77
-  // Get a list of all fieldgroups for this node type.
78
-  $groups = fieldgroup_groups($node_type);
77
+    // Get a list of all fieldgroups for this node type.
78
+    $groups = fieldgroup_groups($node_type);
79 79
 
80
-  if (!isset($groups[$group_name])) {
80
+    if (!isset($groups[$group_name])) {
81 81
     return;
82
-  }
83
-  $group = $groups[$group_name];
84
-
85
-  // Render the field group.
86
-  $node->build_mode = NODE_BUILD_NORMAL;
87
-  $group['settings']['display']['label'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label'];
88
-  $group['settings']['display']['full']['format'] = $conf['format'];
89
-  $group['settings']['display']['full']['exclude'] = 0;
90
-  $output = fieldgroup_view_group($group, $node);
91
-
92
-  $block = new stdClass();
93
-  if ($conf['label'] == 'normal') {
82
+    }
83
+    $group = $groups[$group_name];
84
+
85
+    // Render the field group.
86
+    $node->build_mode = NODE_BUILD_NORMAL;
87
+    $group['settings']['display']['label'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label'];
88
+    $group['settings']['display']['full']['format'] = $conf['format'];
89
+    $group['settings']['display']['full']['exclude'] = 0;
90
+    $output = fieldgroup_view_group($group, $node);
91
+
92
+    $block = new stdClass();
93
+    if ($conf['label'] == 'normal') {
94 94
     $block->title = t($group['label']);
95
-  }
96
-  $block->content = !empty($output) ? $output : $conf['empty'];
97
-  return $block;
95
+    }
96
+    $block->content = !empty($output) ? $output : $conf['empty'];
97
+    return $block;
98 98
 }
99 99
 
100 100
 /**
101 101
  * Returns a settings form for the custom type.
102 102
  */
103 103
 function fieldgroup_content_fieldgroup_content_type_edit_form(&$form, &$form_state) {
104
-  $conf = $form_state['conf'];
104
+    $conf = $form_state['conf'];
105 105
 
106
-  $label_options = array(
106
+    $label_options = array(
107 107
     'normal' => t('Block title'),
108 108
     'above' => t('Above'),
109
-  );
110
-  $form['label'] = array(
109
+    );
110
+    $form['label'] = array(
111 111
     '#type' => 'select',
112 112
     '#title' => t('Field group label'),
113 113
     '#default_value' => !empty($conf['label']) && isset($label_options[$conf['label']]) ? $conf['label'] : 'hidden',
114 114
     '#options' => $label_options,
115 115
     '#description' => t('Configure how the field group label is going to be displayed. This option takes no effect when "Override title" option is enabled, the specified block title is displayed instead.'),
116
-  );
116
+    );
117 117
 
118
-  $format_options = array(
118
+    $format_options = array(
119 119
     'simple' => t('Simple'),
120 120
     'fieldset' => t('Fieldset'),
121 121
     'fieldset_collapsible' => t('Fieldset - Collapsible'),
122 122
     'fieldset_collapsed' => t('Fieldset - Collapsed'),
123
-  );
124
-  $form['format'] = array(
123
+    );
124
+    $form['format'] = array(
125 125
     '#type' => 'select',
126 126
     '#title' => t('Field group format'),
127 127
     '#default_value' => !empty($conf['format']) && isset($format_options[$conf['format']]) ? $conf['format'] : 'simple',
128 128
     '#options' => $format_options,
129 129
     '#description' => t('This option allows you to configure the field group format.'),
130
-  );
130
+    );
131 131
 
132
-  $form['empty'] = array(
132
+    $form['empty'] = array(
133 133
     '#type' => 'textarea',
134 134
     '#title' => t('Empty text'),
135 135
     '#description' => t('Text to display if group has no data. Note that title will not display unless overridden.'),
136 136
     '#rows' => 5,
137 137
     '#default_value' => $conf['empty'],
138
-  );
138
+    );
139 139
 }
140 140
 
141 141
 function fieldgroup_content_fieldgroup_content_type_edit_form_submit(&$form, &$form_state) {
142
-  // Copy everything from our defaults.
143
-  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
142
+    // Copy everything from our defaults.
143
+    foreach (array_keys($form_state['plugin']['defaults']) as $key) {
144 144
     $form_state['conf'][$key] = $form_state['values'][$key];
145
-  }
145
+    }
146 146
 }
147 147
 
148 148
 /**
149 149
  * Admin title for fieldgroup content type.
150 150
  */
151 151
 function fieldgroup_content_fieldgroup_content_type_admin_title($subtype, $conf, $context) {
152
-  // Extract the node type and fieldgroup name from the subtype.
153
-  list($node_type, $group_name) = explode(':', $subtype, 2);
152
+    // Extract the node type and fieldgroup name from the subtype.
153
+    list($node_type, $group_name) = explode(':', $subtype, 2);
154 154
 
155
-  // Get information about this field group for this node type.
156
-  $groups = fieldgroup_groups($node_type);
157
-  $group = $groups[$group_name];
155
+    // Get information about this field group for this node type.
156
+    $groups = fieldgroup_groups($node_type);
157
+    $group = $groups[$group_name];
158 158
 
159
-  return t('"@s" field group: @group in @type', array(
159
+    return t('"@s" field group: @group in @type', array(
160 160
     '@s' => $context->identifier,
161 161
     '@group' => t($group['label']),
162 162
     '@type' => node_get_types('name', $node_type),
163
-  ));
163
+    ));
164 164
 }
Please login to merge, or discard this patch.
default/boinc/modules/contrib/cck/modules/fieldgroup/fieldgroup.module 1 patch
Indentation   +366 added lines, -366 removed lines patch added patch discarded remove patch
@@ -16,230 +16,230 @@  discard block
 block discarded – undo
16 16
  * Implementation of hook_init().
17 17
  */
18 18
 function fieldgroup_init() {
19
-  drupal_add_css(drupal_get_path('module', 'fieldgroup') .'/fieldgroup.css');
19
+    drupal_add_css(drupal_get_path('module', 'fieldgroup') .'/fieldgroup.css');
20 20
 }
21 21
 
22 22
 /**
23 23
  * Implementation of hook_ctools_plugin_directory().
24 24
  */
25 25
 function fieldgroup_ctools_plugin_directory($module, $plugin) {
26
-  if ($module == 'ctools' && $plugin == 'content_types') {
26
+    if ($module == 'ctools' && $plugin == 'content_types') {
27 27
     return 'panels/' . $plugin;
28
-  }
28
+    }
29 29
 }
30 30
 
31 31
 /**
32 32
  * Implementation of hook_menu().
33 33
  */
34 34
 function fieldgroup_menu() {
35
-  $items = array();
35
+    $items = array();
36 36
 
37
-  // Make sure this doesn't fire until content_types is working,
38
-  // needed to avoid errors on initial installation.
39
-  if (!defined('MAINTENANCE_MODE')) {
37
+    // Make sure this doesn't fire until content_types is working,
38
+    // needed to avoid errors on initial installation.
39
+    if (!defined('MAINTENANCE_MODE')) {
40 40
     foreach (node_get_types() as $type) {
41
-      $type_name = $type->type;
42
-      $content_type = content_types($type_name);
43
-      $type_url_str = $content_type['url_str'];
44
-      $items['admin/content/node-type/'. $type_url_str .'/groups/%'] = array(
41
+        $type_name = $type->type;
42
+        $content_type = content_types($type_name);
43
+        $type_url_str = $content_type['url_str'];
44
+        $items['admin/content/node-type/'. $type_url_str .'/groups/%'] = array(
45 45
         'title' => 'Edit group',
46 46
         'page callback' => 'drupal_get_form',
47 47
         'page arguments' => array('fieldgroup_group_edit_form', $type_name, 5),
48 48
         'access arguments' => array('administer content types'),
49 49
         'type' => MENU_CALLBACK,
50
-      );
51
-      $items['admin/content/node-type/'. $type_url_str .'/groups/%/remove'] = array(
50
+        );
51
+        $items['admin/content/node-type/'. $type_url_str .'/groups/%/remove'] = array(
52 52
         'title' => 'Edit group',
53 53
         'page callback' => 'drupal_get_form',
54 54
         'page arguments' => array('fieldgroup_remove_group', $type_name, 5),
55 55
         'access arguments' => array('administer content types'),
56 56
         'type' => MENU_CALLBACK,
57
-      );
57
+        );
58 58
     }
59
-  }
60
-  return $items;
59
+    }
60
+    return $items;
61 61
 }
62 62
 
63 63
 /**
64 64
  * Implementation of hook_theme().
65 65
  */
66 66
 function fieldgroup_theme() {
67
-  return array(
67
+    return array(
68 68
     'fieldgroup_simple' => array(
69
-      'template' => 'fieldgroup-simple',
70
-      'arguments' => array('element' => NULL),
69
+        'template' => 'fieldgroup-simple',
70
+        'arguments' => array('element' => NULL),
71 71
     ),
72 72
     'fieldgroup_fieldset' => array(
73
-      'arguments' => array('element' => NULL),
73
+        'arguments' => array('element' => NULL),
74 74
     ),
75 75
     'fieldgroup_display_overview_form' => array(
76
-      'arguments' => array('form' => NULL),
76
+        'arguments' => array('form' => NULL),
77 77
     ),
78
-  );
78
+    );
79 79
 }
80 80
 
81 81
 /**
82 82
  * Implementation of hook_elements().
83 83
  */
84 84
 function fieldgroup_elements() {
85
-  return array(
85
+    return array(
86 86
     'fieldgroup_simple' => array(),
87 87
     'fieldgroup_fieldset' => array('#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL,),
88
-  );
88
+    );
89 89
 }
90 90
 
91 91
 /**
92 92
  * Implementation of hook_fieldapi().
93 93
  */
94 94
 function fieldgroup_content_fieldapi($op, $field) {
95
-  switch ($op) {
95
+    switch ($op) {
96 96
     case 'delete instance':
97 97
       db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']);
98
-      cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
99
-      break;
100
-  }
98
+        cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
99
+        break;
100
+    }
101 101
 }
102 102
 
103 103
 function fieldgroup_group_edit_form(&$form_state, $type_name, $group_name) {
104
-  $content_type = content_types($type_name);
105
-  $groups = fieldgroup_groups($content_type['type']);
104
+    $content_type = content_types($type_name);
105
+    $groups = fieldgroup_groups($content_type['type']);
106 106
 
107
-  if (!$group = $groups[$group_name]) {
107
+    if (!$group = $groups[$group_name]) {
108 108
     drupal_not_found();
109 109
     exit;
110
-  }
110
+    }
111 111
 
112
-  $form['label'] = array(
112
+    $form['label'] = array(
113 113
     '#type' => 'textfield',
114 114
     '#title' => t('Label'),
115 115
     '#default_value' => $group['label'],
116 116
     '#required' => TRUE,
117
-  );
117
+    );
118 118
 
119
-  // Set a default value for group type early in the form so it
120
-  // can be overridden by subsequent form elements added by other modules.
121
-  $group_type = !empty($group['group_type']) ? $group['group_type'] : 'standard';
122
-  $form['group_type'] = array('#type' => 'hidden', '#default_value' => $group_type);
119
+    // Set a default value for group type early in the form so it
120
+    // can be overridden by subsequent form elements added by other modules.
121
+    $group_type = !empty($group['group_type']) ? $group['group_type'] : 'standard';
122
+    $form['group_type'] = array('#type' => 'hidden', '#default_value' => $group_type);
123 123
 
124
-  $form['settings']['#tree'] = TRUE;
125
-  $form['settings']['form'] = array(
124
+    $form['settings']['#tree'] = TRUE;
125
+    $form['settings']['form'] = array(
126 126
     '#type' => 'fieldset',
127 127
     '#title' => t('Form settings'),
128 128
     '#description' => t('These settings apply to the group in the node editing form.'),
129
-  );
130
-  $form['settings']['form']['style'] = array(
129
+    );
130
+    $form['settings']['form']['style'] = array(
131 131
     '#type' => 'radios',
132 132
     '#title' => t('Style'),
133 133
     '#default_value' => $group['settings']['form']['style'],
134 134
     '#options' => array(
135
-      'fieldset' => t('always open'),
136
-      'fieldset_collapsible' => t('collapsible'),
137
-      'fieldset_collapsed' => t('collapsed'),
135
+        'fieldset' => t('always open'),
136
+        'fieldset_collapsible' => t('collapsible'),
137
+        'fieldset_collapsed' => t('collapsed'),
138 138
     )
139
-  );
140
-  $form['settings']['form']['description'] = array(
139
+    );
140
+    $form['settings']['form']['description'] = array(
141 141
     '#type' => 'textarea',
142 142
     '#title' => t('Help text'),
143 143
     '#default_value' => $group['settings']['form']['description'],
144 144
     '#rows' => 5,
145 145
     '#description' => t('Instructions to present to the user on the editing form.'),
146 146
     '#required' => FALSE,
147
-  );
148
-  $form['settings']['display'] = array(
147
+    );
148
+    $form['settings']['display'] = array(
149 149
     '#type' => 'fieldset',
150 150
     '#title' => t('Display settings'),
151 151
     '#description' => t('These settings apply to the group on node display.'),
152
-  );
153
-  $form['settings']['display']['description'] = array(
152
+    );
153
+    $form['settings']['display']['description'] = array(
154 154
     '#type' => 'textarea',
155 155
     '#title' => t('Description'),
156 156
     '#default_value' => $group['settings']['display']['description'],
157 157
     '#rows' => 5,
158 158
     '#description' => t('A description of the group.'),
159 159
     '#required' => FALSE,
160
-  );
160
+    );
161 161
 
162
-  foreach (array_keys(content_build_modes()) as $key) {
162
+    foreach (array_keys(content_build_modes()) as $key) {
163 163
     $form['settings']['display'][$key]['format'] = array('#type' => 'value', '#value' => isset($group['settings']['display'][$key]['format']) ? $group['settings']['display'][$key]['format'] : 'fieldset');
164 164
     $form['settings']['display'][$key]['exclude'] = array('#type' => 'value', '#value' => isset($group['settings']['display'][$key]['exclude']) ? $group['settings']['display'][$key]['exclude'] : 0);
165
-  }
166
-  $form['settings']['display']['label'] = array('#type' => 'value', '#value' => $group['settings']['display']['label']);
167
-  $form['weight'] = array('#type' => 'hidden', '#default_value' => $group['weight']);
168
-  $form['group_name'] = array('#type' => 'hidden', '#default_value' => $group_name);
165
+    }
166
+    $form['settings']['display']['label'] = array('#type' => 'value', '#value' => $group['settings']['display']['label']);
167
+    $form['weight'] = array('#type' => 'hidden', '#default_value' => $group['weight']);
168
+    $form['group_name'] = array('#type' => 'hidden', '#default_value' => $group_name);
169 169
 
170
-  $form['#content_type'] = $content_type;
170
+    $form['#content_type'] = $content_type;
171 171
 
172
-  $form['submit'] = array(
172
+    $form['submit'] = array(
173 173
     '#type' => 'submit',
174 174
     '#value' => t('Save'),
175 175
     '#weight' => 10,
176
-  );
176
+    );
177 177
 
178
-  return $form;
178
+    return $form;
179 179
 }
180 180
 
181 181
 function fieldgroup_group_edit_form_submit($form, &$form_state) {
182
-  $form_values = $form_state['values'];
183
-  $content_type = $form['#content_type'];
184
-  fieldgroup_save_group($content_type['type'], $form_values);
185
-  $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields';
182
+    $form_values = $form_state['values'];
183
+    $content_type = $form['#content_type'];
184
+    fieldgroup_save_group($content_type['type'], $form_values);
185
+    $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields';
186 186
 }
187 187
 
188 188
 function fieldgroup_remove_group(&$form_state, $type_name, $group_name) {
189
-  $content_type = content_types($type_name);
190
-  $groups = fieldgroup_groups($content_type['type']);
191
-  $group = isset($groups[$group_name]) ? $groups[$group_name] : '';
189
+    $content_type = content_types($type_name);
190
+    $groups = fieldgroup_groups($content_type['type']);
191
+    $group = isset($groups[$group_name]) ? $groups[$group_name] : '';
192 192
 
193
-  if (empty($group)) {
193
+    if (empty($group)) {
194 194
     drupal_not_found();
195 195
     exit;
196
-  }
196
+    }
197 197
 
198
-  $form['#submit'][] = 'fieldgroup_remove_group_submit';
199
-  $form['#content_type'] = $content_type;
200
-  $form['#group_name'] = $group_name;
198
+    $form['#submit'][] = 'fieldgroup_remove_group_submit';
199
+    $form['#content_type'] = $content_type;
200
+    $form['#group_name'] = $group_name;
201 201
 
202
-  return confirm_form($form,
203
-                  t('Are you sure you want to remove the group %label?',
204
-                  array('%label' => t($group['label']))),
205
-                  'admin/content/node-type/'. $content_type['url_str'] .'/fields', t('This action cannot be undone.'),
206
-                  t('Remove'), t('Cancel'));
202
+    return confirm_form($form,
203
+                    t('Are you sure you want to remove the group %label?',
204
+                    array('%label' => t($group['label']))),
205
+                    'admin/content/node-type/'. $content_type['url_str'] .'/fields', t('This action cannot be undone.'),
206
+                    t('Remove'), t('Cancel'));
207 207
 }
208 208
 
209 209
 function fieldgroup_remove_group_submit($form, &$form_state) {
210
-  $form_values = $form_state['values'];
211
-  $content_type = $form['#content_type'];
212
-  $group_name = $form['#group_name'];
213
-  fieldgroup_delete($content_type['type'], $group_name);
214
-  drupal_set_message(t('The group %group_name has been removed.', array('%group_name' => $group_name)));
215
-  $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields';
210
+    $form_values = $form_state['values'];
211
+    $content_type = $form['#content_type'];
212
+    $group_name = $form['#group_name'];
213
+    fieldgroup_delete($content_type['type'], $group_name);
214
+    drupal_set_message(t('The group %group_name has been removed.', array('%group_name' => $group_name)));
215
+    $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields';
216 216
 }
217 217
 
218 218
 /**
219 219
  * Returns all groups for a content type
220 220
  */
221 221
 function fieldgroup_groups($content_type = '', $sorted = FALSE, $reset = FALSE) {
222
-  global $language;
223
-  static $groups, $groups_sorted;
224
-  if (!isset($groups) || $reset) {
222
+    global $language;
223
+    static $groups, $groups_sorted;
224
+    if (!isset($groups) || $reset) {
225 225
     if ($cached = cache_get('fieldgroup_data:'. $language->language, content_cache_tablename())) {
226
-      $data = $cached->data;
227
-      $groups = $data['groups'];
228
-      $groups_sorted = $data['groups_sorted'];
226
+        $data = $cached->data;
227
+        $groups = $data['groups'];
228
+        $groups_sorted = $data['groups_sorted'];
229 229
     }
230 230
     else {
231
-      $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name");
232
-      $groups = array();
233
-      $groups_sorted = array();
234
-      while ($group = db_fetch_array($result)) {
231
+        $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name");
232
+        $groups = array();
233
+        $groups_sorted = array();
234
+        while ($group = db_fetch_array($result)) {
235 235
         $group['settings'] = unserialize($group['settings']);
236 236
         $group['fields'] = array();
237 237
 
238 238
         // Allow external modules to translate field group strings.
239 239
         $group_strings = array(
240
-          'label' => $group['label'],
241
-          'form_description' => $group['settings']['form']['description'],
242
-          'display_description' => $group['settings']['display']['description'],
240
+            'label' => $group['label'],
241
+            'form_description' => $group['settings']['form']['description'],
242
+            'display_description' => $group['settings']['display']['description'],
243 243
         );
244 244
         drupal_alter('content_fieldgroup_strings', $group_strings, $group['type_name'], $group['group_name']);
245 245
         $group['label'] = $group_strings['label'];
@@ -248,58 +248,58 @@  discard block
 block discarded – undo
248 248
 
249 249
         $groups[$group['type_name']][$group['group_name']] = $group;
250 250
         $groups_sorted[$group['type_name']][] = &$groups[$group['type_name']][$group['group_name']];
251
-      }
252
-      //load fields
253
-      $result = db_query("SELECT nfi.*, ng.group_name FROM {". fieldgroup_tablename() ."} ng ".
254
- "INNER JOIN {". fieldgroup_fields_tablename() ."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ".
255
- "INNER JOIN {". content_instance_tablename() ."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ".
256
- "WHERE nfi.widget_active = 1 ORDER BY nfi.weight");
257
-      while ($field = db_fetch_array($result)) {
251
+        }
252
+        //load fields
253
+        $result = db_query("SELECT nfi.*, ng.group_name FROM {". fieldgroup_tablename() ."} ng ".
254
+    "INNER JOIN {". fieldgroup_fields_tablename() ."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ".
255
+    "INNER JOIN {". content_instance_tablename() ."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ".
256
+    "WHERE nfi.widget_active = 1 ORDER BY nfi.weight");
257
+        while ($field = db_fetch_array($result)) {
258 258
         // Allow external modules to translate field strings.
259 259
         $field_strings = array(
260
-          'widget_label' => $field['label'],
261
-          'widget_description' => $field['description'],
260
+            'widget_label' => $field['label'],
261
+            'widget_description' => $field['description'],
262 262
         );
263 263
         drupal_alter('content_field_strings', $field_strings, $field['type_name'], $field['field_name']);
264 264
         $field['label'] = $field_strings['widget_label'];
265 265
         $field['description'] = $field_strings['widget_description'];
266 266
 
267 267
         $groups[$field['type_name']][$field['group_name']]['fields'][$field['field_name']] = $field;
268
-      }
269
-      cache_set('fieldgroup_data:'. $language->language, array('groups' => $groups, 'groups_sorted' => $groups_sorted), content_cache_tablename());
268
+        }
269
+        cache_set('fieldgroup_data:'. $language->language, array('groups' => $groups, 'groups_sorted' => $groups_sorted), content_cache_tablename());
270
+    }
270 271
     }
271
-  }
272
-  if (empty($content_type)) {
272
+    if (empty($content_type)) {
273 273
     return $groups;
274
-  }
275
-  elseif (empty($groups) || empty($groups[$content_type])) {
274
+    }
275
+    elseif (empty($groups) || empty($groups[$content_type])) {
276 276
     return array();
277
-  }
278
-  return $sorted ? $groups_sorted[$content_type] : $groups[$content_type];
277
+    }
278
+    return $sorted ? $groups_sorted[$content_type] : $groups[$content_type];
279 279
 }
280 280
 
281 281
 
282 282
 function _fieldgroup_groups_label($content_type) {
283
-  $groups = fieldgroup_groups($content_type);
283
+    $groups = fieldgroup_groups($content_type);
284 284
 
285
-  $labels[''] = '<'. t('none') .'>';
286
-  foreach ($groups as $group_name => $group) {
285
+    $labels[''] = '<'. t('none') .'>';
286
+    foreach ($groups as $group_name => $group) {
287 287
     $labels[$group_name] = t($group['label']);
288
-  }
289
-  return $labels;
288
+    }
289
+    return $labels;
290 290
 }
291 291
 
292 292
 function _fieldgroup_field_get_group($content_type, $field_name) {
293
-  return db_result(db_query("SELECT group_name FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name));
293
+    return db_result(db_query("SELECT group_name FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name));
294 294
 }
295 295
 
296 296
 /**
297 297
  * Implementation of hook_form_alter()
298 298
  */
299 299
 function fieldgroup_form_alter(&$form, $form_state, $form_id) {
300
-  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
300
+    if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
301 301
     foreach (fieldgroup_groups($form['type']['#value']) as $group_name => $group) {
302
-      $form[$group_name] = array(
302
+        $form[$group_name] = array(
303 303
         '#type' => 'fieldset',
304 304
         '#title' => check_plain(t($group['label'])),
305 305
         '#collapsed' => $group['settings']['form']['style'] == 'fieldset_collapsed',
@@ -307,62 +307,62 @@  discard block
 block discarded – undo
307 307
         '#weight' => $group['weight'],
308 308
         '#description' => content_filter_xss(t($group['settings']['form']['description'])),
309 309
         '#attributes' => array('class' => strtr($group['group_name'], '_', '-')),
310
-      );
310
+        );
311 311
 
312
-      $has_accessible_field = FALSE;
313
-      foreach ($group['fields'] as $field_name => $field) {
312
+        $has_accessible_field = FALSE;
313
+        foreach ($group['fields'] as $field_name => $field) {
314 314
         if (isset($form[$field_name])) {
315
-          $form[$group_name][$field_name] = $form[$field_name];
316
-          // Track whether this group has any accessible fields within it.
317
-          if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== FALSE) {
315
+            $form[$group_name][$field_name] = $form[$field_name];
316
+            // Track whether this group has any accessible fields within it.
317
+            if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== FALSE) {
318 318
             $has_accessible_field = TRUE;
319
-          }
320
-          unset($form[$field_name]);
319
+            }
320
+            unset($form[$field_name]);
321
+        }
321 322
         }
322
-      }
323
-      if (!empty($group['fields']) && !element_children($form[$group_name])) {
323
+        if (!empty($group['fields']) && !element_children($form[$group_name])) {
324 324
         //hide the fieldgroup, because the fields are hidden too
325 325
         unset($form[$group_name]);
326
-      }
326
+        }
327 327
 
328
-      if (!$has_accessible_field) {
328
+        if (!$has_accessible_field) {
329 329
         // Hide the fieldgroup, because the fields are inaccessible.
330 330
         $form[$group_name]['#access'] = FALSE;
331
-      }
331
+        }
332 332
 
333
-      // Allow other modules to alter the form.
334
-      // Can't use module_invoke_all because we want
335
-      // to be able to use a reference to $form and $form_state.
336
-      foreach (module_implements('fieldgroup_form') as $module) {
333
+        // Allow other modules to alter the form.
334
+        // Can't use module_invoke_all because we want
335
+        // to be able to use a reference to $form and $form_state.
336
+        foreach (module_implements('fieldgroup_form') as $module) {
337 337
         $function = $module .'_fieldgroup_form';
338 338
         $function($form, $form_state, $form_id, $group);
339
-      }
339
+        }
340 340
 
341 341
     }
342 342
 
343
-  }
344
-  // The group is only added here so it will appear in the export
345
-  // when using Content Copy.
346
-  elseif ($form_id == 'content_field_edit_form' && isset($form['widget'])) {
343
+    }
344
+    // The group is only added here so it will appear in the export
345
+    // when using Content Copy.
346
+    elseif ($form_id == 'content_field_edit_form' && isset($form['widget'])) {
347 347
     $content_type = content_types($form['type_name']['#value']);
348 348
     $form['widget']['group'] = array(
349
-      '#type' => 'value',
350
-      '#value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']),
349
+        '#type' => 'value',
350
+        '#value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']),
351 351
     );
352
-  }
353
-  elseif ($form_id == 'content_field_overview_form') {
352
+    }
353
+    elseif ($form_id == 'content_field_overview_form') {
354 354
     $form['#validate'][] = 'fieldgroup_field_overview_form_validate';
355 355
     $form['#submit'][] = 'fieldgroup_field_overview_form_submit';
356
-  }
357
-  elseif ($form_id == 'content_display_overview_form' && !empty($form['#groups'])) {
356
+    }
357
+    elseif ($form_id == 'content_display_overview_form' && !empty($form['#groups'])) {
358 358
     $form['#submit'][] = 'fieldgroup_display_overview_form_submit';
359 359
     if (!isset($form['submit'])) {
360
-      $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 10);
360
+        $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 10);
361 361
     }
362
-  }
363
-  elseif ($form_id == 'content_field_remove_form') {
362
+    }
363
+    elseif ($form_id == 'content_field_remove_form') {
364 364
     $form['#submit'][] = 'fieldgroup_field_remove_form_submit';
365
-  }
365
+    }
366 366
 }
367 367
 
368 368
 /**
@@ -371,185 +371,185 @@  discard block
 block discarded – undo
371 371
  * Pulled into separate function to be re-usable.
372 372
  */
373 373
 function fieldgroup_validate_name($group, $type_name) {
374
-  $errors = array();
374
+    $errors = array();
375 375
 
376
-  // No label.
377
-  if (!$group['label']) {
376
+    // No label.
377
+    if (!$group['label']) {
378 378
     $errors['label'][] = t('You need to provide a label.');
379
-  }
379
+    }
380 380
 
381
-  // No group name.
382
-  if (!$group['group_name']) {
381
+    // No group name.
382
+    if (!$group['group_name']) {
383 383
     $errors['group_name'][] = t('You need to provide a group name.');
384
-  }
385
-  // Group name validation.
386
-  else {
384
+    }
385
+    // Group name validation.
386
+    else {
387 387
     $group_name = $group['group_name'];
388 388
     $group['group_type'] = !empty($group['group_type']) ? $group['group_type'] : 'standard';
389 389
 
390 390
     // Add the 'group_' prefix.
391 391
     if (substr($group_name, 0, 6) != 'group_') {
392
-      $group_name = 'group_'. $group_name;
392
+        $group_name = 'group_'. $group_name;
393 393
     }
394 394
 
395 395
     // Invalid field name.
396 396
     if (!preg_match('!^group_[a-z0-9_]+$!', $group_name)) {
397
-      $errors['group_name'][] = t('The group name %group_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%group_name' => $group_name));
397
+        $errors['group_name'][] = t('The group name %group_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%group_name' => $group_name));
398 398
     }
399 399
     if (strlen($group_name) > 32) {
400
-      $errors['group_name'][] = t('The group name %group_name is too long. The name is limited to 32 characters, including the \'group_\' prefix.', array('%group_name' => $group_name));
400
+        $errors['group_name'][] = t('The group name %group_name is too long. The name is limited to 32 characters, including the \'group_\' prefix.', array('%group_name' => $group_name));
401 401
     }
402 402
 
403 403
     // Group name already exists.
404 404
     $groups = fieldgroup_groups($type_name);
405 405
     if (isset($groups[$group_name])) {
406
-      $errors['group_name'][] = t('The group name %group_name already exists.', array('%group_name' => $group_name));
406
+        $errors['group_name'][] = t('The group name %group_name already exists.', array('%group_name' => $group_name));
407 407
     }
408 408
     if (empty($errors['group_name'])) {
409
-      $group['group_name'] = $group_name;
409
+        $group['group_name'] = $group_name;
410
+    }
410 411
     }
411
-  }
412
-  return array('group_name' => $group['group_name'], 'errors' => $errors);
412
+    return array('group_name' => $group['group_name'], 'errors' => $errors);
413 413
 }
414 414
 
415 415
 function fieldgroup_field_overview_form_validate($form, &$form_state) {
416
-  $form_values = $form_state['values'];
417
-  $group = $form_values['_add_new_group'];
416
+    $form_values = $form_state['values'];
417
+    $group = $form_values['_add_new_group'];
418 418
 
419
-  if (array_filter(array($group['label'], $group['group_name']))) {
419
+    if (array_filter(array($group['label'], $group['group_name']))) {
420 420
     $validation = fieldgroup_validate_name($group, $form['#type_name']);
421 421
     if (!empty($validation['errors'])) {
422
-      foreach ($validation['errors'] as $type => $messages) {
422
+        foreach ($validation['errors'] as $type => $messages) {
423 423
         foreach ($messages as $message) {
424
-          if ($type == 'label') {
424
+            if ($type == 'label') {
425 425
             form_set_error('_add_new_group][label', t('Add new group:') .' '. $message);
426
-          }
427
-          else {
426
+            }
427
+            else {
428 428
             form_set_error('_add_new_group][group_name', t('Add new group:') .' '. $message);
429
-          }
429
+            }
430
+        }
430 431
         }
431
-      }
432 432
     }
433 433
     $group_name = $validation['group_name'];
434 434
     form_set_value($form['_add_new_group']['group_name'], $group_name, $form_state);
435
-  }
436
-  else {
435
+    }
436
+    else {
437 437
     // Fail validation if attempt to nest fields under a new group without the
438 438
     // proper information. Not raising an error would cause the nested fields
439 439
     // to get weights the user doesn't expect.
440 440
 
441 441
     foreach ($form_values as $key => $values) {
442
-      if ($values['parent'] == '_add_new_group') {
442
+        if ($values['parent'] == '_add_new_group') {
443 443
         form_set_error('_add_new_group][label', t('Add new group: you need to provide a label.'));
444 444
         form_set_error('_add_new_group][group_name', t('Add new group: you need to provide a group name.'));
445 445
         break;
446
-      }
446
+        }
447
+    }
447 448
     }
448
-  }
449 449
 }
450 450
 
451 451
 function fieldgroup_field_overview_form_submit($form, &$form_state) {
452
-  $form_values = $form_state['values'];
453
-  $type_name = $form['#type_name'];
452
+    $form_values = $form_state['values'];
453
+    $type_name = $form['#type_name'];
454 454
 
455
-  // Create new group if needed.
456
-  if (!empty($form_values['_add_new_group']['label'])) {
455
+    // Create new group if needed.
456
+    if (!empty($form_values['_add_new_group']['label'])) {
457 457
     $group = $form_values['_add_new_group'];
458 458
     $group['settings'] = field_group_default_settings($group['group_type']);
459 459
     fieldgroup_save_group($type_name, $group);
460 460
     $new_group_name = $group['group_name'];
461
-  }
461
+    }
462 462
 
463
-  // Parse incoming rows.
464
-  $add_field_rows = array('_add_new_field', '_add_existing_field');
465
-  $field_rows = array_merge($form['#fields'], $add_field_rows);
466
-  foreach ($form_values as $key => $values) {
463
+    // Parse incoming rows.
464
+    $add_field_rows = array('_add_new_field', '_add_existing_field');
465
+    $field_rows = array_merge($form['#fields'], $add_field_rows);
466
+    foreach ($form_values as $key => $values) {
467 467
     // If 'field' row: update field parenting.
468 468
     if (in_array($key, $field_rows)) {
469
-      // If newly added fields were added to a group:
470
-      if (in_array($key, $add_field_rows)) {
469
+        // If newly added fields were added to a group:
470
+        if (in_array($key, $add_field_rows)) {
471 471
         // We replace the '_add_*_field' key with the actual name of
472 472
         // the field that got added.
473 473
         // content_field_overview_form_submit() placed those
474 474
         // in $form_state['fields_added'] for us.
475 475
         if (isset($form_state['fields_added'][$key])) {
476
-          $key = $form_state['fields_added'][$key];
476
+            $key = $form_state['fields_added'][$key];
477 477
         }
478 478
         else {
479
-          // No field was actually created : skip to next row.
480
-          continue;
479
+            // No field was actually created : skip to next row.
480
+            continue;
481 481
         }
482
-      }
483
-      // If the field was added to the newly created group, replace the
484
-      // '_add_new_group' value with the actual name of the group.
485
-      $parent = ($values['parent'] == '_add_new_group' && isset($new_group_name)) ? $new_group_name : $values['parent'];
486
-      // TODO: check the parent group does exist ?
487
-      fieldgroup_update_fields(array('field_name' => $key, 'group' => $parent, 'type_name' => $type_name));
482
+        }
483
+        // If the field was added to the newly created group, replace the
484
+        // '_add_new_group' value with the actual name of the group.
485
+        $parent = ($values['parent'] == '_add_new_group' && isset($new_group_name)) ? $new_group_name : $values['parent'];
486
+        // TODO: check the parent group does exist ?
487
+        fieldgroup_update_fields(array('field_name' => $key, 'group' => $parent, 'type_name' => $type_name));
488 488
     }
489 489
 
490 490
     // If 'group' row:  update groups weights
491 491
     // (possible newly created group has already been taken care of).
492 492
     elseif (in_array($key, $form['#groups'])) {
493
-      db_query("UPDATE {". fieldgroup_tablename() ."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'",
493
+        db_query("UPDATE {". fieldgroup_tablename() ."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'",
494 494
         $values['weight'], $type_name, $key);
495 495
     }
496
-  }
496
+    }
497 497
 
498
-  cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
498
+    cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
499 499
 }
500 500
 
501 501
 function field_group_default_settings($group_type) {
502
-  $settings = array(
502
+    $settings = array(
503 503
     'form' => array('style' => 'fieldset', 'description' => ''),
504 504
     'display' => array('description' => '', 'label' => 'above'),
505
-  );
506
-  module_load_include('inc', 'content', 'includes/content.admin');
507
-  foreach (array_keys(content_build_modes()) as $key) {
505
+    );
506
+    module_load_include('inc', 'content', 'includes/content.admin');
507
+    foreach (array_keys(content_build_modes()) as $key) {
508 508
     $settings['display'][$key]['format'] = 'fieldset';
509 509
     $settings['display'][$key]['exclude'] = 0;
510
-  }
511
-  // Allow other modules to add new default settings.
512
-  $settings = array_merge($settings, module_invoke_all('fieldgroup_default_settings', $group_type));
513
-  return $settings;
510
+    }
511
+    // Allow other modules to add new default settings.
512
+    $settings = array_merge($settings, module_invoke_all('fieldgroup_default_settings', $group_type));
513
+    return $settings;
514 514
 }
515 515
 
516 516
 function fieldgroup_display_overview_form_submit($form, &$form_state) {
517
-  $form_values = $form_state['values'];
518
-  $groups = fieldgroup_groups($form['#type_name']);
519
-  foreach ($form_values as $key => $values) {
517
+    $form_values = $form_state['values'];
518
+    $groups = fieldgroup_groups($form['#type_name']);
519
+    foreach ($form_values as $key => $values) {
520 520
     if (in_array($key, $form['#groups'])) {
521
-      $group = $groups[$key];
522
-      // We have some numeric keys here, so we can't use array_merge.
523
-      $group['settings']['display'] = $values + $group['settings']['display'];
524
-      fieldgroup_save_group($form['#type_name'], $group);
521
+        $group = $groups[$key];
522
+        // We have some numeric keys here, so we can't use array_merge.
523
+        $group['settings']['display'] = $values + $group['settings']['display'];
524
+        fieldgroup_save_group($form['#type_name'], $group);
525
+    }
525 526
     }
526
-  }
527 527
 }
528 528
 
529 529
 function fieldgroup_field_remove_form_submit($form, &$form_state) {
530
-  $form_values = $form_state['values'];
531
-  // TODO:
532
-  // - when a (non last) field is removed from a group, a 'ghost row' remains in the fields overview
533
-  // - when the last field is removed, the group disappears
534
-  // seems to be fixed when emptying the cache.
535
-  db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']);
530
+    $form_values = $form_state['values'];
531
+    // TODO:
532
+    // - when a (non last) field is removed from a group, a 'ghost row' remains in the fields overview
533
+    // - when the last field is removed, the group disappears
534
+    // seems to be fixed when emptying the cache.
535
+    db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']);
536 536
 }
537 537
 
538 538
 /**
539 539
  * Implementation of hook_nodeapi().
540 540
  */
541 541
 function fieldgroup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
542
-  switch ($op) {
542
+    switch ($op) {
543 543
     case 'view':
544 544
       // Prevent against invalid 'nodes' built by broken 3rd party code.
545 545
       if (isset($node->type)) {
546 546
         // Build the node content element needed to render each fieldgroup.
547 547
         foreach (fieldgroup_groups($node->type) as $group) {
548
-          fieldgroup_build_content($group, $node, $teaser, $page);
548
+            fieldgroup_build_content($group, $node, $teaser, $page);
549
+        }
549 550
         }
550
-      }
551
-      break;
552
-  }
551
+        break;
552
+    }
553 553
 }
554 554
 
555 555
 /**
@@ -569,80 +569,80 @@  discard block
 block discarded – undo
569 569
  * @see fieldgroup_view_group()
570 570
  */
571 571
 function fieldgroup_build_content($group, &$node, $teaser, $page) {
572
-  // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===.
573
-  if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) {
572
+    // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===.
573
+    if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) {
574 574
     $context = $teaser ? 'teaser' : 'full';
575
-  }
576
-  else {
575
+    }
576
+    else {
577 577
     $context = $node->build_mode;
578
-  }
578
+    }
579 579
 
580
-  $group_name = $group['group_name'];
580
+    $group_name = $group['group_name'];
581 581
 
582
-  // Do not include group labels when indexing content.
583
-  if ($context == NODE_BUILD_SEARCH_INDEX) {
582
+    // Do not include group labels when indexing content.
583
+    if ($context == NODE_BUILD_SEARCH_INDEX) {
584 584
     $group['settings']['display']['label'] = 'hidden';
585
-  }
586
-  $label = $group['settings']['display']['label'] == 'above';
587
-  $element = array(
585
+    }
586
+    $label = $group['settings']['display']['label'] == 'above';
587
+    $element = array(
588 588
     '#title' => $label ? check_plain(t($group['label'])) : '',
589 589
     '#description' => $label ? content_filter_xss(t($group['settings']['display']['description'])) : '',
590
-  );
591
-  $format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset';
590
+    );
591
+    $format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset';
592 592
 
593
-  switch ($format) {
593
+    switch ($format) {
594 594
     case 'simple':
595 595
       $element['#type'] = 'fieldgroup_simple';
596
-      $element['#group_name'] = $group_name;
597
-      $element['#node'] = $node;
598
-      break;
596
+        $element['#group_name'] = $group_name;
597
+        $element['#node'] = $node;
598
+        break;
599 599
     case 'hidden':
600 600
       $element['#access'] = FALSE;
601
-      break;
601
+        break;
602 602
     case 'fieldset_collapsed':
603 603
       $element['#collapsed'] = TRUE;
604 604
     case 'fieldset_collapsible':
605 605
       $element['#collapsible'] = TRUE;
606 606
     case 'fieldset':
607 607
       $element['#type'] = 'fieldgroup_fieldset';
608
-      $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-'));
609
-      break;
610
-  }
611
-  foreach ($group['fields'] as $field_name => $field) {
608
+        $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-'));
609
+        break;
610
+    }
611
+    foreach ($group['fields'] as $field_name => $field) {
612 612
     if (isset($node->content[$field_name])) {
613
-      $element[$field_name] = $node->content[$field_name];
613
+        $element[$field_name] = $node->content[$field_name];
614
+    }
614 615
     }
615
-  }
616 616
 
617
-  // Allow other modules to alter the group view.
618
-  // Can't use module_invoke_all because we want
619
-  // to be able to use a reference to $node and $element.
620
-  foreach (module_implements('fieldgroup_view') as $module) {
617
+    // Allow other modules to alter the group view.
618
+    // Can't use module_invoke_all because we want
619
+    // to be able to use a reference to $node and $element.
620
+    foreach (module_implements('fieldgroup_view') as $module) {
621 621
     $function = $module .'_fieldgroup_view';
622 622
     $function($node, $element, $group, $context);
623
-  }
623
+    }
624 624
 
625
-  // Unset the original field values now that we've moved them.
626
-  foreach ($group['fields'] as $field_name => $field) {
625
+    // Unset the original field values now that we've moved them.
626
+    foreach ($group['fields'] as $field_name => $field) {
627 627
     if (isset($node->content[$field_name])) {
628
-      unset($node->content[$field_name]);
628
+        unset($node->content[$field_name]);
629
+    }
629 630
     }
630
-  }
631 631
 
632
-  // The wrapper lets us get the themed output for the group
633
-  // to populate the $GROUP_NAME_rendered variable for node templates,
634
-  // and hide it from the $content variable if needed.
635
-  // See fieldgroup_preprocess_node(), theme_fieldgroup_wrapper().
636
-  $wrapper = array(
632
+    // The wrapper lets us get the themed output for the group
633
+    // to populate the $GROUP_NAME_rendered variable for node templates,
634
+    // and hide it from the $content variable if needed.
635
+    // See fieldgroup_preprocess_node(), theme_fieldgroup_wrapper().
636
+    $wrapper = array(
637 637
     'group' => $element,
638 638
     '#weight' => $group['weight'],
639 639
     '#post_render' => array('fieldgroup_wrapper_post_render'),
640 640
     '#group_name' => $group_name,
641 641
     '#type_name' => $node->type,
642 642
     '#context' => $context,
643
-  );
643
+    );
644 644
 
645
-  $node->content[$group_name] = $wrapper;
645
+    $node->content[$group_name] = $wrapper;
646 646
 }
647 647
 
648 648
 /**
@@ -674,64 +674,64 @@  discard block
 block discarded – undo
674 674
  * @see content_view_field()
675 675
  */
676 676
 function fieldgroup_view_group($group, &$node, $teaser = FALSE, $page = FALSE) {
677
-  $group_name = $group['group_name'];
678
-  $field_types = _content_field_types();
677
+    $group_name = $group['group_name'];
678
+    $field_types = _content_field_types();
679 679
 
680
-  // Clone the node to prevent from altering the original.
681
-  $node_copy = drupal_clone($node);
680
+    // Clone the node to prevent from altering the original.
681
+    $node_copy = drupal_clone($node);
682 682
 
683
-  // Use 'full'/'teaser' if not specified otherwise.
684
-  $node_copy->build_mode = isset($node_copy->build_mode) ? $node_copy->build_mode : NODE_BUILD_NORMAL;
683
+    // Use 'full'/'teaser' if not specified otherwise.
684
+    $node_copy->build_mode = isset($node_copy->build_mode) ? $node_copy->build_mode : NODE_BUILD_NORMAL;
685 685
 
686
-  // Build the content element for individual fields in the field group.
687
-  if (!isset($node_copy->content)) {
686
+    // Build the content element for individual fields in the field group.
687
+    if (!isset($node_copy->content)) {
688 688
     $node_copy->content = array();
689
-  }
690
-  foreach (array_keys($group['fields']) as $field_name) {
689
+    }
690
+    foreach (array_keys($group['fields']) as $field_name) {
691 691
     $field = content_fields($field_name, $node_copy->type);
692 692
 
693 693
     if (isset($node_copy->{$field_name})) {
694
-      $items = $node_copy->{$field_name};
694
+        $items = $node_copy->{$field_name};
695 695
 
696
-      // One-field equivalent to _content_field_invoke('sanitize').
697
-      $module = $field_types[$field['type']]['module'];
698
-      $function = $module .'_field';
699
-      if (function_exists($function)) {
696
+        // One-field equivalent to _content_field_invoke('sanitize').
697
+        $module = $field_types[$field['type']]['module'];
698
+        $function = $module .'_field';
699
+        if (function_exists($function)) {
700 700
         $function('sanitize', $node_copy, $field, $items, $teaser, $page);
701 701
         $node_copy->{$field_name} = $items;
702
-      }
702
+        }
703 703
 
704
-      $field_view = content_field('view', $node_copy, $field, $items, $teaser, $page);
705
-      // content_field('view') adds a wrapper to handle variables and 'excluded'
706
-      // fields for node templates. We bypass it and get the actual field.
707
-      $node_copy->content[$field_name] = $field_view[$field_name];
704
+        $field_view = content_field('view', $node_copy, $field, $items, $teaser, $page);
705
+        // content_field('view') adds a wrapper to handle variables and 'excluded'
706
+        // fields for node templates. We bypass it and get the actual field.
707
+        $node_copy->content[$field_name] = $field_view[$field_name];
708
+    }
708 709
     }
709
-  }
710 710
 
711
-  // Build the content element of the field group itself.
712
-  fieldgroup_build_content($group, $node_copy, $teaser, $page);
711
+    // Build the content element of the field group itself.
712
+    fieldgroup_build_content($group, $node_copy, $teaser, $page);
713 713
 
714
-  // fieldgroup_build_content() adds a wrapper to handle variables and 'excluded'
715
-  // groups for node templates. We bypass it and render the actual field group.
716
-  $output = drupal_render($node_copy->content[$group_name]['group']);
714
+    // fieldgroup_build_content() adds a wrapper to handle variables and 'excluded'
715
+    // groups for node templates. We bypass it and render the actual field group.
716
+    $output = drupal_render($node_copy->content[$group_name]['group']);
717 717
 
718
-  return $output;
718
+    return $output;
719 719
 }
720 720
 
721 721
 /**
722 722
  * Hide specified fields from the $content variable in node templates.
723 723
  */
724 724
 function fieldgroup_wrapper_post_render($content, $element) {
725
-  $groups = fieldgroup_groups($element['#type_name']);
726
-  $group = $groups[$element['#group_name']];
725
+    $groups = fieldgroup_groups($element['#type_name']);
726
+    $group = $groups[$element['#group_name']];
727 727
 
728
-  // The display settings are not in quite the same place in the
729
-  // group and the field, so create the value the theme will expect.
730
-  $group['display_settings'] = $group['settings']['display'];
731
-  if (theme('content_exclude', $content, $group, $element['#context'])) {
728
+    // The display settings are not in quite the same place in the
729
+    // group and the field, so create the value the theme will expect.
730
+    $group['display_settings'] = $group['settings']['display'];
731
+    if (theme('content_exclude', $content, $group, $element['#context'])) {
732 732
     return '';
733
-  }
734
-  return $content;
733
+    }
734
+    return $content;
735 735
 }
736 736
 
737 737
 /*
@@ -740,12 +740,12 @@  discard block
 block discarded – undo
740 740
  * @return The name of the group, or FALSE.
741 741
  */
742 742
 function fieldgroup_get_group($content_type, $field_name) {
743
-  foreach (fieldgroup_groups($content_type) as $group_name => $group) {
743
+    foreach (fieldgroup_groups($content_type) as $group_name => $group) {
744 744
     if (in_array($field_name, array_keys($group['fields']))) {
745
-      return $group_name;
745
+        return $group_name;
746 746
     }
747
-  }
748
-  return FALSE;
747
+    }
748
+    return FALSE;
749 749
 }
750 750
 
751 751
 /**
@@ -753,37 +753,37 @@  discard block
 block discarded – undo
753 753
  *  React to change in node types
754 754
  */
755 755
 function fieldgroup_node_type($op, $info) {
756
-  if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) {
756
+    if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) {
757 757
     // update the tables
758 758
     db_query("UPDATE {". fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type));
759 759
     db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type));
760 760
     cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
761
-  }
762
-  elseif ($op == 'delete') {
761
+    }
762
+    elseif ($op == 'delete') {
763 763
     db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type);
764 764
     db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s'", $info->type);
765
-  }
765
+    }
766 766
 }
767 767
 
768 768
 function fieldgroup_types() {
769
-  $types = array('standard' => t('Standard group'));
770
-  // Allow other modules to add new group_types.
771
-  $types = array_merge($types, module_invoke_all('fieldgroup_types'));
772
-  return $types;
769
+    $types = array('standard' => t('Standard group'));
770
+    // Allow other modules to add new group_types.
771
+    $types = array_merge($types, module_invoke_all('fieldgroup_types'));
772
+    return $types;
773 773
 }
774 774
 
775 775
 function fieldgroup_tablename($version = NULL) {
776
-  if (is_null($version)) {
776
+    if (is_null($version)) {
777 777
     $version = variable_get('fieldgroup_schema_version', 0);
778
-  }
779
-  return $version < 6000 ? 'node_group' : 'content_group';
778
+    }
779
+    return $version < 6000 ? 'node_group' : 'content_group';
780 780
 }
781 781
 
782 782
 function fieldgroup_fields_tablename($version = NULL) {
783
-  if (is_null($version)) {
783
+    if (is_null($version)) {
784 784
     $version = variable_get('fieldgroup_schema_version', 0);
785
-  }
786
-  return $version < 6000 ? 'node_group_fields' : 'content_group_fields';
785
+    }
786
+    return $version < 6000 ? 'node_group_fields' : 'content_group_fields';
787 787
 }
788 788
 
789 789
 /**
@@ -796,51 +796,51 @@  discard block
 block discarded – undo
796 796
  * Saves the given group for this content-type
797 797
  */
798 798
 function fieldgroup_save_group($type_name, $group) {
799
-  $groups = fieldgroup_groups($type_name);
799
+    $groups = fieldgroup_groups($type_name);
800 800
 
801
-  // Allow other modules to intervene when the group is saved.
802
-  foreach (module_implements('fieldgroup_save_group') as $module) {
801
+    // Allow other modules to intervene when the group is saved.
802
+    foreach (module_implements('fieldgroup_save_group') as $module) {
803 803
     $function = $module .'_fieldgroup_save_group';
804 804
     $function($group);
805
-  }
805
+    }
806 806
 
807
-  if (!isset($groups[$group['group_name']])) {
807
+    if (!isset($groups[$group['group_name']])) {
808 808
     // Accept group name from programmed submissions if valid.
809 809
     db_query("INSERT INTO {". fieldgroup_tablename() ."} (group_type, type_name, group_name, label, settings, weight)".
810
-      " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']);
810
+        " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']);
811 811
     cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
812 812
     return SAVED_NEW;
813
-  }
814
-  else {
813
+    }
814
+    else {
815 815
     db_query("UPDATE {". fieldgroup_tablename() ."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ".
816
-             "WHERE type_name = '%s' AND group_name = '%s'",
817
-             $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']);
816
+                "WHERE type_name = '%s' AND group_name = '%s'",
817
+                $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']);
818 818
     cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
819 819
     return SAVED_UPDATED;
820
-  }
820
+    }
821 821
 }
822 822
 
823 823
 function fieldgroup_update_fields($form_values) {
824
-  $default = _fieldgroup_field_get_group($form_values['type_name'], $form_values['field_name']);
824
+    $default = _fieldgroup_field_get_group($form_values['type_name'], $form_values['field_name']);
825 825
 
826
-  if ($default != $form_values['group']) {
826
+    if ($default != $form_values['group']) {
827 827
     if ($form_values['group'] && !$default) {
828
-      db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']);
828
+        db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']);
829 829
     }
830 830
     elseif ($form_values['group']) {
831
-      db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']);
831
+        db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']);
832 832
     }
833 833
     else {
834
-      db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']);
834
+        db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']);
835 835
     }
836 836
     cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
837
-  }
837
+    }
838 838
 }
839 839
 
840 840
 function fieldgroup_delete($content_type, $group_name) {
841
-  db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE  type_name = '%s' AND group_name = '%s'", $content_type, $group_name);
842
-  db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE  type_name = '%s' AND group_name = '%s'", $content_type, $group_name);
843
-  cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
841
+    db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE  type_name = '%s' AND group_name = '%s'", $content_type, $group_name);
842
+    db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE  type_name = '%s' AND group_name = '%s'", $content_type, $group_name);
843
+    cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
844 844
 }
845 845
 
846 846
 /**
@@ -849,23 +849,23 @@  discard block
 block discarded – undo
849 849
  * Derived from core's theme_fieldset, with no output if the content is empty.
850 850
  */
851 851
 function theme_fieldgroup_fieldset($element) {
852
-  if (empty($element['#children']) && empty($element['#value'])) {
852
+    if (empty($element['#children']) && empty($element['#value'])) {
853 853
     return '';
854
-  }
854
+    }
855 855
 
856
-  if ($element['#collapsible']) {
856
+    if ($element['#collapsible']) {
857 857
     drupal_add_js('misc/collapse.js');
858 858
 
859 859
     if (!isset($element['#attributes']['class'])) {
860
-      $element['#attributes']['class'] = '';
860
+        $element['#attributes']['class'] = '';
861 861
     }
862 862
 
863 863
     $element['#attributes']['class'] .= ' collapsible';
864 864
     if ($element['#collapsed']) {
865
-      $element['#attributes']['class'] .= ' collapsed';
865
+        $element['#attributes']['class'] .= ' collapsed';
866
+    }
866 867
     }
867
-  }
868
-  return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n";
868
+    return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n";
869 869
 }
870 870
 
871 871
 
@@ -882,19 +882,19 @@  discard block
 block discarded – undo
882 882
  * @see fieldgroup-simple.tpl.php
883 883
  */
884 884
 function template_preprocess_fieldgroup_simple(&$vars) {
885
-  $element = $vars['element'];
886
-
887
-  $vars['group_name'] = $element['#group_name'];
888
-  $vars['group_name_css'] = strtr($element['#group_name'], '_', '-');
889
-  $vars['label'] = isset($element['#title']) ? $element['#title'] : '';;
890
-  $vars['description'] = isset($element['#description']) ? $element['#description'] : '';;
891
-  $vars['content'] = isset($element['#children']) ? $element['#children'] : '';
892
-  $vars['template_files'] = array(
885
+    $element = $vars['element'];
886
+
887
+    $vars['group_name'] = $element['#group_name'];
888
+    $vars['group_name_css'] = strtr($element['#group_name'], '_', '-');
889
+    $vars['label'] = isset($element['#title']) ? $element['#title'] : '';;
890
+    $vars['description'] = isset($element['#description']) ? $element['#description'] : '';;
891
+    $vars['content'] = isset($element['#children']) ? $element['#children'] : '';
892
+    $vars['template_files'] = array(
893 893
     'fieldgroup-simple-',
894 894
     'fieldgroup-simple-'. $element['#group_name'],
895 895
     'fieldgroup-simple-'. $element['#node']->type,
896 896
     'fieldgroup-simple-'. $element['#group_name'] .'-'. $element['#node']->type,
897
-  );
897
+    );
898 898
 }
899 899
 
900 900
 /**
@@ -904,10 +904,10 @@  discard block
 block discarded – undo
904 904
  * containing the themed output for the whole group.
905 905
  */
906 906
 function fieldgroup_preprocess_node(&$vars) {
907
-  $node = $vars['node'];
907
+    $node = $vars['node'];
908 908
 
909
-  foreach (fieldgroup_groups($node->type) as $group_name => $group) {
909
+    foreach (fieldgroup_groups($node->type) as $group_name => $group) {
910 910
     // '#chilren' might not be set if the group is empty.
911 911
     $vars[$group_name .'_rendered'] = isset($node->content[$group_name]['#children']) ? $node->content[$group_name]['#children'] : '';
912
-  }
912
+    }
913 913
 }
Please login to merge, or discard this patch.
boinc/modules/contrib/cck/modules/nodereference/nodereference.rules.inc 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -10,37 +10,37 @@  discard block
 block discarded – undo
10 10
  * Implementation of hook_rules_action_info().
11 11
  */
12 12
 function nodereference_rules_action_info() {
13
-  $info = array();
14
-  $info['nodereference_rules_action_load'] = array(
13
+    $info = array();
14
+    $info['nodereference_rules_action_load'] = array(
15 15
     'label' => t('Load a referenced node'),
16 16
     'arguments' => array(
17
-      'node' => array(
17
+        'node' => array(
18 18
         'type' => 'node',
19 19
         'label' => t('Content containing the node reference field'),
20
-      ),
20
+        ),
21 21
     ),
22 22
     'new variables' => array(
23
-      'referenced_node' => array(
23
+        'referenced_node' => array(
24 24
         'type' => 'node',
25 25
         'label' => t('Referenced content'),
26
-      ),
26
+        ),
27 27
     ),
28 28
     'module' => 'CCK',
29 29
     'help' => t('Note that if the field has multiple values, only the first content node will be loaded.'),
30
-  );
31
-  return $info;
30
+    );
31
+    return $info;
32 32
 }
33 33
 
34 34
 function nodereference_rules_action_load($node, $settings) {
35
-  if ($nid = $node->{$settings['field']}[0]['nid']) {
35
+    if ($nid = $node->{$settings['field']}[0]['nid']) {
36 36
     return array('referenced_node' => node_load(array('nid' => $nid)));
37
-  }
37
+    }
38 38
 }
39 39
 
40 40
 function nodereference_rules_action_load_form($settings, &$form) {
41
-  $settings += array('field' => '');
42
-  $options = content_rules_get_field_names_by_type('nodereference');
43
-  $form['settings']['field'] = array(
41
+    $settings += array('field' => '');
42
+    $options = content_rules_get_field_names_by_type('nodereference');
43
+    $form['settings']['field'] = array(
44 44
     '#type' => 'select',
45 45
     '#title' => t('Field'),
46 46
     '#default_value' => $settings['field'],
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
     '#required' => TRUE,
49 49
     '#disabled' => empty($options),
50 50
     '#description' => empty($options) ? t('There are no nodereference fields defined.') : '',
51
-  );
51
+    );
52 52
 }
53 53
 
54 54
 /**
@@ -56,5 +56,5 @@  discard block
 block discarded – undo
56 56
  * "workflow_ng_action_load_referenced_node" to the equivalent rules action.
57 57
  */
58 58
 function workflow_ng_action_load_referenced_node_upgrade(&$element) {
59
-  $element['#name'] = 'nodereference_rules_action_load';
59
+    $element['#name'] = 'nodereference_rules_action_load';
60 60
 }
Please login to merge, or discard this patch.
cck/modules/nodereference/panels/relationships/node_from_noderef.inc 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * Implementation of hook_ctools_relationships().
11 11
  */
12 12
 function nodereference_node_from_noderef_ctools_relationships() {
13
-  return array(
13
+    return array(
14 14
     'title' => t('Node from reference'),
15 15
     'keyword' => 'nodereference',
16 16
     'description' => t('Adds a node from a node reference in a node context; if multiple nodes are referenced, this will get the first referenced node only.'),
@@ -18,59 +18,59 @@  discard block
 block discarded – undo
18 18
     'context' => 'nodereference_node_from_noderef_context',
19 19
     'settings form' => 'nodereference_node_from_noderef_settings_form',
20 20
     'settings form validate' => 'nodereference_node_from_noderef_settings_form_validate',
21
-  );
21
+    );
22 22
 }
23 23
 
24 24
 /**
25 25
  * Return a new ctools context based on an existing context.
26 26
  */
27 27
 function nodereference_node_from_noderef_context($context, $conf) {
28
-  $field = content_fields($conf['field_name']);
28
+    $field = content_fields($conf['field_name']);
29 29
 
30
-  // If unset it wants a generic, unfilled context, which is just NULL.
31
-  if (empty($context->data)) {
30
+    // If unset it wants a generic, unfilled context, which is just NULL.
31
+    if (empty($context->data)) {
32 32
     $new_context = ctools_context_create_empty('node', NULL);
33
-  }
34
-  else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) {
33
+    }
34
+    else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) {
35 35
     if ($node = node_load($nid)) {
36
-      $new_context = ctools_context_create('node', $node);
36
+        $new_context = ctools_context_create('node', $node);
37
+    }
37 38
     }
38
-  }
39 39
 
40
-  if (!empty($new_context)) {
40
+    if (!empty($new_context)) {
41 41
     // Have nodereference relationships limit CCK field availability as well.
42 42
     $restrictions = array_keys(array_filter($field['referenceable_types']));
43 43
     if ($restrictions) {
44
-      if (isset($new_context->restrictions['type'])) {
44
+        if (isset($new_context->restrictions['type'])) {
45 45
         $new_context->restrictions['type'] = array_unique(array_merge($new_context->restrictions['type'], $restrictions));
46
-      }
47
-      else {
46
+        }
47
+        else {
48 48
         $new_context->restrictions['type'] = $restrictions;
49
-      }
49
+        }
50 50
     }
51 51
 
52 52
     return $new_context;
53
-  }
53
+    }
54 54
 }
55 55
 
56 56
 /**
57 57
  * Settings form for the ctools relationship.
58 58
  */
59 59
 function nodereference_node_from_noderef_settings_form($conf) {
60
-  $options = array();
61
-  foreach (content_fields() as $field) {
60
+    $options = array();
61
+    foreach (content_fields() as $field) {
62 62
     if ($field['type'] == 'nodereference') {
63
-      $options[$field['field_name']] = t($field['widget']['label']);
63
+        $options[$field['field_name']] = t($field['widget']['label']);
64
+    }
64 65
     }
65
-  }
66
-  $form['field_name'] = array(
66
+    $form['field_name'] = array(
67 67
     '#title' => t('Node reference field'),
68 68
     '#type' => 'select',
69 69
     '#options' => $options,
70 70
     '#default_value' => isset($conf['field_name']) ? $conf['field_name'] : '',
71 71
     '#prefix' => '<div class="clear-block">',
72 72
     '#suffix' => '</div>',
73
-  );
73
+    );
74 74
 
75
-  return $form;
75
+    return $form;
76 76
 }
Please login to merge, or discard this patch.
boinc/modules/contrib/cck/modules/nodereference/nodereference.module 1 patch
Indentation   +360 added lines, -360 removed lines patch added patch discarded remove patch
@@ -10,230 +10,230 @@  discard block
 block discarded – undo
10 10
  * Implementation of hook_menu().
11 11
  */
12 12
 function nodereference_menu() {
13
-  $items = array();
14
-  $items['nodereference/autocomplete'] = array(
13
+    $items = array();
14
+    $items['nodereference/autocomplete'] = array(
15 15
     'title' => 'Nodereference autocomplete',
16 16
     'page callback' => 'nodereference_autocomplete',
17 17
     'access callback' => 'nodereference_autocomplete_access',
18 18
     'access arguments' => array(2),
19 19
     'type' => MENU_CALLBACK
20
-  );
21
-  return $items;
20
+    );
21
+    return $items;
22 22
 }
23 23
 
24 24
 /**
25 25
  * Implementation of hook_theme().
26 26
  */
27 27
 function nodereference_theme() {
28
-  return array(
28
+    return array(
29 29
     'nodereference_select' => array(
30
-      'arguments' => array('element' => NULL),
30
+        'arguments' => array('element' => NULL),
31 31
     ),
32 32
     'nodereference_buttons' => array(
33
-      'arguments' => array('element' => NULL),
33
+        'arguments' => array('element' => NULL),
34 34
     ),
35 35
     'nodereference_autocomplete' => array(
36
-      'arguments' => array('element' => NULL),
36
+        'arguments' => array('element' => NULL),
37 37
     ),
38 38
     'nodereference_formatter_default' => array(
39
-      'arguments' => array('element'),
39
+        'arguments' => array('element'),
40 40
     ),
41 41
     'nodereference_formatter_plain' => array(
42
-      'arguments' => array('element'),
42
+        'arguments' => array('element'),
43 43
     ),
44 44
     'nodereference_formatter_full' => array(
45
-      'arguments' => array('element'),
46
-      'function' => 'theme_nodereference_formatter_full_teaser',
45
+        'arguments' => array('element'),
46
+        'function' => 'theme_nodereference_formatter_full_teaser',
47 47
     ),
48 48
     'nodereference_formatter_teaser' => array(
49
-      'arguments' => array('element'),
50
-      'function' => 'theme_nodereference_formatter_full_teaser',
49
+        'arguments' => array('element'),
50
+        'function' => 'theme_nodereference_formatter_full_teaser',
51 51
     ),
52
-  );
52
+    );
53 53
 }
54 54
 
55 55
 /**
56 56
  * Implementaion of hook_ctools_plugin_directory().
57 57
  */
58 58
 function nodereference_ctools_plugin_directory($module, $plugin) {
59
-  if ($module == 'ctools' && $plugin == 'relationships') {
59
+    if ($module == 'ctools' && $plugin == 'relationships') {
60 60
     return 'panels/' . $plugin;
61
-  }
61
+    }
62 62
 }
63 63
 
64 64
 /**
65 65
  * Implementation of hook_field_info().
66 66
  */
67 67
 function nodereference_field_info() {
68
-  return array(
68
+    return array(
69 69
     'nodereference' => array(
70
-      'label' => t('Node reference'),
71
-      'description' => t('Store the ID of a related node as an integer value.'),
70
+        'label' => t('Node reference'),
71
+        'description' => t('Store the ID of a related node as an integer value.'),
72 72
 //      'content_icon' => 'icon_content_noderef.png',
73 73
     ),
74
-  );
74
+    );
75 75
 }
76 76
 
77 77
 /**
78 78
  * Implementation of hook_field_settings().
79 79
  */
80 80
 function nodereference_field_settings($op, $field) {
81
-  switch ($op) {
81
+    switch ($op) {
82 82
     case 'form':
83 83
       $form = array();
84
-      $form['referenceable_types'] = array(
84
+        $form['referenceable_types'] = array(
85 85
         '#type' => 'checkboxes',
86 86
         '#title' => t('Content types that can be referenced'),
87 87
         '#multiple' => TRUE,
88 88
         '#default_value' => is_array($field['referenceable_types']) ? $field['referenceable_types'] : array(),
89 89
         '#options' => array_map('check_plain', node_get_types('names')),
90
-      );
91
-      if (module_exists('views')) {
90
+        );
91
+        if (module_exists('views')) {
92 92
         $views = array('--' => '--');
93 93
         $all_views = views_get_all_views();
94 94
         foreach ($all_views as $view) {
95
-          // Only 'node' views that have fields will work for our purpose.
96
-          if ($view->base_table == 'node' && !empty($view->display['default']->display_options['fields'])) {
95
+            // Only 'node' views that have fields will work for our purpose.
96
+            if ($view->base_table == 'node' && !empty($view->display['default']->display_options['fields'])) {
97 97
             if ($view->type == 'Default') {
98
-              $views[t('Default Views')][$view->name] = $view->name;
98
+                $views[t('Default Views')][$view->name] = $view->name;
99 99
             }
100 100
             else {
101
-              $views[t('Existing Views')][$view->name] = $view->name;
101
+                $views[t('Existing Views')][$view->name] = $view->name;
102
+            }
102 103
             }
103
-          }
104 104
         }
105 105
 
106 106
         $form['advanced'] = array(
107
-           '#type' => 'fieldset',
108
-           '#title' => t('Advanced - Nodes that can be referenced (View)'),
109
-           '#collapsible' => TRUE,
110
-           '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--',
111
-         );
107
+            '#type' => 'fieldset',
108
+            '#title' => t('Advanced - Nodes that can be referenced (View)'),
109
+            '#collapsible' => TRUE,
110
+            '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--',
111
+            );
112 112
         if (count($views) > 1) {
113
-          $form['advanced']['advanced_view'] = array(
113
+            $form['advanced']['advanced_view'] = array(
114 114
             '#type' => 'select',
115 115
             '#title' => t('View used to select the nodes'),
116 116
             '#options' => $views,
117 117
             '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--',
118 118
             '#description' => t('<p>Choose the "Views module" view that selects the nodes that can be referenced.<br />Note:</p>') .
119
-              t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'),
120
-          );
121
-          $form['advanced']['advanced_view_args'] = array(
119
+                t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'),
120
+            );
121
+            $form['advanced']['advanced_view_args'] = array(
122 122
             '#type' => 'textfield',
123 123
             '#title' => t('View arguments'),
124 124
             '#default_value' => isset($field['advanced_view_args']) ? $field['advanced_view_args'] : '',
125 125
             '#required' => FALSE,
126 126
             '#description' => t('Provide a comma separated list of arguments to pass to the view.'),
127
-          );
127
+            );
128 128
         }
129 129
         else {
130
-          $form['advanced']['no_view_help'] = array(
130
+            $form['advanced']['no_view_help'] = array(
131 131
             '#value' => t('<p>The list of nodes that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') .
132
-              t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'),
133
-          );
132
+                t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'),
133
+            );
134 134
         }
135
-      }
136
-      return $form;
135
+        }
136
+        return $form;
137 137
 
138 138
     case 'save':
139 139
       $settings = array('referenceable_types');
140
-      if (module_exists('views')) {
140
+        if (module_exists('views')) {
141 141
         $settings[] = 'advanced_view';
142 142
         $settings[] = 'advanced_view_args';
143
-      }
144
-      return $settings;
143
+        }
144
+        return $settings;
145 145
 
146 146
     case 'database columns':
147 147
       $columns = array(
148 148
         'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'index' => TRUE),
149
-      );
150
-      return $columns;
149
+        );
150
+        return $columns;
151 151
 
152 152
     case 'views data':
153 153
       $data = content_views_field_views_data($field);
154
-      $db_info = content_database_info($field);
155
-      $table_alias = content_views_tablename($field);
154
+        $db_info = content_database_info($field);
155
+        $table_alias = content_views_tablename($field);
156 156
 
157
-      // Filter: swap the handler to the 'in' operator.
158
-      $data[$table_alias][$field['field_name'] .'_nid']['filter']['handler'] = 'content_handler_filter_many_to_one';
159
-      // Argument: use node.title for summaries.
160
-      $data["node_$table_alias"]['table']['join']['node'] = array(
157
+        // Filter: swap the handler to the 'in' operator.
158
+        $data[$table_alias][$field['field_name'] .'_nid']['filter']['handler'] = 'content_handler_filter_many_to_one';
159
+        // Argument: use node.title for summaries.
160
+        $data["node_$table_alias"]['table']['join']['node'] = array(
161 161
         'table' => 'node',
162 162
         'field' => 'nid',
163 163
         'left_table' => $table_alias,
164 164
         'left_field' => $field['field_name'] .'_nid',
165
-      );
166
-      $data[$table_alias][$field['field_name'] .'_nid']['argument']['handler'] = 'content_handler_argument_reference';
167
-      $data[$table_alias][$field['field_name'] .'_nid']['argument']['name table'] = "node_$table_alias";
168
-      $data[$table_alias][$field['field_name'] .'_nid']['argument']['name field'] = 'title';
169
-      // Relationship: add a relationship for related node.
170
-      $data[$table_alias][$field['field_name'] .'_nid']['relationship'] = array(
165
+        );
166
+        $data[$table_alias][$field['field_name'] .'_nid']['argument']['handler'] = 'content_handler_argument_reference';
167
+        $data[$table_alias][$field['field_name'] .'_nid']['argument']['name table'] = "node_$table_alias";
168
+        $data[$table_alias][$field['field_name'] .'_nid']['argument']['name field'] = 'title';
169
+        // Relationship: add a relationship for related node.
170
+        $data[$table_alias][$field['field_name'] .'_nid']['relationship'] = array(
171 171
         'base' => 'node',
172 172
         'field' => $db_info['columns']['nid']['column'],
173 173
         'handler' => 'content_handler_relationship',
174 174
         'label' => t($field['widget']['label']),
175 175
         'content_field_name' => $field['field_name'],
176
-      );
177
-      return $data;
178
-  }
176
+        );
177
+        return $data;
178
+    }
179 179
 }
180 180
 
181 181
 /**
182 182
  * Implementation of hook_field().
183 183
  */
184 184
 function nodereference_field($op, &$node, $field, &$items, $teaser, $page) {
185
-  static $sanitized_nodes = array();
185
+    static $sanitized_nodes = array();
186 186
   
187
-  switch ($op) {
187
+    switch ($op) {
188 188
     // When preparing a translation, load any translations of existing references.
189 189
     case 'prepare translation':
190 190
       $addition = array();
191
-      $addition[$field['field_name']] = array();
192
-      if (isset($node->translation_source->$field['field_name']) && is_array($node->translation_source->$field['field_name'])) {
191
+        $addition[$field['field_name']] = array();
192
+        if (isset($node->translation_source->$field['field_name']) && is_array($node->translation_source->$field['field_name'])) {
193 193
         foreach ($node->translation_source->$field['field_name'] as $key => $reference) {
194
-          $reference_node = node_load($reference['nid']);
195
-          // Test if the referenced node type is translatable and, if so,
196
-          // load translations if the reference is not for the current language.
197
-          // We can assume the translation module is present because it invokes 'prepare translation'.
198
-          if (translation_supported_type($reference_node->type) && !empty($reference_node->language) && $reference_node->language != $node->language && $translations = translation_node_get_translations($reference_node->tnid)) {
194
+            $reference_node = node_load($reference['nid']);
195
+            // Test if the referenced node type is translatable and, if so,
196
+            // load translations if the reference is not for the current language.
197
+            // We can assume the translation module is present because it invokes 'prepare translation'.
198
+            if (translation_supported_type($reference_node->type) && !empty($reference_node->language) && $reference_node->language != $node->language && $translations = translation_node_get_translations($reference_node->tnid)) {
199 199
             // If there is a translation for the current language, use it.
200 200
             $addition[$field['field_name']][] = array(
201
-              'nid' => isset($translations[$node->language]) ? $translations[$node->language]->nid : $reference['nid'],
201
+                'nid' => isset($translations[$node->language]) ? $translations[$node->language]->nid : $reference['nid'],
202 202
             );
203
-          }
203
+            }
204
+        }
204 205
         }
205
-      }
206
-      return $addition;
206
+        return $addition;
207 207
 
208 208
     case 'validate':
209 209
       // Extract nids to check.
210 210
       $ids = array();
211
-      foreach ($items as $delta => $item) {
211
+        foreach ($items as $delta => $item) {
212 212
         if (is_array($item) && !empty($item['nid'])) {
213
-          if (is_numeric($item['nid'])) {
213
+            if (is_numeric($item['nid'])) {
214 214
             $ids[] = $item['nid'];
215
-          }
216
-          else {
215
+            }
216
+            else {
217 217
             $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
218 218
             if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']);
219 219
             form_set_error($error_element, t("%name: invalid input.", array('%name' => t($field['widget']['label']))));
220
-          }
220
+            }
221
+        }
221 222
         }
222
-      }
223
-      // Prevent performance hog if there are no ids to check.
224
-      if ($ids) {
223
+        // Prevent performance hog if there are no ids to check.
224
+        if ($ids) {
225 225
         $refs = _nodereference_potential_references($field, '', NULL, $ids);
226 226
         foreach ($items as $delta => $item) {
227
-          if (is_array($item)) {
227
+            if (is_array($item)) {
228 228
             $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
229 229
             if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']);
230 230
             if (!empty($item['nid']) && !isset($refs[$item['nid']])) {
231
-              form_set_error($error_element, t("%name: this post can't be referenced.", array('%name' => t($field['widget']['label']))));
231
+                form_set_error($error_element, t("%name: this post can't be referenced.", array('%name' => t($field['widget']['label']))));
232 232
             }
233
-          }
233
+            }
234
+        }
234 235
         }
235
-      }
236
-      return $items;
236
+        return $items;
237 237
 
238 238
     case 'sanitize':
239 239
       // We can't just check the node is 'referenceable', because Views-mode
@@ -241,133 +241,133 @@  discard block
 block discarded – undo
241 241
 
242 242
       // Extract nids to check.
243 243
       $ids = array();
244
-      foreach ($items as $delta => $item) {
244
+        foreach ($items as $delta => $item) {
245 245
         if (is_array($item)) {
246
-          // Default to 'non accessible'.
247
-          $items[$delta]['safe'] = array();
248
-          if (!empty($item['nid']) && is_numeric($item['nid'])) {
246
+            // Default to 'non accessible'.
247
+            $items[$delta]['safe'] = array();
248
+            if (!empty($item['nid']) && is_numeric($item['nid'])) {
249 249
             $ids[] = $item['nid'];
250
-          }
250
+            }
251
+        }
251 252
         }
252
-      }
253
-      if ($ids) {
253
+        if ($ids) {
254 254
         // Load information about nids that we haven't already loaded during
255 255
         // this page request.
256 256
         $missing_ids = array_diff($ids, array_keys($sanitized_nodes));
257 257
         if (!empty($missing_ids)) {
258
-          $where = array('n.nid in ('. db_placeholders($missing_ids) . ')');
259
-          if (!user_access('administer nodes')) {
258
+            $where = array('n.nid in ('. db_placeholders($missing_ids) . ')');
259
+            if (!user_access('administer nodes')) {
260 260
             $where[] = 'n.status = 1';
261
-          }
262
-          $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.status FROM {node} n WHERE '. implode(' AND ', $where)), $missing_ids);
263
-          while ($row = db_fetch_array($result)) {
261
+            }
262
+            $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.status FROM {node} n WHERE '. implode(' AND ', $where)), $missing_ids);
263
+            while ($row = db_fetch_array($result)) {
264 264
             $sanitized_nodes[$row['nid']] = $row;
265
-          }
265
+            }
266 266
         }
267 267
         foreach ($items as $delta => $item) {
268
-          if (is_array($item) && !empty($item['nid']) && isset($sanitized_nodes[$item['nid']])) {
268
+            if (is_array($item) && !empty($item['nid']) && isset($sanitized_nodes[$item['nid']])) {
269 269
             $items[$delta]['safe'] = $sanitized_nodes[$item['nid']];
270
-          }
270
+            }
271
+        }
271 272
         }
272
-      }
273
-      return $items;
274
-  }
273
+        return $items;
274
+    }
275 275
 }
276 276
 
277 277
 /**
278 278
  * Implementation of hook_content_is_empty().
279 279
  */
280 280
 function nodereference_content_is_empty($item, $field) {
281
-  if (empty($item['nid'])) {
281
+    if (empty($item['nid'])) {
282 282
     return TRUE;
283
-  }
284
-  return FALSE;
283
+    }
284
+    return FALSE;
285 285
 }
286 286
 
287 287
 /**
288 288
  * Implementation of hook_field_formatter_info().
289 289
  */
290 290
 function nodereference_field_formatter_info() {
291
-  return array(
291
+    return array(
292 292
     'default' => array(
293
-      'label' => t('Title (link)'),
294
-      'field types' => array('nodereference'),
295
-      'multiple values' => CONTENT_HANDLE_CORE,
293
+        'label' => t('Title (link)'),
294
+        'field types' => array('nodereference'),
295
+        'multiple values' => CONTENT_HANDLE_CORE,
296 296
     ),
297 297
     'plain' => array(
298
-      'label' => t('Title (no link)'),
299
-      'field types' => array('nodereference'),
300
-      'multiple values' => CONTENT_HANDLE_CORE,
298
+        'label' => t('Title (no link)'),
299
+        'field types' => array('nodereference'),
300
+        'multiple values' => CONTENT_HANDLE_CORE,
301 301
     ),
302 302
     'full' => array(
303
-      'label' => t('Full node'),
304
-      'field types' => array('nodereference'),
305
-      'multiple values' => CONTENT_HANDLE_CORE,
303
+        'label' => t('Full node'),
304
+        'field types' => array('nodereference'),
305
+        'multiple values' => CONTENT_HANDLE_CORE,
306 306
     ),
307 307
     'teaser' => array(
308
-      'label' => t('Teaser'),
309
-      'field types' => array('nodereference'),
310
-      'multiple values' => CONTENT_HANDLE_CORE,
308
+        'label' => t('Teaser'),
309
+        'field types' => array('nodereference'),
310
+        'multiple values' => CONTENT_HANDLE_CORE,
311 311
     ),
312
-  );
312
+    );
313 313
 }
314 314
 
315 315
 /**
316 316
  * Theme function for 'default' nodereference field formatter.
317 317
  */
318 318
 function theme_nodereference_formatter_default($element) {
319
-  $output = '';
320
-  if (!empty($element['#item']['safe']['nid'])) {
319
+    $output = '';
320
+    if (!empty($element['#item']['safe']['nid'])) {
321 321
     $output = l($element['#item']['safe']['title'], 'node/'. $element['#item']['safe']['nid']);
322 322
     if (!$element['#item']['safe']['status']) {
323
-      $output = '<span class="node-unpublished"> '. t('(Unpublished)') ." $output</span>";
323
+        $output = '<span class="node-unpublished"> '. t('(Unpublished)') ." $output</span>";
324 324
     }
325
-  }
326
-  return $output;
325
+    }
326
+    return $output;
327 327
 }
328 328
 
329 329
 /**
330 330
  * Theme function for 'plain' nodereference field formatter.
331 331
  */
332 332
 function theme_nodereference_formatter_plain($element) {
333
-  $output = '';
334
-  if (!empty($element['#item']['safe']['nid'])) {
333
+    $output = '';
334
+    if (!empty($element['#item']['safe']['nid'])) {
335 335
     $output = check_plain($element['#item']['safe']['title']);
336 336
     if (!$element['#item']['safe']['status']) {
337
-      $output = '<span class="node-unpublished"> '. t('(Unpublished)') ." $output</span>";
337
+        $output = '<span class="node-unpublished"> '. t('(Unpublished)') ." $output</span>";
338
+    }
338 339
     }
339
-  }
340
-  return $output;
340
+    return $output;
341 341
 }
342 342
 
343 343
 /**
344 344
  * Proxy theme function for 'full' and 'teaser' nodereference field formatters.
345 345
  */
346 346
 function theme_nodereference_formatter_full_teaser($element) {
347
-  static $recursion_queue = array();
348
-  $output = '';
349
-  if (!empty($element['#item']['safe']['nid'])) {
347
+    static $recursion_queue = array();
348
+    $output = '';
349
+    if (!empty($element['#item']['safe']['nid'])) {
350 350
     $nid = $element['#item']['safe']['nid'];
351 351
     $node = $element['#node'];
352 352
     $field = content_fields($element['#field_name'], $element['#type_name']);
353 353
     // If no 'referencing node' is set, we are starting a new 'reference thread'
354 354
     if (!isset($node->referencing_node)) {
355
-      $recursion_queue = array();
355
+        $recursion_queue = array();
356 356
     }
357 357
     $recursion_queue[] = $node->nid;
358 358
     if (in_array($nid, $recursion_queue)) {
359
-      // Prevent infinite recursion caused by reference cycles:
360
-      // if the node has already been rendered earlier in this 'thread',
361
-      // we fall back to 'default' (node title) formatter.
362
-      return theme('nodereference_formatter_default', $element);
359
+        // Prevent infinite recursion caused by reference cycles:
360
+        // if the node has already been rendered earlier in this 'thread',
361
+        // we fall back to 'default' (node title) formatter.
362
+        return theme('nodereference_formatter_default', $element);
363 363
     }
364 364
     if ($referenced_node = node_load($nid)) {
365
-      $referenced_node->referencing_node = $node;
366
-      $referenced_node->referencing_field = $field;
367
-      $output = node_view($referenced_node, $element['#formatter'] == 'teaser');
365
+        $referenced_node->referencing_node = $node;
366
+        $referenced_node->referencing_field = $field;
367
+        $output = node_view($referenced_node, $element['#formatter'] == 'teaser');
368
+    }
368 369
     }
369
-  }
370
-  return $output;
370
+    return $output;
371 371
 }
372 372
 
373 373
 /**
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
  * Store node titles collected in the curent request.
377 377
  */
378 378
 function _nodereference_titles($nid, $known_title = NULL) {
379
-  static $titles = array();
380
-  if (!isset($titles[$nid])) {
379
+    static $titles = array();
380
+    if (!isset($titles[$nid])) {
381 381
     $title = $known_title ? $known_title : db_result(db_query(db_rewrite_sql("SELECT n.title FROM {node} n WHERE n.nid=%d"), $nid));
382 382
     $titles[$nid] = $title ? $title : '';
383
-  }
384
-  return $titles[$nid];
383
+    }
384
+    return $titles[$nid];
385 385
 }
386 386
 
387 387
 /**
@@ -399,32 +399,32 @@  discard block
 block discarded – undo
399 399
  * differently.
400 400
  */
401 401
 function nodereference_widget_info() {
402
-  return array(
402
+    return array(
403 403
     'nodereference_select' => array(
404
-      'label' => t('Select list'),
405
-      'field types' => array('nodereference'),
406
-      'multiple values' => CONTENT_HANDLE_MODULE,
407
-      'callbacks' => array(
404
+        'label' => t('Select list'),
405
+        'field types' => array('nodereference'),
406
+        'multiple values' => CONTENT_HANDLE_MODULE,
407
+        'callbacks' => array(
408 408
         'default value' => CONTENT_CALLBACK_DEFAULT,
409
-      ),
409
+        ),
410 410
     ),
411 411
     'nodereference_buttons' => array(
412
-      'label' => t('Check boxes/radio buttons'),
413
-      'field types' => array('nodereference'),
414
-      'multiple values' => CONTENT_HANDLE_MODULE,
415
-      'callbacks' => array(
412
+        'label' => t('Check boxes/radio buttons'),
413
+        'field types' => array('nodereference'),
414
+        'multiple values' => CONTENT_HANDLE_MODULE,
415
+        'callbacks' => array(
416 416
         'default value' => CONTENT_CALLBACK_DEFAULT,
417
-      ),
417
+        ),
418 418
     ),
419 419
     'nodereference_autocomplete' => array(
420
-      'label' => t('Autocomplete text field'),
421
-      'field types' => array('nodereference'),
422
-      'multiple values' => CONTENT_HANDLE_CORE,
423
-      'callbacks' => array(
420
+        'label' => t('Autocomplete text field'),
421
+        'field types' => array('nodereference'),
422
+        'multiple values' => CONTENT_HANDLE_CORE,
423
+        'callbacks' => array(
424 424
         'default value' => CONTENT_CALLBACK_DEFAULT,
425
-      ),
425
+        ),
426 426
     ),
427
-  );
427
+    );
428 428
 }
429 429
 
430 430
 /**
@@ -440,23 +440,23 @@  discard block
 block discarded – undo
440 440
  * (see nodereference and userreference).
441 441
  */
442 442
 function nodereference_elements() {
443
-  return array(
443
+    return array(
444 444
     'nodereference_select' => array(
445
-      '#input' => TRUE,
446
-      '#columns' => array('uid'), '#delta' => 0,
447
-      '#process' => array('nodereference_select_process'),
445
+        '#input' => TRUE,
446
+        '#columns' => array('uid'), '#delta' => 0,
447
+        '#process' => array('nodereference_select_process'),
448 448
     ),
449 449
     'nodereference_buttons' => array(
450
-      '#input' => TRUE,
451
-      '#columns' => array('uid'), '#delta' => 0,
452
-      '#process' => array('nodereference_buttons_process'),
450
+        '#input' => TRUE,
451
+        '#columns' => array('uid'), '#delta' => 0,
452
+        '#process' => array('nodereference_buttons_process'),
453 453
     ),
454 454
     'nodereference_autocomplete' => array(
455
-      '#input' => TRUE,
456
-      '#columns' => array('name'), '#delta' => 0,
457
-      '#process' => array('nodereference_autocomplete_process'),
458
-      '#autocomplete_path' => FALSE,
459
-      ),
455
+        '#input' => TRUE,
456
+        '#columns' => array('name'), '#delta' => 0,
457
+        '#process' => array('nodereference_autocomplete_process'),
458
+        '#autocomplete_path' => FALSE,
459
+        ),
460 460
     );
461 461
 }
462 462
 
@@ -464,39 +464,39 @@  discard block
 block discarded – undo
464 464
  * Implementation of hook_widget_settings().
465 465
  */
466 466
 function nodereference_widget_settings($op, $widget) {
467
-  switch ($op) {
467
+    switch ($op) {
468 468
     case 'form':
469 469
       $form = array();
470
-      $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains';
471
-      $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
472
-      if ($widget['type'] == 'nodereference_autocomplete') {
470
+        $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains';
471
+        $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
472
+        if ($widget['type'] == 'nodereference_autocomplete') {
473 473
         $form['autocomplete_match'] = array(
474
-          '#type' => 'select',
475
-          '#title' => t('Autocomplete matching'),
476
-          '#default_value' => $match,
477
-          '#options' => array(
474
+            '#type' => 'select',
475
+            '#title' => t('Autocomplete matching'),
476
+            '#default_value' => $match,
477
+            '#options' => array(
478 478
             'starts_with' => t('Starts with'),
479 479
             'contains' => t('Contains'),
480
-          ),
481
-          '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'),
480
+            ),
481
+            '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'),
482 482
         );
483 483
         $form['size'] = array(
484
-          '#type' => 'textfield',
485
-          '#title' => t('Size of textfield'),
486
-          '#default_value' => $size,
487
-          '#element_validate' => array('_element_validate_integer_positive'),
488
-          '#required' => TRUE,
484
+            '#type' => 'textfield',
485
+            '#title' => t('Size of textfield'),
486
+            '#default_value' => $size,
487
+            '#element_validate' => array('_element_validate_integer_positive'),
488
+            '#required' => TRUE,
489 489
         );
490
-      }
491
-      else {
490
+        }
491
+        else {
492 492
         $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match);
493 493
         $form['size'] = array('#type' => 'hidden', '#value' => $size);
494
-      }
495
-      return $form;
494
+        }
495
+        return $form;
496 496
 
497 497
     case 'save':
498 498
       return array('autocomplete_match', 'size');
499
-  }
499
+    }
500 500
 }
501 501
 
502 502
 /**
@@ -531,30 +531,30 @@  discard block
 block discarded – undo
531 531
  *   the form item for a single element for this field
532 532
  */
533 533
 function nodereference_widget(&$form, &$form_state, $field, $items, $delta = 0) {
534
-  switch ($field['widget']['type']) {
534
+    switch ($field['widget']['type']) {
535 535
     case 'nodereference_select':
536 536
       $element = array(
537 537
         '#type' => 'nodereference_select',
538 538
         '#default_value' => $items,
539
-      );
540
-      break;
539
+        );
540
+        break;
541 541
 
542 542
     case 'nodereference_buttons':
543 543
       $element = array(
544 544
         '#type' => 'nodereference_buttons',
545 545
         '#default_value' => $items,
546
-      );
547
-      break;
546
+        );
547
+        break;
548 548
 
549 549
     case 'nodereference_autocomplete':
550 550
       $element = array(
551 551
         '#type' => 'nodereference_autocomplete',
552 552
         '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
553 553
         '#value_callback' => 'nodereference_autocomplete_value',
554
-      );
555
-      break;
556
-  }
557
-  return $element;
554
+        );
555
+        break;
556
+    }
557
+    return $element;
558 558
 }
559 559
 
560 560
 /**
@@ -563,14 +563,14 @@  discard block
 block discarded – undo
563 563
  * Substitute in the node title for the node nid.
564 564
  */
565 565
 function nodereference_autocomplete_value($element, $edit = FALSE) {
566
-  $field_key  = $element['#columns'][0];
567
-  if (!empty($element['#default_value'][$field_key])) {
566
+    $field_key  = $element['#columns'][0];
567
+    if (!empty($element['#default_value'][$field_key])) {
568 568
     $nid = $element['#default_value'][$field_key];
569 569
     $value = db_result(db_query(db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.nid = %d'), $nid));
570 570
     $value .= ' [nid:'. $nid .']';
571 571
     return array($field_key => $value);
572
-  }
573
-  return array($field_key => NULL);
572
+    }
573
+    return array($field_key => NULL);
574 574
 }
575 575
 
576 576
 /**
@@ -582,12 +582,12 @@  discard block
 block discarded – undo
582 582
  * The $fields array is in $form['#field_info'][$element['#field_name']].
583 583
  */
584 584
 function nodereference_select_process($element, $edit, $form_state, $form) {
585
-  // The nodereference_select widget doesn't need to create its own
586
-  // element, it can wrap around the optionwidgets_select element.
587
-  // This will create a new, nested instance of the field.
588
-  // Add a validation step where the value can be unwrapped.
589
-  $field_key  = $element['#columns'][0];
590
-  $element[$field_key] = array(
585
+    // The nodereference_select widget doesn't need to create its own
586
+    // element, it can wrap around the optionwidgets_select element.
587
+    // This will create a new, nested instance of the field.
588
+    // Add a validation step where the value can be unwrapped.
589
+    $field_key  = $element['#columns'][0];
590
+    $element[$field_key] = array(
591 591
     '#type' => 'optionwidgets_select',
592 592
     '#default_value' => isset($element['#value']) ? $element['#value'] : '',
593 593
     // The following values were set by the content module and need
@@ -599,12 +599,12 @@  discard block
 block discarded – undo
599 599
     '#type_name' => $element['#type_name'],
600 600
     '#delta' => $element['#delta'],
601 601
     '#columns' => $element['#columns'],
602
-  );
603
-  if (empty($element[$field_key]['#element_validate'])) {
602
+    );
603
+    if (empty($element[$field_key]['#element_validate'])) {
604 604
     $element[$field_key]['#element_validate'] = array();
605
-  }
606
-  array_unshift($element[$field_key]['#element_validate'], 'nodereference_optionwidgets_validate');
607
-  return $element;
605
+    }
606
+    array_unshift($element[$field_key]['#element_validate'], 'nodereference_optionwidgets_validate');
607
+    return $element;
608 608
 }
609 609
 
610 610
 /**
@@ -616,12 +616,12 @@  discard block
 block discarded – undo
616 616
  * The $fields array is in $form['#field_info'][$element['#field_name']].
617 617
  */
618 618
 function nodereference_buttons_process($element, $edit, $form_state, $form) {
619
-  // The nodereference_select widget doesn't need to create its own
620
-  // element, it can wrap around the optionwidgets_select element.
621
-  // This will create a new, nested instance of the field.
622
-  // Add a validation step where the value can be unwrapped.
623
-  $field_key  = $element['#columns'][0];
624
-  $element[$field_key] = array(
619
+    // The nodereference_select widget doesn't need to create its own
620
+    // element, it can wrap around the optionwidgets_select element.
621
+    // This will create a new, nested instance of the field.
622
+    // Add a validation step where the value can be unwrapped.
623
+    $field_key  = $element['#columns'][0];
624
+    $element[$field_key] = array(
625 625
     '#type' => 'optionwidgets_buttons',
626 626
     '#default_value' => isset($element['#value']) ? $element['#value'] : '',
627 627
     // The following values were set by the content module and need
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
     '#type_name' => $element['#type_name'],
634 634
     '#delta' => $element['#delta'],
635 635
     '#columns' => $element['#columns'],
636
-  );
637
-  if (empty($element[$field_key]['#element_validate'])) {
636
+    );
637
+    if (empty($element[$field_key]['#element_validate'])) {
638 638
     $element[$field_key]['#element_validate'] = array();
639
-  }
640
-  array_unshift($element[$field_key]['#element_validate'], 'nodereference_optionwidgets_validate');
641
-  return $element;
639
+    }
640
+    array_unshift($element[$field_key]['#element_validate'], 'nodereference_optionwidgets_validate');
641
+    return $element;
642 642
 }
643 643
 
644 644
 /**
@@ -650,13 +650,13 @@  discard block
 block discarded – undo
650 650
  */
651 651
 function nodereference_autocomplete_process($element, $edit, $form_state, $form) {
652 652
 
653
-  // The nodereference autocomplete widget doesn't need to create its own
654
-  // element, it can wrap around the text_textfield element and add an autocomplete
655
-  // path and some extra processing to it.
656
-  // Add a validation step where the value can be unwrapped.
657
-  $field_key  = $element['#columns'][0];
653
+    // The nodereference autocomplete widget doesn't need to create its own
654
+    // element, it can wrap around the text_textfield element and add an autocomplete
655
+    // path and some extra processing to it.
656
+    // Add a validation step where the value can be unwrapped.
657
+    $field_key  = $element['#columns'][0];
658 658
 
659
-  $element[$field_key] = array(
659
+    $element[$field_key] = array(
660 660
     '#type' => 'text_textfield',
661 661
     '#default_value' => isset($element['#value']) ? $element['#value'] : '',
662 662
     '#autocomplete_path' => 'nodereference/autocomplete/'. $element['#field_name'],
@@ -669,20 +669,20 @@  discard block
 block discarded – undo
669 669
     '#type_name' => $element['#type_name'],
670 670
     '#delta' => $element['#delta'],
671 671
     '#columns' => $element['#columns'],
672
-  );
673
-  if (empty($element[$field_key]['#element_validate'])) {
672
+    );
673
+    if (empty($element[$field_key]['#element_validate'])) {
674 674
     $element[$field_key]['#element_validate'] = array();
675
-  }
676
-  array_unshift($element[$field_key]['#element_validate'], 'nodereference_autocomplete_validate');
675
+    }
676
+    array_unshift($element[$field_key]['#element_validate'], 'nodereference_autocomplete_validate');
677 677
 
678
-  // Used so that hook_field('validate') knows where to flag an error.
679
-  $element['_error_element'] = array(
678
+    // Used so that hook_field('validate') knows where to flag an error.
679
+    $element['_error_element'] = array(
680 680
     '#type' => 'value',
681 681
     // Wrapping the element around a text_textfield element creates a
682 682
     // nested element, so the final id will look like 'field-name-0-nid-nid'.
683 683
     '#value' => implode('][', array_merge($element['#parents'], array($field_key, $field_key))),
684
-  );
685
-  return $element;
684
+    );
685
+    return $element;
686 686
 }
687 687
 
688 688
 /**
@@ -697,20 +697,20 @@  discard block
 block discarded – undo
697 697
  * like optionwidgets are using #element_validate to alter the value.
698 698
  */
699 699
 function nodereference_optionwidgets_validate($element, &$form_state) {
700
-  $field_key  = $element['#columns'][0];
700
+    $field_key  = $element['#columns'][0];
701 701
 
702
-  $value = $form_state['values'];
703
-  $new_parents = array();
704
-  foreach ($element['#parents'] as $parent) {
702
+    $value = $form_state['values'];
703
+    $new_parents = array();
704
+    foreach ($element['#parents'] as $parent) {
705 705
     $value = $value[$parent];
706 706
     // Use === to be sure we get right results if parent is a zero (delta) value.
707 707
     if ($parent === $field_key) {
708
-      $element['#parents'] = $new_parents;
709
-      form_set_value($element, $value, $form_state);
710
-      break;
708
+        $element['#parents'] = $new_parents;
709
+        form_set_value($element, $value, $form_state);
710
+        break;
711 711
     }
712 712
     $new_parents[] = $parent;
713
-  }
713
+    }
714 714
 }
715 715
 
716 716
 /**
@@ -721,52 +721,52 @@  discard block
 block discarded – undo
721 721
  * back to its original location, 'field-name-0-nid'.
722 722
  */
723 723
 function nodereference_autocomplete_validate($element, &$form_state) {
724
-  $field_name = $element['#field_name'];
725
-  $type_name = $element['#type_name'];
726
-  $field = content_fields($field_name, $type_name);
727
-  $field_key  = $element['#columns'][0];
728
-  $delta = $element['#delta'];
729
-  $value = $element['#value'][$field_key];
730
-  $nid = NULL;
731
-  if (!empty($value)) {
724
+    $field_name = $element['#field_name'];
725
+    $type_name = $element['#type_name'];
726
+    $field = content_fields($field_name, $type_name);
727
+    $field_key  = $element['#columns'][0];
728
+    $delta = $element['#delta'];
729
+    $value = $element['#value'][$field_key];
730
+    $nid = NULL;
731
+    if (!empty($value)) {
732 732
     preg_match('/^(?:\s*|(.*) )?\[\s*nid\s*:\s*(\d+)\s*\]$/', $value, $matches);
733 733
     if (!empty($matches)) {
734
-      // Explicit [nid:n].
735
-      list(, $title, $nid) = $matches;
736
-      if (!empty($title) && ($n = node_load($nid)) && trim($title) != trim($n->title)) {
734
+        // Explicit [nid:n].
735
+        list(, $title, $nid) = $matches;
736
+        if (!empty($title) && ($n = node_load($nid)) && trim($title) != trim($n->title)) {
737 737
         form_error($element[$field_key], t('%name: title mismatch. Please check your selection.', array('%name' => t($field['widget']['label']))));
738
-      }
738
+        }
739 739
     }
740 740
     else {
741
-      // No explicit nid.
742
-      $reference = _nodereference_potential_references($field, $value, 'equals', NULL, 1);
743
-      if (empty($reference)) {
741
+        // No explicit nid.
742
+        $reference = _nodereference_potential_references($field, $value, 'equals', NULL, 1);
743
+        if (empty($reference)) {
744 744
         form_error($element[$field_key], t('%name: found no valid post with that title.', array('%name' => t($field['widget']['label']))));
745
-      }
746
-      else {
745
+        }
746
+        else {
747 747
         // TODO:
748 748
         // the best thing would be to present the user with an additional form,
749 749
         // allowing the user to choose between valid candidates with the same title
750 750
         // ATM, we pick the first matching candidate...
751 751
         $nid = key($reference);
752
-      }
752
+        }
753 753
     }
754
-  }
755
-  form_set_value($element, $nid, $form_state);
754
+    }
755
+    form_set_value($element, $nid, $form_state);
756 756
 }
757 757
 
758 758
 /**
759 759
  * Implementation of hook_allowed_values().
760 760
  */
761 761
 function nodereference_allowed_values($field) {
762
-  $references = _nodereference_potential_references($field);
762
+    $references = _nodereference_potential_references($field);
763 763
 
764
-  $options = array();
765
-  foreach ($references as $key => $value) {
764
+    $options = array();
765
+    foreach ($references as $key => $value) {
766 766
     $options[$key] = $value['rendered'];
767
-  }
767
+    }
768 768
 
769
-  return $options;
769
+    return $options;
770 770
 }
771 771
 
772 772
 /**
@@ -802,26 +802,26 @@  discard block
 block discarded – undo
802 802
  *   )
803 803
  */
804 804
 function _nodereference_potential_references($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) {
805
-  static $results = array();
805
+    static $results = array();
806 806
 
807
-  // Create unique id for static cache.
808
-  $cid = $field['field_name'] .':'. $match .':'. ($string !== '' ? $string : implode('-', $ids)) .':'. $limit;
809
-  if (!isset($results[$cid])) {
807
+    // Create unique id for static cache.
808
+    $cid = $field['field_name'] .':'. $match .':'. ($string !== '' ? $string : implode('-', $ids)) .':'. $limit;
809
+    if (!isset($results[$cid])) {
810 810
     $references = FALSE;
811 811
     if (module_exists('views') && !empty($field['advanced_view']) && $field['advanced_view'] != '--') {
812
-      $references = _nodereference_potential_references_views($field, $string, $match, $ids, $limit);
812
+        $references = _nodereference_potential_references_views($field, $string, $match, $ids, $limit);
813 813
     }
814 814
     // If the view doesn't exist, we got FALSE, and fallback to the regular 'standard mode'.
815 815
 
816 816
     if ($references === FALSE) {
817
-      $references = _nodereference_potential_references_standard($field, $string, $match, $ids, $limit);
817
+        $references = _nodereference_potential_references_standard($field, $string, $match, $ids, $limit);
818 818
     }
819 819
 
820 820
     // Store the results.
821 821
     $results[$cid] = !empty($references) ? $references : array();
822
-  }
822
+    }
823 823
 
824
-  return $results[$cid];
824
+    return $results[$cid];
825 825
 }
826 826
 
827 827
 /**
@@ -829,9 +829,9 @@  discard block
 block discarded – undo
829 829
  * case of Views-defined referenceable nodes.
830 830
  */
831 831
 function _nodereference_potential_references_views($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) {
832
-  $view_name = $field['advanced_view'];
832
+    $view_name = $field['advanced_view'];
833 833
 
834
-  if ($view = views_get_view($view_name)) {
834
+    if ($view = views_get_view($view_name)) {
835 835
     // We add a display, and let it derive from the 'default' display.
836 836
     // TODO: We should let the user pick a display in the fields settings - sort of requires AHAH...
837 837
     $display = $view->add_display('content_references');
@@ -848,12 +848,12 @@  discard block
 block discarded – undo
848 848
     // Additional options to let content_plugin_display_references::query()
849 849
     // narrow the results.
850 850
     $options = array(
851
-      'table' => 'node',
852
-      'field_string' => 'title',
853
-      'string' => $string,
854
-      'match' => $match,
855
-      'field_id' => 'nid',
856
-      'ids' => $ids,
851
+        'table' => 'node',
852
+        'field_string' => 'title',
853
+        'string' => $string,
854
+        'match' => $match,
855
+        'field_id' => 'nid',
856
+        'ids' => $ids,
857 857
     );
858 858
     $view->display_handler->set_option('content_options', $options);
859 859
 
@@ -866,26 +866,26 @@  discard block
 block discarded – undo
866 866
 
867 867
     // Get arguments for the view.
868 868
     if (!empty($field['advanced_view_args'])) {
869
-      // TODO: Support Tokens using token.module ?
870
-      $view_args = array_map('trim', explode(',', $field['advanced_view_args']));
869
+        // TODO: Support Tokens using token.module ?
870
+        $view_args = array_map('trim', explode(',', $field['advanced_view_args']));
871 871
     }
872 872
     else {
873
-      $view_args = array();
873
+        $view_args = array();
874 874
     }
875 875
 
876 876
     // We do need title field, so add it if not present (unlikely, but...)
877 877
     $fields = $view->get_items('field', $display);
878 878
     if (!isset($fields['title'])) {
879
-      $view->add_item($display, 'field', 'node', 'title');
879
+        $view->add_item($display, 'field', 'node', 'title');
880 880
     }
881 881
 
882 882
     // If not set, make all fields inline and define a separator.
883 883
     $options = $view->display_handler->get_option('row_options');
884 884
     if (empty($options['inline'])) {
885
-      $options['inline'] = drupal_map_assoc(array_keys($view->get_items('field', $display)));
885
+        $options['inline'] = drupal_map_assoc(array_keys($view->get_items('field', $display)));
886 886
     }
887 887
     if (empty($options['separator'])) {
888
-      $options['separator'] = '-';
888
+        $options['separator'] = '-';
889 889
     }
890 890
     $view->display_handler->set_option('row_options', $options);
891 891
 
@@ -894,12 +894,12 @@  discard block
 block discarded – undo
894 894
 
895 895
     // Get the results.
896 896
     $result = $view->execute_display($display, $view_args);
897
-  }
898
-  else {
897
+    }
898
+    else {
899 899
     $result = FALSE;
900
-  }
900
+    }
901 901
 
902
-  return $result;
902
+    return $result;
903 903
 }
904 904
 
905 905
 /**
@@ -907,50 +907,50 @@  discard block
 block discarded – undo
907 907
  * referenceable nodes defined by content types.
908 908
  */
909 909
 function _nodereference_potential_references_standard($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) {
910
-  $related_types = array();
911
-  $where = array();
912
-  $args = array();
910
+    $related_types = array();
911
+    $where = array();
912
+    $args = array();
913 913
 
914
-  if (is_array($field['referenceable_types'])) {
914
+    if (is_array($field['referenceable_types'])) {
915 915
     foreach (array_filter($field['referenceable_types']) as $related_type) {
916
-      $related_types[] = "n.type = '%s'";
917
-      $args[] = $related_type;
916
+        $related_types[] = "n.type = '%s'";
917
+        $args[] = $related_type;
918
+    }
918 919
     }
919
-  }
920 920
 
921
-  $where[] = implode(' OR ', $related_types);
921
+    $where[] = implode(' OR ', $related_types);
922 922
 
923
-  if (!count($related_types)) {
923
+    if (!count($related_types)) {
924 924
     return array();
925
-  }
925
+    }
926 926
 
927
-  if ($string !== '') {
927
+    if ($string !== '') {
928 928
     $like = $GLOBALS["db_type"] == 'pgsql' ? "ILIKE" : "LIKE";
929 929
     $match_clauses = array(
930
-      'contains' => "$like '%%%s%%'",
931
-      'equals' => "= '%s'",
932
-      'starts_with' => "$like '%s%%'",
930
+        'contains' => "$like '%%%s%%'",
931
+        'equals' => "= '%s'",
932
+        'starts_with' => "$like '%s%%'",
933 933
     );
934 934
     $where[] = 'n.title '. (isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']);
935 935
     $args[] = $string;
936
-  }
937
-  elseif ($ids) {
936
+    }
937
+    elseif ($ids) {
938 938
     $where[] = 'n.nid IN (' . db_placeholders($ids) . ')';
939 939
     $args = array_merge($args, $ids);
940
-  }
940
+    }
941 941
 
942
-  $where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : '';
943
-  $sql = db_rewrite_sql("SELECT n.nid, n.title AS node_title, n.type AS node_type FROM {node} n $where_clause ORDER BY n.title, n.type");
944
-  $result = $limit ? db_query_range($sql, $args, 0, $limit) : db_query($sql, $args);
945
-  $references = array();
946
-  while ($node = db_fetch_object($result)) {
942
+    $where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : '';
943
+    $sql = db_rewrite_sql("SELECT n.nid, n.title AS node_title, n.type AS node_type FROM {node} n $where_clause ORDER BY n.title, n.type");
944
+    $result = $limit ? db_query_range($sql, $args, 0, $limit) : db_query($sql, $args);
945
+    $references = array();
946
+    while ($node = db_fetch_object($result)) {
947 947
     $references[$node->nid] = array(
948
-      'title' => $node->node_title,
949
-      'rendered' => check_plain($node->node_title),
948
+        'title' => $node->node_title,
949
+        'rendered' => check_plain($node->node_title),
950 950
     );
951
-  }
951
+    }
952 952
 
953
-  return $references;
953
+    return $references;
954 954
 }
955 955
 
956 956
 /**
@@ -960,31 +960,31 @@  discard block
 block discarded – undo
960 960
  * a user has edit but not view access.
961 961
  */
962 962
 function nodereference_autocomplete_access($field_name) {
963
-  return user_access('access content') && ($field = content_fields($field_name)) && isset($field['field_name']) && content_access('view', $field) && content_access('edit', $field);
963
+    return user_access('access content') && ($field = content_fields($field_name)) && isset($field['field_name']) && content_access('view', $field) && content_access('edit', $field);
964 964
 }
965 965
 
966 966
 /**
967 967
  * Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing users
968 968
  */
969 969
 function nodereference_autocomplete($field_name, $string = '') {
970
-  $fields = content_fields();
971
-  $field = $fields[$field_name];
972
-  $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains';
973
-  $matches = array();
970
+    $fields = content_fields();
971
+    $field = $fields[$field_name];
972
+    $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains';
973
+    $matches = array();
974 974
 
975
-  $references = _nodereference_potential_references($field, $string, $match, array(), 10);
976
-  foreach ($references as $id => $row) {
975
+    $references = _nodereference_potential_references($field, $string, $match, array(), 10);
976
+    foreach ($references as $id => $row) {
977 977
     // Add a class wrapper for a few required CSS overrides.
978 978
     $matches[$row['title'] ." [nid:$id]"] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>';
979
-  }
980
-  drupal_json($matches);
979
+    }
980
+    drupal_json($matches);
981 981
 }
982 982
 
983 983
 /**
984 984
  * Implementation of hook_node_types.
985 985
  */
986 986
 function nodereference_node_type($op, $info) {
987
-  switch ($op) {
987
+    switch ($op) {
988 988
     case 'update':
989 989
       // Reflect type name changes to the 'referenceable types' settings.
990 990
       if (!empty($info->old_type) && $info->old_type != $info->type) {
@@ -993,22 +993,22 @@  discard block
 block discarded – undo
993 993
         $fields = content_fields();
994 994
         $rebuild = FALSE;
995 995
         foreach ($fields as $field_name => $field) {
996
-          if ($field['type'] == 'nodereference' && isset($field['referenceable_types'][$info->old_type])) {
996
+            if ($field['type'] == 'nodereference' && isset($field['referenceable_types'][$info->old_type])) {
997 997
             $field['referenceable_types'][$info->type] = empty($field['referenceable_types'][$info->old_type]) ? 0 : $info->type;
998 998
             unset($field['referenceable_types'][$info->old_type]);
999 999
             content_field_instance_update($field, FALSE);
1000 1000
             $rebuild = TRUE;
1001
-          }
1001
+            }
1002 1002
         }
1003 1003
 
1004 1004
         // Clear caches and rebuild menu only if any field has been updated.
1005 1005
         if ($rebuild) {
1006
-          content_clear_type_cache(TRUE);
1007
-          menu_rebuild();
1006
+            content_clear_type_cache(TRUE);
1007
+            menu_rebuild();
1008
+        }
1008 1009
         }
1009
-      }
1010
-      break;
1011
-  }
1010
+        break;
1011
+    }
1012 1012
 }
1013 1013
 
1014 1014
 /**
@@ -1018,16 +1018,16 @@  discard block
 block discarded – undo
1018 1018
  * nodereference field with the 'full node' / 'teaser' formatters.
1019 1019
  */
1020 1020
 function nodereference_preprocess_node(&$vars) {
1021
-  // The 'referencing_field' attribute of the node is added by the 'teaser'
1022
-  // and 'full node' formatters.
1023
-  if (!empty($vars['node']->referencing_field)) {
1021
+    // The 'referencing_field' attribute of the node is added by the 'teaser'
1022
+    // and 'full node' formatters.
1023
+    if (!empty($vars['node']->referencing_field)) {
1024 1024
     $node = $vars['node'];
1025 1025
     $field = $node->referencing_field;
1026 1026
     $vars['template_files'][] = 'node-nodereference';
1027 1027
     $vars['template_files'][] = 'node-nodereference-'. $field['field_name'];
1028 1028
     $vars['template_files'][] = 'node-nodereference-'. $node->type;
1029 1029
     $vars['template_files'][] = 'node-nodereference-'. $field['field_name'] .'-'. $node->type;
1030
-  }
1030
+    }
1031 1031
 }
1032 1032
 
1033 1033
 /**
@@ -1042,13 +1042,13 @@  discard block
 block discarded – undo
1042 1042
  * $element['#delta]  is the position of this element in the group
1043 1043
  */
1044 1044
 function theme_nodereference_select($element) {
1045
-  return $element['#children'];
1045
+    return $element['#children'];
1046 1046
 }
1047 1047
 
1048 1048
 function theme_nodereference_buttons($element) {
1049
-  return $element['#children'];
1049
+    return $element['#children'];
1050 1050
 }
1051 1051
 
1052 1052
 function theme_nodereference_autocomplete($element) {
1053
-  return $element['#children'];
1053
+    return $element['#children'];
1054 1054
 }
Please login to merge, or discard this patch.