Completed
Pull Request — master (#2592)
by Kevin
11:52
created
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.
drupal/sites/default/boinc/modules/contrib/cck/modules/number/number.module 1 patch
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * Implementation of hook_theme().
11 11
  */
12 12
 function number_theme() {
13
-  return array(
13
+    return array(
14 14
     'number' => array('arguments' => array('element' => NULL)),
15 15
     'number_formatter_default' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'),
16 16
     'number_formatter_us_0' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'),
@@ -23,156 +23,156 @@  discard block
 block discarded – undo
23 23
     'number_formatter_fr_1' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'),
24 24
     'number_formatter_fr_2' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'),
25 25
     'number_formatter_unformatted' => array('arguments' => array('element' => NULL)),
26
-  );
26
+    );
27 27
 }
28 28
 
29 29
 /**
30 30
  * Implementation of hook_field_info().
31 31
  */
32 32
 function number_field_info() {
33
-  return array(
33
+    return array(
34 34
     'number_integer' => array(
35
-      'label' => t('Integer'),
36
-      'description' => t('Store a number in the database as an integer.'),
35
+        'label' => t('Integer'),
36
+        'description' => t('Store a number in the database as an integer.'),
37 37
 //      'content_icon' => 'icon_content_number.png',
38 38
     ),
39 39
     'number_decimal' => array(
40
-      'label' => t('Decimal'),
41
-      'description' => t('Store a number in the database in a fixed decimal format.'),
40
+        'label' => t('Decimal'),
41
+        'description' => t('Store a number in the database in a fixed decimal format.'),
42 42
 //      'content_icon' => 'icon_content_number.png',
43 43
     ),
44 44
     'number_float' => array(
45
-      'label' => t('Float'),
46
-      'description' => t('Store a number in the database in a floating point format.'),
45
+        'label' => t('Float'),
46
+        'description' => t('Store a number in the database in a floating point format.'),
47 47
 //      'content_icon' => 'icon_content_number.png',
48 48
     ),
49
-  );
49
+    );
50 50
 }
51 51
 
52 52
 /**
53 53
  * Implementation of hook_field_settings().
54 54
  */
55 55
 function number_field_settings($op, $field) {
56
-  switch ($op) {
56
+    switch ($op) {
57 57
     case 'form':
58 58
       $form = array();
59
-      $form['min'] = array(
59
+        $form['min'] = array(
60 60
         '#type' => 'textfield',
61 61
         '#title' => t('Minimum'),
62 62
         '#element_validate' => array('_element_validate_number'),
63 63
         '#default_value' => is_numeric($field['min']) ? $field['min'] : '',
64
-      );
65
-      $form['max'] = array(
64
+        );
65
+        $form['max'] = array(
66 66
         '#type' => 'textfield',
67 67
         '#title' => t('Maximum'),
68 68
         '#element_validate' => array('_element_validate_number'),
69 69
         '#default_value' => is_numeric($field['max']) ? $field['max'] : '',
70
-      );
71
-      if ($field['type'] == 'number_decimal') {
70
+        );
71
+        if ($field['type'] == 'number_decimal') {
72 72
         $form['precision'] = array(
73
-          '#type' => 'select',
74
-          '#options' => drupal_map_assoc(range(10, 32)),
75
-          '#title' => t('Precision'),
76
-          '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'),
77
-          '#default_value' => is_numeric($field['precision']) ? $field['precision'] : 10,
73
+            '#type' => 'select',
74
+            '#options' => drupal_map_assoc(range(10, 32)),
75
+            '#title' => t('Precision'),
76
+            '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'),
77
+            '#default_value' => is_numeric($field['precision']) ? $field['precision'] : 10,
78 78
         );
79 79
         $form['scale'] = array(
80
-          '#type' => 'select',
81
-          '#options' => drupal_map_assoc(range(0, 10)),
82
-          '#title' => t('Scale'),
83
-          '#description' => t('The number of digits to the right of the decimal.'),
84
-          '#default_value' => is_numeric($field['scale']) ? $field['scale'] : 2,
80
+            '#type' => 'select',
81
+            '#options' => drupal_map_assoc(range(0, 10)),
82
+            '#title' => t('Scale'),
83
+            '#description' => t('The number of digits to the right of the decimal.'),
84
+            '#default_value' => is_numeric($field['scale']) ? $field['scale'] : 2,
85 85
         );
86 86
         $form['decimal'] = array(
87
-          '#type' => 'select',
88
-          '#options' => array('.' => 'decimal point', ',' => 'comma', ' ' => 'space'),
89
-          '#title' => t('Decimal marker'),
90
-          '#description' => t('The character users will input to mark the decimal point in forms.'),
91
-          '#default_value' => !empty($field['decimal']) ? $field['decimal'] : '.',
87
+            '#type' => 'select',
88
+            '#options' => array('.' => 'decimal point', ',' => 'comma', ' ' => 'space'),
89
+            '#title' => t('Decimal marker'),
90
+            '#description' => t('The character users will input to mark the decimal point in forms.'),
91
+            '#default_value' => !empty($field['decimal']) ? $field['decimal'] : '.',
92 92
         );
93
-      }
94
-      $form['append']['prefix'] = array(
93
+        }
94
+        $form['append']['prefix'] = array(
95 95
         '#type' => 'textfield',
96 96
         '#title' => t('Prefix'),
97 97
         '#size' => 60,
98 98
         '#default_value' => !empty($field['prefix']) ? $field['prefix'] : '',
99 99
         '#description' => t('Define a string that should be prefixed to the value, like $ or €. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'),
100
-      );
101
-      $form['append']['suffix'] = array(
100
+        );
101
+        $form['append']['suffix'] = array(
102 102
         '#type' => 'textfield',
103 103
         '#title' => t('Suffix'),
104 104
         '#size' => 60,
105 105
         '#default_value' => !empty($field['suffix']) ? $field['suffix'] : '',
106 106
         '#description' => t('Define a string that should suffixed to the value, like m², m/s², kb/s. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'),
107
-      );
108
-      $form['allowed_values_fieldset'] = array(
107
+        );
108
+        $form['allowed_values_fieldset'] = array(
109 109
         '#type' => 'fieldset',
110 110
         '#title' => t('Allowed values'),
111 111
         '#collapsible' => TRUE,
112 112
         '#collapsed' => TRUE,
113
-      );
114
-      $form['allowed_values_fieldset']['allowed_values'] = array(
113
+        );
114
+        $form['allowed_values_fieldset']['allowed_values'] = array(
115 115
         '#type' => 'textarea',
116 116
         '#title' => t('Allowed values list'),
117 117
         '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '',
118 118
         '#required' => FALSE,
119 119
         '#rows' => 10,
120 120
         '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())),
121
-      );
122
-      $form['allowed_values_fieldset']['advanced_options'] = array(
121
+        );
122
+        $form['allowed_values_fieldset']['advanced_options'] = array(
123 123
         '#type' => 'fieldset',
124 124
         '#title' => t('PHP code'),
125 125
         '#collapsible' => TRUE,
126 126
         '#collapsed' => empty($field['allowed_values_php']),
127
-      );
128
-      if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
127
+        );
128
+        if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
129 129
         $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array(
130
-          '#type' => 'textarea',
131
-          '#title' => t('Code'),
132
-          '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '',
133
-          '#rows' => 6,
134
-          '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
130
+            '#type' => 'textarea',
131
+            '#title' => t('Code'),
132
+            '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '',
133
+            '#rows' => 6,
134
+            '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
135 135
         );
136
-      }
137
-      else {
136
+        }
137
+        else {
138 138
         $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array(
139
-          '#type' => 'item',
140
-          '#title' => t('Code'),
141
-          '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('&lt;none&gt;'),
142
-          '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'),
139
+            '#type' => 'item',
140
+            '#title' => t('Code'),
141
+            '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('&lt;none&gt;'),
142
+            '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'),
143 143
         );
144
-      }
145
-      return $form;
144
+        }
145
+        return $form;
146 146
 
147 147
     case 'save':
148 148
       $values = array('prefix', 'suffix', 'min', 'max', 'allowed_values', 'allowed_values_php');
149
-      if ($field['type'] == 'number_decimal') {
149
+        if ($field['type'] == 'number_decimal') {
150 150
         $values = array_merge($values, array('precision', 'scale', 'decimal'));
151
-      }
152
-      return $values;
151
+        }
152
+        return $values;
153 153
 
154 154
     case 'database columns':
155 155
       if ($field['type'] == 'number_integer') {
156 156
         return array(
157
-          'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE),
157
+            'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE),
158 158
         );
159
-      }
160
-      if ($field['type'] == 'number_float') {
159
+        }
160
+        if ($field['type'] == 'number_float') {
161 161
         return array(
162
-          'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE),
162
+            'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE),
163 163
         );
164
-      }
165
-      if ($field['type'] == 'number_decimal') {
164
+        }
165
+        if ($field['type'] == 'number_decimal') {
166 166
         $precision = isset($field['precision']) ? $field['precision'] : 10;
167 167
         $scale = isset($field['scale']) ? $field['scale'] : 2;
168 168
         return array(
169
-          'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE),
169
+            'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE),
170 170
         );
171
-      }
171
+        }
172 172
 
173 173
     case 'views data':
174 174
       $allowed_values = content_allowed_values($field);
175
-      if (count($allowed_values)) {
175
+        if (count($allowed_values)) {
176 176
         $data = content_views_field_views_data($field);
177 177
         $db_info = content_database_info($field);
178 178
         $table_alias = content_views_tablename($field);
@@ -188,79 +188,79 @@  discard block
 block discarded – undo
188 188
         $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one';
189 189
         $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE;
190 190
         return $data;
191
-      }
192
-      break;
193
-  }
191
+        }
192
+        break;
193
+    }
194 194
 }
195 195
 
196 196
 function _number_widget_settings_min_validate($element, &$form_state) {
197
-  $value = $form_state['values']['min'];
198
-  if ($value && !is_numeric($value)) {
197
+    $value = $form_state['values']['min'];
198
+    if ($value && !is_numeric($value)) {
199 199
     form_set_error('min', t('"Minimum" must be a number.'));
200
-  }
200
+    }
201 201
 }
202 202
 
203 203
 function _number_widget_settings_max_validate($element, &$form_state) {
204
-  $value = $form_state['values']['max'];
205
-  if ($value && !is_numeric($value)) {
204
+    $value = $form_state['values']['max'];
205
+    if ($value && !is_numeric($value)) {
206 206
     form_set_error('max', t('"Maximum" must be a number.'));
207
-  }
207
+    }
208 208
 }
209 209
 
210 210
 /**
211 211
  * Implementation of hook_field().
212 212
  */
213 213
 function number_field($op, &$node, $field, &$items, $teaser, $page) {
214
-  switch ($op) {
214
+    switch ($op) {
215 215
     case 'validate':
216 216
       $allowed_values = content_allowed_values($field);
217
-      if (is_array($items)) {
217
+        if (is_array($items)) {
218 218
         foreach ($items as $delta => $item) {
219
-          $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
220
-          if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']);
221
-          if ($item['value'] != '') {
219
+            $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
220
+            if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']);
221
+            if ($item['value'] != '') {
222 222
             if (is_numeric($field['min']) && $item['value'] < $field['min']) {
223
-              form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min'])));
223
+                form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min'])));
224 224
             }
225 225
             if (is_numeric($field['max']) && $item['value'] > $field['max']) {
226
-              form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max'])));
226
+                form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max'])));
227 227
             }
228 228
             if (count($allowed_values)) {
229
-              // We cannot use array_key_exists() because allowed values are
230
-              // stored as strings, and we need to compare numeric equality.
231
-              $valid = FALSE;
232
-              foreach ($allowed_values as $kay => $value) {
229
+                // We cannot use array_key_exists() because allowed values are
230
+                // stored as strings, and we need to compare numeric equality.
231
+                $valid = FALSE;
232
+                foreach ($allowed_values as $kay => $value) {
233 233
                 if ((float) $item['value'] == (float) $kay) {
234
-                  $valid = TRUE;
235
-                  break;
234
+                    $valid = TRUE;
235
+                    break;
236 236
                 }
237
-              }
238
-              if (!$valid) {
237
+                }
238
+                if (!$valid) {
239 239
                 form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label']))));
240
-              }
240
+                }
241
+            }
241 242
             }
242
-          }
243 243
         }
244
-      }
245
-      return $items;
246
-  }
244
+        }
245
+        return $items;
246
+    }
247 247
 }
248 248
 
249 249
 /**
250 250
  * Implementation of hook_content_is_empty().
251 251
  */
252 252
 function number_content_is_empty($item, $field) {
253
-  if (empty($item['value']) && (string)$item['value'] !== '0') {
253
+    if (empty($item['value']) && (string)$item['value'] !== '0') {
254 254
     return TRUE;
255
-  }
256
-  return FALSE;
255
+    }
256
+    return FALSE;
257 257
 }
258 258
 
259 259
 /**
260 260
  * Implementation of hook_field_formatter_info().
261 261
  */
262 262
 function number_field_formatter_info() {
263
-  return array(
263
+    return array(
264 264
     'default' => array('label' => '9999',            'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')),
265 265
     'us_0'    => array('label' => '9,999',           'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')),
266 266
     'us_1'    => array('label' => '9,999.9',         'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')),
@@ -272,72 +272,72 @@  discard block
 block discarded – undo
272 272
     'fr_1'    => array('label' => '9 999, 9',        'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')),
273 273
     'fr_2'    => array('label' => '9 999, 99',       'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')),
274 274
     'unformatted' => array('label' => t('unformatted'), 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')),
275
-  );
275
+    );
276 276
 }
277 277
 
278 278
 /**
279 279
  * Proxy theme function for 'unformatted' number field formatter.
280 280
  */
281 281
 function theme_number_formatter_unformatted($element) {
282
-  return $element['#item']['value'];
282
+    return $element['#item']['value'];
283 283
 }
284 284
 
285 285
 /**
286 286
  * Proxy theme function for number field formatters.
287 287
  */
288 288
 function theme_number_formatter_generic($element) {
289
-  $field = content_fields($element['#field_name'], $element['#type_name']);
290
-  $value = $element['#item']['value'];
289
+    $field = content_fields($element['#field_name'], $element['#type_name']);
290
+    $value = $element['#item']['value'];
291 291
 
292
-  if (($allowed_values = content_allowed_values($field))) {
292
+    if (($allowed_values = content_allowed_values($field))) {
293 293
     if (isset($allowed_values[$value]) && $allowed_values[$value] != $value) {
294
-      return $allowed_values[$value];
294
+        return $allowed_values[$value];
295
+    }
295 296
     }
296
-  }
297 297
 
298
-  if (empty($value) && $value !== '0') {
298
+    if (empty($value) && $value !== '0') {
299 299
     return '';
300
-  }
300
+    }
301 301
 
302
-  switch ($element['#formatter']) {
302
+    switch ($element['#formatter']) {
303 303
     case 'us_0':
304 304
       $output = number_format($value, 0, '.', ',');
305
-      break;
305
+        break;
306 306
     case 'us_1':
307 307
       $output = number_format($value, 1, '.', ',');
308
-      break;
308
+        break;
309 309
     case 'us_2':
310 310
       $output = number_format($value, 2, '.', ',');
311
-      break;
311
+        break;
312 312
     case 'be_0':
313 313
       $output = number_format($value, 0, ',', '.');
314
-      break;
314
+        break;
315 315
     case 'be_1':
316 316
       $output = number_format($value, 1, ',', '.');
317
-      break;
317
+        break;
318 318
     case 'be_2':
319 319
       $output = number_format($value, 2, ',', '.');
320
-      break;
320
+        break;
321 321
     case 'fr_0':
322 322
       $output = number_format($value, 0, ', ', ' ');
323
-      break;
323
+        break;
324 324
     case 'fr_1':
325 325
       $output = number_format($value, 1, ', ', ' ');
326
-      break;
326
+        break;
327 327
     case 'fr_2':
328 328
       $output = number_format($value, 2, ', ', ' ');
329
-      break;
329
+        break;
330 330
     default:
331 331
       $output = $value;
332
-      break;
333
-  }
332
+        break;
333
+    }
334 334
 
335
-  $prefixes = isset($field['prefix']) ? array_map('content_filter_xss', explode('|', $field['prefix'])) : array('');
336
-  $suffixes = isset($field['suffix']) ? array_map('content_filter_xss', explode('|', $field['suffix'])) : array('');
337
-  $prefix = (count($prefixes) > 1) ? format_plural($value, $prefixes[0], $prefixes[1]) : $prefixes[0];
338
-  $suffix = (count($suffixes) > 1) ? format_plural($value, $suffixes[0], $suffixes[1]) : $suffixes[0];
335
+    $prefixes = isset($field['prefix']) ? array_map('content_filter_xss', explode('|', $field['prefix'])) : array('');
336
+    $suffixes = isset($field['suffix']) ? array_map('content_filter_xss', explode('|', $field['suffix'])) : array('');
337
+    $prefix = (count($prefixes) > 1) ? format_plural($value, $prefixes[0], $prefixes[1]) : $prefixes[0];
338
+    $suffix = (count($suffixes) > 1) ? format_plural($value, $suffixes[0], $suffixes[1]) : $suffixes[0];
339 339
 
340
-  return $prefix . $output . $suffix;
340
+    return $prefix . $output . $suffix;
341 341
 }
342 342
 
343 343
 /**
@@ -352,16 +352,16 @@  discard block
 block discarded – undo
352 352
  * differently.
353 353
  */
354 354
 function number_widget_info() {
355
-  return array(
355
+    return array(
356 356
     'number' => array(
357
-      'label' => t('Text field'),
358
-      'field types' => array('number_integer', 'number_decimal', 'number_float'),
359
-      'multiple values' => CONTENT_HANDLE_CORE,
360
-      'callbacks' => array(
357
+        'label' => t('Text field'),
358
+        'field types' => array('number_integer', 'number_decimal', 'number_float'),
359
+        'multiple values' => CONTENT_HANDLE_CORE,
360
+        'callbacks' => array(
361 361
         'default value' => CONTENT_CALLBACK_DEFAULT,
362
-      ),
362
+        ),
363 363
     ),
364
-  );
364
+    );
365 365
 }
366 366
 
367 367
 /**
@@ -377,13 +377,13 @@  discard block
 block discarded – undo
377 377
  * the validator can use. The regex can be overridden if necessary.
378 378
  */
379 379
 function number_elements() {
380
-  return array(
380
+    return array(
381 381
     'number' => array(
382
-      '#input' => TRUE,
383
-      '#columns' => array('value'), '#delta' => 0,
384
-      '#process' => array('number_process'),
382
+        '#input' => TRUE,
383
+        '#columns' => array('value'), '#delta' => 0,
384
+        '#process' => array('number_process'),
385 385
     ),
386
-  );
386
+    );
387 387
 }
388 388
 
389 389
 /**
@@ -418,11 +418,11 @@  discard block
 block discarded – undo
418 418
  *   the form item for a single element for this field
419 419
  */
420 420
 function number_widget(&$form, &$form_state, $field, $items, $delta = 0) {
421
-  $element = array(
421
+    $element = array(
422 422
     '#type' => $field['widget']['type'],
423 423
     '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
424
-  );
425
-  return $element;
424
+    );
425
+    return $element;
426 426
 }
427 427
 
428 428
 /**
@@ -434,13 +434,13 @@  discard block
 block discarded – undo
434 434
  * The $fields array is in $form['#field_info'][$element['#field_name']].
435 435
  */
436 436
 function number_process($element, $edit, $form_state, $form) {
437
-  $field_name = $element['#field_name'];
438
-  $field = $form['#field_info'][$field_name];
439
-  $field_key  = $element['#columns'][0];
437
+    $field_name = $element['#field_name'];
438
+    $field = $form['#field_info'][$field_name];
439
+    $field_key  = $element['#columns'][0];
440 440
 
441
-  $value = isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : '';
442
-  $value = isset($field['decimal']) ? str_replace('.', $field['decimal'], $value) : $value;
443
-  $element[$field_key] = array(
441
+    $value = isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : '';
442
+    $value = isset($field['decimal']) ? str_replace('.', $field['decimal'], $value) : $value;
443
+    $element[$field_key] = array(
444 444
     '#type' => 'textfield',
445 445
     '#default_value' => $value,
446 446
     // Need to allow a slightly larger size that the field length to allow
@@ -457,117 +457,117 @@  discard block
 block discarded – undo
457 457
     '#type_name' => $element['#type_name'],
458 458
     '#delta' => $element['#delta'],
459 459
     '#columns' => $element['#columns'],
460
-  );
460
+    );
461 461
 
462
-  $prefixes = array();
463
-  $suffixes = array();
462
+    $prefixes = array();
463
+    $suffixes = array();
464 464
 
465
-  // Make sure we don't wipe out element validation added elsewhere.
466
-  if (empty($element['#element_validate'])) {
465
+    // Make sure we don't wipe out element validation added elsewhere.
466
+    if (empty($element['#element_validate'])) {
467 467
     $element['#element_validate'] = array();
468
-  }
469
-  if (!empty($field['prefix'])) {
468
+    }
469
+    if (!empty($field['prefix'])) {
470 470
     $prefixes = explode('|', $field['prefix']);
471 471
     $element[$field_key]['#field_prefix'] = content_filter_xss(array_pop($prefixes));
472
-  }
473
-  if (!empty($field['suffix'])) {
472
+    }
473
+    if (!empty($field['suffix'])) {
474 474
     $suffixes = explode('|', $field['suffix']);
475 475
     $element[$field_key]['#field_suffix'] = content_filter_xss(array_pop($suffixes));
476
-  }
477
-  switch ($field['type']) {
476
+    }
477
+    switch ($field['type']) {
478 478
     case 'number_float':
479 479
       $element['#element_validate'][] = 'number_float_validate';
480
-      break;
480
+        break;
481 481
     case 'number_integer':
482 482
       $element['#element_validate'][] = 'number_integer_validate';
483
-      break;
483
+        break;
484 484
     case 'number_decimal':
485 485
       $element['#element_validate'][] = 'number_decimal_validate';
486
-      $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.';
487
-      $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10;
488
-      $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2;
489
-      break;
490
-  }
491
-
492
-  // Used so that hook_field('validate') knows where to flag an error.
493
-  $element['_error_element'] = array(
486
+        $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.';
487
+        $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10;
488
+        $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2;
489
+        break;
490
+    }
491
+
492
+    // Used so that hook_field('validate') knows where to flag an error.
493
+    $element['_error_element'] = array(
494 494
     '#type' => 'value',
495 495
     '#value' => implode('][', array_merge($element['#parents'], array($field_key))),
496
-  );
496
+    );
497 497
 
498
-  return $element;
498
+    return $element;
499 499
 }
500 500
 
501 501
 /**
502 502
  * FAPI validation of an individual float element.
503 503
  */
504 504
 function number_float_validate($element, &$form_state) {
505
-  $field_name = $element['#field_name'];
506
-  $type_name = $element['#type_name'];
507
-  $field = content_fields($field_name, $type_name);
508
-  $field_key = $element['#columns'][0];
509
-  $value = $element['#value'][$field_key];
505
+    $field_name = $element['#field_name'];
506
+    $type_name = $element['#type_name'];
507
+    $field = content_fields($field_name, $type_name);
508
+    $field_key = $element['#columns'][0];
509
+    $value = $element['#value'][$field_key];
510 510
 
511
-  if (($element[$field_key]['#required'] || !empty($value))) {
511
+    if (($element[$field_key]['#required'] || !empty($value))) {
512 512
     $start = $value;
513 513
     $value = preg_replace('@[^-0-9\.]@', '', $value);
514 514
     if ($start != $value) {
515
-      $error_field = implode('][', $element['#parents']) .']['. $field_key;
516
-      form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array('%field' => t($field['widget']['label']))));
515
+        $error_field = implode('][', $element['#parents']) .']['. $field_key;
516
+        form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array('%field' => t($field['widget']['label']))));
517 517
     }
518 518
     else {
519
-      form_set_value($element[$field_key], $value, $form_state);
519
+        form_set_value($element[$field_key], $value, $form_state);
520
+    }
520 521
     }
521
-  }
522 522
 }
523 523
 
524 524
 /**
525 525
  * FAPI validation of an individual integer element.
526 526
  */
527 527
 function number_integer_validate($element, &$form_state) {
528
-  $field_name = $element['#field_name'];
529
-  $type_name = $element['#type_name'];
530
-  $field = content_fields($field_name, $type_name);
531
-  $field_key = $element['#columns'][0];
532
-  $value = $element['#value'][$field_key];
528
+    $field_name = $element['#field_name'];
529
+    $type_name = $element['#type_name'];
530
+    $field = content_fields($field_name, $type_name);
531
+    $field_key = $element['#columns'][0];
532
+    $value = $element['#value'][$field_key];
533 533
 
534
-  if (($element[$field_key]['#required'] || !empty($value))) {
534
+    if (($element[$field_key]['#required'] || !empty($value))) {
535 535
     $start = $value;
536 536
     $value = preg_replace('@[^-0-9]@', '', $value);
537 537
     if ($start != $value) {
538
-      $error_field = implode('][', $element['#parents']) .']['. $field_key;
539
-      form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($field['widget']['label']))));
538
+        $error_field = implode('][', $element['#parents']) .']['. $field_key;
539
+        form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($field['widget']['label']))));
540 540
     }
541 541
     else {
542
-      form_set_value($element[$field_key], $value, $form_state);
542
+        form_set_value($element[$field_key], $value, $form_state);
543
+    }
543 544
     }
544
-  }
545 545
 }
546 546
 
547 547
 /**
548 548
  * FAPI validation of an individual decimal element.
549 549
  */
550 550
 function number_decimal_validate($element, &$form_state) {
551
-  $field_name = $element['#field_name'];
552
-  $type_name = $element['#type_name'];
553
-  $field = content_fields($field_name, $type_name);
554
-  $field_key = $element['#columns'][0];
555
-  $value = $element['#value'][$field_key];
551
+    $field_name = $element['#field_name'];
552
+    $type_name = $element['#type_name'];
553
+    $field = content_fields($field_name, $type_name);
554
+    $field_key = $element['#columns'][0];
555
+    $value = $element['#value'][$field_key];
556 556
 
557
-  if (($element[$field_key]['#required'] || !empty($value))) {
557
+    if (($element[$field_key]['#required'] || !empty($value))) {
558 558
     $decimal = $element['#decimal'] ? $element['#decimal'] : '.';
559 559
     $start = $value;
560 560
     $value = preg_replace('@[^-0-9\\'. $decimal .']@', '', $value);
561 561
     if ($start != $value) {
562
-      $error_field = implode('][', $element['#parents']) .']['. $field_key;
563
-      form_set_error($error_field, t('Only numbers and the decimal character (%decimal) are allowed in %field.', array('%decimal' => $element['#decimal'], '%field' => t($field['widget']['label']))));
562
+        $error_field = implode('][', $element['#parents']) .']['. $field_key;
563
+        form_set_error($error_field, t('Only numbers and the decimal character (%decimal) are allowed in %field.', array('%decimal' => $element['#decimal'], '%field' => t($field['widget']['label']))));
564 564
     }
565 565
     else {
566
-      $value = str_replace($element['#decimal'], '.', $value);
567
-      $value = round($value, $element['#scale']);
568
-      form_set_value($element[$field_key], $value, $form_state);
566
+        $value = str_replace($element['#decimal'], '.', $value);
567
+        $value = round($value, $element['#scale']);
568
+        form_set_value($element[$field_key], $value, $form_state);
569
+    }
569 570
     }
570
-  }
571 571
 }
572 572
 
573 573
 /**
@@ -581,5 +581,5 @@  discard block
 block discarded – undo
581 581
  * $element['#delta]  is the position of this element in the group
582 582
  */
583 583
 function theme_number($element) {
584
-  return $element['#children'];
584
+    return $element['#children'];
585 585
 }
586 586
\ No newline at end of file
Please login to merge, or discard this patch.
boinc/modules/contrib/cck/modules/optionwidgets/optionwidgets.module 1 patch
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
  * Implementation of hook_form_alter.
11 11
  */
12 12
 function optionwidgets_form_alter(&$form, $form_state, $form_id) {
13
-  // Provide additional help for the field settings form.
14
-  if ($form_id == 'content_field_edit_form' && isset($form['widget'])) {
13
+    // Provide additional help for the field settings form.
14
+    if ($form_id == 'content_field_edit_form' && isset($form['widget'])) {
15 15
     $widget_type = $form['#field']['widget']['type'];
16 16
     $field_type = $form['#field']['type'];
17 17
     $label = $form['#field']['widget']['label'];
@@ -19,45 +19,45 @@  discard block
 block discarded – undo
19 19
     $output = '<p>'. t('Create a list of options as a list in <strong>Allowed values list</strong> or as an array in PHP code. These values will be the same for %field in all content types.', array('%field' => $label)) .'</p>';
20 20
 
21 21
     if ($widget_type == 'optionwidgets_onoff') {
22
-      $output .= '<p>'. t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.") .'</p>';
22
+        $output .= '<p>'. t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.") .'</p>';
23 23
     }
24 24
     elseif ($widget_type == 'optionwidgets_buttons') {
25
-      $output .= '<p>'. t("The 'checkboxes/radio buttons' widget will display checkboxes if the multiple values option is selected for this field, otherwise radios will be displayed.") .'</p>';
25
+        $output .= '<p>'. t("The 'checkboxes/radio buttons' widget will display checkboxes if the multiple values option is selected for this field, otherwise radios will be displayed.") .'</p>';
26 26
     }
27 27
 
28 28
     if (in_array($field_type, array('text', 'number_integer', 'number_float', 'number_decimal'))
29 29
     && in_array($widget_type, array('optionwidgets_onoff', 'optionwidgets_buttons', 'optionwidgets_select'))) {
30
-      $form['field']['allowed_values_fieldset']['#collapsed'] = FALSE;
31
-      $form['field']['allowed_values_fieldset']['#description'] = $output;
30
+        $form['field']['allowed_values_fieldset']['#collapsed'] = FALSE;
31
+        $form['field']['allowed_values_fieldset']['#description'] = $output;
32 32
 
33
-      // If no 'allowed values' were set yet, add a remainder in the messages area.
34
-      if (empty($form_state['post'])
33
+        // If no 'allowed values' were set yet, add a remainder in the messages area.
34
+        if (empty($form_state['post'])
35 35
       && empty($form['field']['allowed_values_fieldset']['allowed_values']['#default_value'])
36 36
       && empty($form['field']['allowed_values_fieldset']['advanced_options']['allowed_values_php']['#default_value'])) {
37 37
         drupal_set_message(t("You need to specify the 'allowed values' for this field."), 'warning');
38
-      }
38
+        }
39
+    }
39 40
     }
40
-  }
41 41
 }
42 42
 
43 43
 /**
44 44
  * Implementation of hook_theme().
45 45
  */
46 46
 function optionwidgets_theme() {
47
-  return array(
47
+    return array(
48 48
     'optionwidgets_select' => array(
49
-      'arguments' => array('element' => NULL),
49
+        'arguments' => array('element' => NULL),
50 50
     ),
51 51
     'optionwidgets_buttons' => array(
52
-      'arguments' => array('element' => NULL),
52
+        'arguments' => array('element' => NULL),
53 53
     ),
54 54
     'optionwidgets_onoff' => array(
55
-      'arguments' => array('element' => NULL),
55
+        'arguments' => array('element' => NULL),
56 56
     ),
57 57
     'optionwidgets_none' => array(
58
-      'arguments' => array('widget_type' => NULL, 'field_name' => NULL, 'node_type' => NULL),
59
-      ),
60
-  );
58
+        'arguments' => array('widget_type' => NULL, 'field_name' => NULL, 'node_type' => NULL),
59
+        ),
60
+    );
61 61
 }
62 62
 
63 63
 /**
@@ -75,32 +75,32 @@  discard block
 block discarded – undo
75 75
  */
76 76
 function optionwidgets_widget_info() {
77 77
 
78
-  return array(
78
+    return array(
79 79
     'optionwidgets_select' => array(
80
-      'label' => t('Select list'),
81
-      'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'),
82
-      'multiple values' => CONTENT_HANDLE_MODULE,
83
-      'callbacks' => array(
80
+        'label' => t('Select list'),
81
+        'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'),
82
+        'multiple values' => CONTENT_HANDLE_MODULE,
83
+        'callbacks' => array(
84 84
         'default value' => CONTENT_CALLBACK_DEFAULT,
85
-      ),
85
+        ),
86 86
     ),
87 87
     'optionwidgets_buttons' => array(
88
-      'label' => t('Check boxes/radio buttons'),
89
-      'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'),
90
-      'multiple values' => CONTENT_HANDLE_MODULE,
91
-      'callbacks' => array(
88
+        'label' => t('Check boxes/radio buttons'),
89
+        'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'),
90
+        'multiple values' => CONTENT_HANDLE_MODULE,
91
+        'callbacks' => array(
92 92
         'default value' => CONTENT_CALLBACK_DEFAULT,
93
-      ),
93
+        ),
94 94
     ),
95 95
     'optionwidgets_onoff' => array(
96
-      'label' => t('Single on/off checkbox'),
97
-      'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'),
98
-      'multiple values' => CONTENT_HANDLE_MODULE,
99
-      'callbacks' => array(
96
+        'label' => t('Single on/off checkbox'),
97
+        'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'),
98
+        'multiple values' => CONTENT_HANDLE_MODULE,
99
+        'callbacks' => array(
100 100
         'default value' => CONTENT_CALLBACK_DEFAULT,
101
-      ),
101
+        ),
102 102
     ),
103
-  );
103
+    );
104 104
 }
105 105
 
106 106
 /**
@@ -113,22 +113,22 @@  discard block
 block discarded – undo
113 113
  * the same name as the hook_elements key.
114 114
  */
115 115
 function optionwidgets_elements() {
116
-  return array(
116
+    return array(
117 117
     'optionwidgets_select' => array(
118
-      '#input' => TRUE,
119
-      '#columns' => array('value'), '#delta' => 0,
120
-      '#process' => array('optionwidgets_select_process'),
121
-      ),
118
+        '#input' => TRUE,
119
+        '#columns' => array('value'), '#delta' => 0,
120
+        '#process' => array('optionwidgets_select_process'),
121
+        ),
122 122
     'optionwidgets_buttons' => array(
123
-      '#input' => TRUE,
124
-      '#columns' => array('value'), '#delta' => 0,
125
-      '#process' => array('optionwidgets_buttons_process'),
126
-      ),
123
+        '#input' => TRUE,
124
+        '#columns' => array('value'), '#delta' => 0,
125
+        '#process' => array('optionwidgets_buttons_process'),
126
+        ),
127 127
     'optionwidgets_onoff' => array(
128
-      '#input' => TRUE,
129
-      '#columns' => array('value'), '#delta' => 0,
130
-      '#process' => array('optionwidgets_onoff_process'),
131
-      ),
128
+        '#input' => TRUE,
129
+        '#columns' => array('value'), '#delta' => 0,
130
+        '#process' => array('optionwidgets_onoff_process'),
131
+        ),
132 132
     );
133 133
 }
134 134
 
@@ -164,11 +164,11 @@  discard block
 block discarded – undo
164 164
  *   the form item for a single element for this field
165 165
  */
166 166
 function optionwidgets_widget(&$form, &$form_state, $field, $items, $delta = NULL) {
167
-  $element = array(
167
+    $element = array(
168 168
     '#type' => $field['widget']['type'],
169 169
     '#default_value' => !empty($items) ? $items : array(),
170
-  );
171
-  return $element;
170
+    );
171
+    return $element;
172 172
 }
173 173
 
174 174
 /**
@@ -180,17 +180,17 @@  discard block
 block discarded – undo
180 180
  * The $fields array is in $form['#field_info'][$element['#field_name']].
181 181
  */
182 182
 function optionwidgets_buttons_process($element, $edit, &$form_state, $form) {
183
-  $field_name = $element['#field_name'];
184
-  $field = $form['#field_info'][$field_name];
185
-  $field_key  = $element['#columns'][0];
183
+    $field_name = $element['#field_name'];
184
+    $field = $form['#field_info'][$field_name];
185
+    $field_key  = $element['#columns'][0];
186 186
 
187
-  // See if this element is in the database format or the transformed format,
188
-  // and transform it if necessary.
189
-  if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) {
187
+    // See if this element is in the database format or the transformed format,
188
+    // and transform it if necessary.
189
+    if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) {
190 190
     $element['#value'] = optionwidgets_data2form($element, $element['#default_value'], $field);
191
-  }
192
-  $options = optionwidgets_options($field);
193
-  $element[$field_key] = array(
191
+    }
192
+    $options = optionwidgets_options($field);
193
+    $element[$field_key] = array(
194 194
     '#type' => $field['multiple'] ? 'checkboxes' : 'radios',
195 195
     '#title' => $element['#title'],
196 196
     '#description' => $element['#description'],
@@ -198,19 +198,19 @@  discard block
 block discarded – undo
198 198
     '#multiple' => isset($element['#multiple']) ? $element['#multiple'] : $field['multiple'],
199 199
     '#options' => $options,
200 200
     '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
201
-  );
201
+    );
202 202
 
203
-  // Set #element_validate in a way that it will not wipe out other
204
-  // validation functions already set by other modules.
205
-  if (empty($element['#element_validate'])) {
203
+    // Set #element_validate in a way that it will not wipe out other
204
+    // validation functions already set by other modules.
205
+    if (empty($element['#element_validate'])) {
206 206
     $element['#element_validate'] = array();
207
-  }
208
-  array_unshift($element['#element_validate'], 'optionwidgets_validate');
207
+    }
208
+    array_unshift($element['#element_validate'], 'optionwidgets_validate');
209 209
 
210
-  // Make sure field info will be available to the validator which
211
-  // does not get the values in $form.
212
-  $form_state['#field_info'][$field['field_name']] = $field;
213
-  return $element;
210
+    // Make sure field info will be available to the validator which
211
+    // does not get the values in $form.
212
+    $form_state['#field_info'][$field['field_name']] = $field;
213
+    return $element;
214 214
 }
215 215
 
216 216
 /**
@@ -222,23 +222,23 @@  discard block
 block discarded – undo
222 222
  * The $fields array is in $form['#field_info'][$element['#field_name']].
223 223
  */
224 224
 function optionwidgets_select_process($element, $edit, &$form_state, $form) {
225
-  $field_name = $element['#field_name'];
226
-  $field = $form['#field_info'][$field_name];
227
-  $field_key  = $element['#columns'][0];
225
+    $field_name = $element['#field_name'];
226
+    $field = $form['#field_info'][$field_name];
227
+    $field_key  = $element['#columns'][0];
228 228
 
229
-  // See if this element is in the database format or the transformed format,
230
-  // and transform it if necessary.
231
-  if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) {
229
+    // See if this element is in the database format or the transformed format,
230
+    // and transform it if necessary.
231
+    if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) {
232 232
     $element['#value'] = optionwidgets_data2form($element, $element['#default_value'], $field);
233
-  }
233
+    }
234 234
 
235
-  $options = optionwidgets_options($field, FALSE);
235
+    $options = optionwidgets_options($field, FALSE);
236 236
 
237
-  // For this specific widget, HTML should be filtered out and entities left unencoded.
238
-  // See content_allowed_values / content_filter_xss / filter_xss.
239
-  content_allowed_values_filter_html($options);
237
+    // For this specific widget, HTML should be filtered out and entities left unencoded.
238
+    // See content_allowed_values / content_filter_xss / filter_xss.
239
+    content_allowed_values_filter_html($options);
240 240
 
241
-  $element[$field_key] = array(
241
+    $element[$field_key] = array(
242 242
     '#type' => 'select',
243 243
     '#title' => $element['#title'],
244 244
     '#description' => $element['#description'],
@@ -246,24 +246,24 @@  discard block
 block discarded – undo
246 246
     '#multiple' => isset($element['#multiple']) ? $element['#multiple'] : $field['multiple'],
247 247
     '#options' => $options,
248 248
     '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
249
-  );
249
+    );
250 250
 
251
-  // Set #element_validate in a way that it will not wipe out other
252
-  // validation functions already set by other modules.
253
-  if (empty($element['#element_validate'])) {
251
+    // Set #element_validate in a way that it will not wipe out other
252
+    // validation functions already set by other modules.
253
+    if (empty($element['#element_validate'])) {
254 254
     $element['#element_validate'] = array();
255
-  }
256
-  array_unshift($element['#element_validate'], 'optionwidgets_validate');
257
-
258
-  // Make sure field info will be available to the validator which
259
-  // does not get the values in $form.
260
-
261
-  // TODO for some reason putting the $field array into $form_state['storage']
262
-  // causes the node's hook_form_alter to be invoked twice, garbling the
263
-  // results. Need to investigate why that is happening (a core bug?), but
264
-  // in the meantime avoid using $form_state['storage'] to store anything.
265
-  $form_state['#field_info'][$field['field_name']] = $field;
266
-  return $element;
255
+    }
256
+    array_unshift($element['#element_validate'], 'optionwidgets_validate');
257
+
258
+    // Make sure field info will be available to the validator which
259
+    // does not get the values in $form.
260
+
261
+    // TODO for some reason putting the $field array into $form_state['storage']
262
+    // causes the node's hook_form_alter to be invoked twice, garbling the
263
+    // results. Need to investigate why that is happening (a core bug?), but
264
+    // in the meantime avoid using $form_state['storage'] to store anything.
265
+    $form_state['#field_info'][$field['field_name']] = $field;
266
+    return $element;
267 267
 }
268 268
 
269 269
 /**
@@ -275,64 +275,64 @@  discard block
 block discarded – undo
275 275
  * The $fields array is in $form['#field_info'][$element['#field_name']].
276 276
  */
277 277
 function optionwidgets_onoff_process($element, $edit, &$form_state, $form) {
278
-  $field_name = $element['#field_name'];
279
-  $field = $form['#field_info'][$field_name];
280
-  $field_key  = $element['#columns'][0];
278
+    $field_name = $element['#field_name'];
279
+    $field = $form['#field_info'][$field_name];
280
+    $field_key  = $element['#columns'][0];
281 281
 
282
-  // See if this element is in the database format or the transformed format,
283
-  // and transform it if necessary.
284
-  if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) {
282
+    // See if this element is in the database format or the transformed format,
283
+    // and transform it if necessary.
284
+    if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) {
285 285
     $element['#value'] = optionwidgets_data2form($element, $element['#default_value'], $field);
286
-  }
287
-  $options = optionwidgets_options($field);
288
-  $keys = array_keys($options);
289
-  $on_value = (!empty($keys) && isset($keys[1])) ? $keys[1] : NULL;
290
-  $element[$field_key] = array(
286
+    }
287
+    $options = optionwidgets_options($field);
288
+    $keys = array_keys($options);
289
+    $on_value = (!empty($keys) && isset($keys[1])) ? $keys[1] : NULL;
290
+    $element[$field_key] = array(
291 291
     '#type' => 'checkbox',
292 292
     '#title' => isset($options[$on_value]) ? $options[$on_value] : '',
293 293
     '#description' => $element['#description'],
294 294
     '#required' => isset($element['#required']) ? $element['#required'] : $field['required'],
295 295
     '#default_value' => isset($element['#value'][$field_key][0]) ? $element['#value'][$field_key][0] == $on_value : FALSE,
296 296
     '#return_value' => $on_value,
297
-  );
297
+    );
298 298
 
299
-  // Set #element_validate in a way that it will not wipe out other
300
-  // validation functions already set by other modules.
301
-  if (empty($element['#element_validate'])) {
299
+    // Set #element_validate in a way that it will not wipe out other
300
+    // validation functions already set by other modules.
301
+    if (empty($element['#element_validate'])) {
302 302
     $element['#element_validate'] = array();
303
-  }
304
-  array_unshift($element['#element_validate'], 'optionwidgets_validate');
303
+    }
304
+    array_unshift($element['#element_validate'], 'optionwidgets_validate');
305 305
 
306
-  // Make sure field info will be available to the validator which
307
-  // does not get the values in $form.
308
-  $form_state['#field_info'][$field['field_name']] = $field;
309
-  return $element;
306
+    // Make sure field info will be available to the validator which
307
+    // does not get the values in $form.
308
+    $form_state['#field_info'][$field['field_name']] = $field;
309
+    return $element;
310 310
 }
311 311
 
312 312
 /**
313 313
  * FAPI function to validate optionwidgets element.
314 314
  */
315 315
 function optionwidgets_validate($element, &$form_state) {
316
-  // Transpose selections from field => delta to delta => field,
317
-  // turning multiple selected options into multiple parent elements.
318
-  // Immediate parent is the delta, need to get back to parent's parent
319
-  // to create multiple elements.
320
-  $field = $form_state['#field_info'][$element['#field_name']];
321
-  $items = optionwidgets_form2data($element, $field);
322
-  form_set_value($element, $items, $form_state);
323
-
324
-  // Check we don't exceed the allowed number of values.
325
-  if ($field['multiple'] >= 2) {
316
+    // Transpose selections from field => delta to delta => field,
317
+    // turning multiple selected options into multiple parent elements.
318
+    // Immediate parent is the delta, need to get back to parent's parent
319
+    // to create multiple elements.
320
+    $field = $form_state['#field_info'][$element['#field_name']];
321
+    $items = optionwidgets_form2data($element, $field);
322
+    form_set_value($element, $items, $form_state);
323
+
324
+    // Check we don't exceed the allowed number of values.
325
+    if ($field['multiple'] >= 2) {
326 326
     // Filter out 'none' value (if present, will always be in key 0)
327 327
     $field_key = $element['#columns'][0];
328 328
     if (isset($items[0][$field_key]) && $items[0][$field_key] === '') {
329
-      unset($items[0]);
329
+        unset($items[0]);
330 330
     }
331 331
     if (count($items) > $field['multiple']) {
332
-      $field_key  = $element['#columns'][0];
333
-      form_error($element[$field_key], t('%name: this field cannot hold more than @count values.', array('%name' => t($field['widget']['label']), '@count' => $field['multiple'])));
332
+        $field_key  = $element['#columns'][0];
333
+        form_error($element[$field_key], t('%name: this field cannot hold more than @count values.', array('%name' => t($field['widget']['label']), '@count' => $field['multiple'])));
334
+    }
334 335
     }
335
-  }
336 336
 }
337 337
 
338 338
 /**
@@ -341,24 +341,24 @@  discard block
 block discarded – undo
341 341
  * transformation is needed.
342 342
  */
343 343
 function optionwidgets_data2form($element, $items, $field) {
344
-  $field_key  = $element['#columns'][0];
345
-  $options    = optionwidgets_options($field);
344
+    $field_key  = $element['#columns'][0];
345
+    $options    = optionwidgets_options($field);
346 346
 
347
-  $items_transposed = content_transpose_array_rows_cols($items);
348
-  $values = (isset($items_transposed[$field_key]) && is_array($items_transposed[$field_key])) ? $items_transposed[$field_key] : array();
349
-  $keys = array();
350
-  foreach ($values as $value) {
347
+    $items_transposed = content_transpose_array_rows_cols($items);
348
+    $values = (isset($items_transposed[$field_key]) && is_array($items_transposed[$field_key])) ? $items_transposed[$field_key] : array();
349
+    $keys = array();
350
+    foreach ($values as $value) {
351 351
     $key = array_search($value, array_keys($options));
352 352
     if (isset($key)) {
353
-      $keys[] = $value;
353
+        $keys[] = $value;
354
+    }
354 355
     }
355
-  }
356
-  if ($field['multiple'] || $element['#type'] == 'optionwidgets_onoff') {
356
+    if ($field['multiple'] || $element['#type'] == 'optionwidgets_onoff') {
357 357
     return array($field_key => $keys);
358
-  }
359
-  else {
358
+    }
359
+    else {
360 360
     return !empty($keys) ? array($field_key => $value) : array();
361
-  }
361
+    }
362 362
 }
363 363
 
364 364
 /**
@@ -367,22 +367,22 @@  discard block
 block discarded – undo
367 367
  * transformation is needed.
368 368
  */
369 369
 function optionwidgets_form2data($element, $field) {
370
-  $field_key = $element['#columns'][0];
371
-  $items = (array) $element[$field_key]['#value'];
372
-  $options = optionwidgets_options($field);
370
+    $field_key = $element['#columns'][0];
371
+    $items = (array) $element[$field_key]['#value'];
372
+    $options = optionwidgets_options($field);
373 373
 
374
-  $values = array_values($items);
374
+    $values = array_values($items);
375 375
 
376
-  if ($element['#type'] == 'optionwidgets_onoff' && ($values[0] === 0)) {
376
+    if ($element['#type'] == 'optionwidgets_onoff' && ($values[0] === 0)) {
377 377
     $keys = array_keys($options);
378 378
     $values = array(array_key_exists(0, $keys) ? $keys[0] : NULL);
379
-  }
379
+    }
380 380
 
381
-  if (empty($values)) {
381
+    if (empty($values)) {
382 382
     $values[] = NULL;
383
-  }
384
-  $result = content_transpose_array_rows_cols(array($field_key => $values));
385
-  return $result;
383
+    }
384
+    $result = content_transpose_array_rows_cols(array($field_key => $values));
385
+    return $result;
386 386
 }
387 387
 
388 388
 /**
@@ -399,18 +399,18 @@  discard block
 block discarded – undo
399 399
  *   when allowed values list is generated using PHP code.
400 400
  */
401 401
 function optionwidgets_options($field, $flatten = TRUE) {
402
-  $function = $field['module'] .'_allowed_values';
403
-  $options = function_exists($function) ? $function($field) : (array) content_allowed_values($field, $flatten);
404
-  // Add an empty choice for :
405
-  // - non required radios
406
-  // - non required selects
407
-  if (!$field['required']) {
402
+    $function = $field['module'] .'_allowed_values';
403
+    $options = function_exists($function) ? $function($field) : (array) content_allowed_values($field, $flatten);
404
+    // Add an empty choice for :
405
+    // - non required radios
406
+    // - non required selects
407
+    if (!$field['required']) {
408 408
     if ((in_array($field['widget']['type'], array('optionwidgets_buttons', 'nodereference_buttons', 'userreference_buttons')) && !$field['multiple'])
409 409
       || (in_array($field['widget']['type'], array('optionwidgets_select', 'nodereference_select', 'userreference_select')))) {
410
-      $options = array('' => theme('optionwidgets_none', $field)) + $options;
410
+        $options = array('' => theme('optionwidgets_none', $field)) + $options;
411
+    }
411 412
     }
412
-  }
413
-  return $options;
413
+    return $options;
414 414
 }
415 415
 
416 416
 /**
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
  *  The default theme will display N/A for a radio list and blank for a select.
419 419
  */
420 420
 function theme_optionwidgets_none($field) {
421
-  switch ($field['widget']['type']) {
421
+    switch ($field['widget']['type']) {
422 422
     case 'optionwidgets_buttons':
423 423
     case 'nodereference_buttons':
424 424
     case 'userreference_buttons':
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
       return t('- None -');
430 430
     default :
431 431
       return '';
432
-  }
432
+    }
433 433
 }
434 434
 
435 435
 /**
@@ -444,13 +444,13 @@  discard block
 block discarded – undo
444 444
  * $element['#delta]  is the position of this element in the group
445 445
  */
446 446
 function theme_optionwidgets_select($element) {
447
-  return $element['#children'];
447
+    return $element['#children'];
448 448
 }
449 449
 
450 450
 function theme_optionwidgets_onoff($element) {
451
-  return $element['#children'];
451
+    return $element['#children'];
452 452
 }
453 453
 
454 454
 function theme_optionwidgets_buttons($element) {
455
-  return $element['#children'];
455
+    return $element['#children'];
456 456
 }
457 457
\ No newline at end of file
Please login to merge, or discard this patch.
default/boinc/modules/contrib/cck/modules/content_copy/content_copy.module 1 patch
Indentation   +273 added lines, -273 removed lines patch added patch discarded remove patch
@@ -32,174 +32,174 @@  discard block
 block discarded – undo
32 32
  * Implementation of hook_menu().
33 33
  */
34 34
 function content_copy_menu() {
35
-  $items = array();
35
+    $items = array();
36 36
 
37
-  $items['admin/content/types/export'] = array(
37
+    $items['admin/content/types/export'] = array(
38 38
     'title' => 'Export',
39 39
     'page callback' => 'drupal_get_form',
40 40
     'page arguments' => array('content_copy_export_form'),
41 41
     'access arguments' => array('administer content types'),
42 42
     'type' => MENU_LOCAL_TASK,
43 43
     'weight' => 3,
44
-  );
45
-  $items['admin/content/types/import'] = array(
44
+    );
45
+    $items['admin/content/types/import'] = array(
46 46
     'title' => 'Import',
47 47
     'page callback' => 'drupal_get_form',
48 48
     'page arguments' => array('content_copy_import_form'),
49 49
     'access arguments' => array('administer content types'),
50 50
     'type' => MENU_LOCAL_TASK,
51 51
     'weight' => 4,
52
-  );
53
-  return $items;
52
+    );
53
+    return $items;
54 54
 }
55 55
 
56 56
 /**
57 57
  * Implementation of hook_theme().
58 58
  */
59 59
 function content_copy_theme() {
60
-  return array(
60
+    return array(
61 61
     'content_copy_export_form' => array(
62
-      'template' => 'content_copy_export_form',
63
-      'arguments' => array('form' => NULL),
62
+        'template' => 'content_copy_export_form',
63
+        'arguments' => array('form' => NULL),
64 64
     ),
65
-  );
65
+    );
66 66
 }
67 67
 
68 68
 /**
69 69
  *  A form to export field definitions.
70 70
  */
71 71
 function content_copy_export_form(&$form_state) {
72
-  include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc');
73
-  include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc');
72
+    include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc');
73
+    include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc');
74 74
 
75
-  $form_values = isset($form_state['values']) ? $form_state['values'] : array();
76
-  $step = isset($form_state['storage']['step']) ? $form_state['storage']['step'] + 1 : 1;
75
+    $form_values = isset($form_state['values']) ? $form_state['values'] : array();
76
+    $step = isset($form_state['storage']['step']) ? $form_state['storage']['step'] + 1 : 1;
77 77
 
78
-  $exportable_fields = array();
79
-  $groups = array();
78
+    $exportable_fields = array();
79
+    $groups = array();
80 80
 
81
-  $type_name = isset($form_values['type_name']) ? $form_values['type_name'] : '';
82
-  if ($type_name) {
81
+    $type_name = isset($form_values['type_name']) ? $form_values['type_name'] : '';
82
+    if ($type_name) {
83 83
     $type = content_types($type_name);
84 84
     $exportable_fields = content_copy_fields($type_name);
85 85
     if (module_exists('fieldgroup')) {
86
-      $groups = fieldgroup_groups($type_name);
86
+        $groups = fieldgroup_groups($type_name);
87
+    }
87 88
     }
88
-  }
89 89
 
90
-  // If a content type has been selected and there are no fields or groups to select,
91
-  // jump straight to export.
92
-  if ($step == 2 && !($groups) && !($exportable_fields)) {
90
+    // If a content type has been selected and there are no fields or groups to select,
91
+    // jump straight to export.
92
+    if ($step == 2 && !($groups) && !($exportable_fields)) {
93 93
     $step = 3;
94
-  }
94
+    }
95 95
 
96
-  $form['#step'] = $step;
97
-  $form['#prefix'] = t('This form will process a content type and one or more fields from that type and export the settings. The export created by this process can be copied and pasted as an import into the current or any other database. The import will add the fields to an existing content type or create a new content type that includes the selected fields.');
96
+    $form['#step'] = $step;
97
+    $form['#prefix'] = t('This form will process a content type and one or more fields from that type and export the settings. The export created by this process can be copied and pasted as an import into the current or any other database. The import will add the fields to an existing content type or create a new content type that includes the selected fields.');
98 98
 
99
-  switch ($step) {
99
+    switch ($step) {
100 100
     case 1: // Select a content type.
101 101
       $types  = content_copy_types();
102
-      $form['type_name'] = array(
102
+        $form['type_name'] = array(
103 103
         '#title' => t('Types'),
104 104
         '#type' => 'radios',
105 105
         '#options' => $types,
106 106
         '#description' => t('Select the content type to export.'),
107
-      );
108
-      break;
107
+        );
108
+        break;
109 109
 
110 110
     case 2: // Select groups and fields.
111 111
       $form['type_name'] = array(
112 112
         '#type' => 'hidden',
113 113
         '#value' => $type_name,
114
-      );
114
+        );
115 115
 
116
-      $form += array(
116
+        $form += array(
117 117
         '#fields' => $exportable_fields,
118 118
         '#groups' => array_keys($groups),
119
-      );
119
+        );
120 120
 
121
-      $fields_options = $groups_options = array();
121
+        $fields_options = $groups_options = array();
122 122
 
123
-      // Fields.
124
-      foreach ($exportable_fields as $field_name) {
123
+        // Fields.
124
+        foreach ($exportable_fields as $field_name) {
125 125
         $field = content_fields($field_name, $type_name);
126 126
         $fields_options[$field_name] = '';
127 127
         $weight = $field['widget']['weight'];
128 128
         $form[$field_name] = array(
129
-          'human_name' => array('#value' => check_plain($field['widget']['label'])),
130
-          'field_name' => array('#value' => $field['field_name']),
131
-          'type' => array('#value' => $field['type']),
132
-          'weight' => array('#type' => 'value', '#value' => $weight),
133
-          'parent' => array('#type' => 'value', '#value' => ''),
134
-          '#row_type' => 'field',
129
+            'human_name' => array('#value' => check_plain($field['widget']['label'])),
130
+            'field_name' => array('#value' => $field['field_name']),
131
+            'type' => array('#value' => $field['type']),
132
+            'weight' => array('#type' => 'value', '#value' => $weight),
133
+            'parent' => array('#type' => 'value', '#value' => ''),
134
+            '#row_type' => 'field',
135 135
         );
136
-      }
137
-      $form['fields'] = array(
136
+        }
137
+        $form['fields'] = array(
138 138
         '#type' => 'checkboxes',
139 139
         '#options' => $fields_options,
140 140
         '#default_value' => array_keys($fields_options),
141
-      );
141
+        );
142 142
 
143
-      // Groups.
144
-      foreach ($groups as $name => $group) {
143
+        // Groups.
144
+        foreach ($groups as $name => $group) {
145 145
         $groups_options[$name] = '';
146 146
         $weight = $group['weight'];
147 147
         $form[$name] = array(
148
-          'human_name' => array('#value' => check_plain($group['label'])),
149
-          'group_name' => array('#value' => $group['group_name']),
150
-          'weight' => array('#type' => 'value', '#value' => $weight),
151
-          '#row_type' => 'group',
148
+            'human_name' => array('#value' => check_plain($group['label'])),
149
+            'group_name' => array('#value' => $group['group_name']),
150
+            'weight' => array('#type' => 'value', '#value' => $weight),
151
+            '#row_type' => 'group',
152 152
         );
153 153
         foreach ($group['fields'] as $field_name => $field) {
154
-          // Do nothing for non-exportable (inactive) fields.
155
-          if (isset($form[$field_name])) {
154
+            // Do nothing for non-exportable (inactive) fields.
155
+            if (isset($form[$field_name])) {
156 156
             $form[$field_name]['parent']['#value'] = $name;
157
-          }
157
+            }
158
+        }
158 159
         }
159
-      }
160
-      if ($groups) {
160
+        if ($groups) {
161 161
         $form['groups'] = array(
162
-          '#type' => 'checkboxes',
163
-          '#options' => $groups_options,
164
-          '#default_value' => array_keys($groups_options),
162
+            '#type' => 'checkboxes',
163
+            '#options' => $groups_options,
164
+            '#default_value' => array_keys($groups_options),
165 165
         );
166
-      }
167
-      break;
166
+        }
167
+        break;
168 168
 
169 169
     case 3: // Display the export macro.
170 170
       $GLOBALS['content_copy']['count'] = 0;
171
-      $form['export'] = array(
171
+        $form['export'] = array(
172 172
         '#title' => t('Export data'),
173 173
         '#type' => 'textarea',
174 174
         '#cols' => 60,
175 175
         '#value' => content_copy_export($form_values),
176 176
         '#rows' => max(40, $GLOBALS['content_copy']['count']),
177 177
         '#description' => t('Copy the export text and paste it into another content type using the import function.'),
178
-      );
179
-      // The calls to drupal_execute('content_field_edit_form') in
180
-      // content_copy_export() affect the page title,
181
-      drupal_set_title(t('Content types'));
182
-      break;
183
-  }
184
-
185
-  if ($step < 3) {  // Omit submit button on the textarea block to display the export data.
178
+        );
179
+        // The calls to drupal_execute('content_field_edit_form') in
180
+        // content_copy_export() affect the page title,
181
+        drupal_set_title(t('Content types'));
182
+        break;
183
+    }
184
+
185
+    if ($step < 3) {  // Omit submit button on the textarea block to display the export data.
186 186
     $form['submit'] = array(
187
-      '#type' => 'submit',
188
-      '#value' => t('Export'),
187
+        '#type' => 'submit',
188
+        '#value' => t('Export'),
189 189
     );
190
-  }
190
+    }
191 191
 
192
-  $form['step'] = array(
192
+    $form['step'] = array(
193 193
     '#type' => 'value',
194 194
     '#value' => $step,
195
-  );
195
+    );
196 196
 
197
-  return $form;
197
+    return $form;
198 198
 }
199 199
 
200 200
 function content_copy_export_form_submit($form, &$form_state) {
201
-  $form_state['rebuild'] = TRUE;
202
-  $form_state['storage']['step'] = $form_state['values']['step'];
201
+    $form_state['rebuild'] = TRUE;
202
+    $form_state['storage']['step'] = $form_state['values']['step'];
203 203
 }
204 204
 
205 205
 
@@ -208,66 +208,66 @@  discard block
 block discarded – undo
208 208
  *   and save the form values as formatted text.
209 209
  */
210 210
 function content_copy_export($form_values) {
211
-  // Set a global variable to tell when to intervene with form_alter().
212
-  $GLOBALS['content_copy']['status'] = 'export';
211
+    // Set a global variable to tell when to intervene with form_alter().
212
+    $GLOBALS['content_copy']['status'] = 'export';
213 213
 
214
-  // Get the content type info by submitting the content type form.
215
-  $node_state = array('values' => array('type_name' => $form_values['type_name']));
216
-  module_load_include('inc', 'node', 'content_types');
217
-  drupal_execute('node_type_form', $node_state, node_get_types('type', $form_values['type_name']));
214
+    // Get the content type info by submitting the content type form.
215
+    $node_state = array('values' => array('type_name' => $form_values['type_name']));
216
+    module_load_include('inc', 'node', 'content_types');
217
+    drupal_execute('node_type_form', $node_state, node_get_types('type', $form_values['type_name']));
218 218
 
219
-  module_load_include('inc', 'content', 'includes/content.admin');
220
-  module_load_include('inc', 'content', 'includes/content.crud');
219
+    module_load_include('inc', 'content', 'includes/content.admin');
220
+    module_load_include('inc', 'content', 'includes/content.crud');
221 221
 
222
-  // Get an array of groups to export.
223
-  // Record a macro for each group by submitting the group edit form.
224
-  $groups = array();
225
-  if (!empty($form_values['groups']) && module_exists('fieldgroup')) {
222
+    // Get an array of groups to export.
223
+    // Record a macro for each group by submitting the group edit form.
224
+    $groups = array();
225
+    if (!empty($form_values['groups']) && module_exists('fieldgroup')) {
226 226
     $groups = array_filter($form_values['groups']);
227 227
     foreach ($groups as $group) {
228
-      $group_state = array('values' => array('group_name' => $group));
229
-      drupal_execute('fieldgroup_group_edit_form', $group_state, $form_values['type_name'], $group, 'edit');
228
+        $group_state = array('values' => array('group_name' => $group));
229
+        drupal_execute('fieldgroup_group_edit_form', $group_state, $form_values['type_name'], $group, 'edit');
230
+    }
230 231
     }
231
-  }
232 232
 
233
-  // Get an array of fields to export
234
-  // Record a macro for each field by submitting the field settings form.
235
-  // Omit fields from the export if their module is not currently installed
236
-  // otherwise the system will generate errors when the macro tries to execute their forms.
237
-  if (!empty($form_values['fields'])) {
233
+    // Get an array of fields to export
234
+    // Record a macro for each field by submitting the field settings form.
235
+    // Omit fields from the export if their module is not currently installed
236
+    // otherwise the system will generate errors when the macro tries to execute their forms.
237
+    if (!empty($form_values['fields'])) {
238 238
     $type = content_types($form_values['type_name']);
239 239
     $fields = array_filter($form_values['fields']);
240 240
     foreach ($fields as $field_name) {
241
-      $field = $type['fields'][$field_name];
242
-      $field_types = _content_field_types();
243
-      $field_module = $field_types[$field['type']]['module'];
244
-      $widget_types = _content_widget_types();
245
-      $widget_module = $widget_types[$field['widget']['type']]['module'];
246
-      if (!empty($field_module) && module_exists($field_module) && !empty($widget_module) && module_exists($widget_module)) {
241
+        $field = $type['fields'][$field_name];
242
+        $field_types = _content_field_types();
243
+        $field_module = $field_types[$field['type']]['module'];
244
+        $widget_types = _content_widget_types();
245
+        $widget_module = $widget_types[$field['widget']['type']]['module'];
246
+        if (!empty($field_module) && module_exists($field_module) && !empty($widget_module) && module_exists($widget_module)) {
247 247
         $field_state = array('values' => content_field_instance_collapse($field));
248 248
         $field_state['values']['op'] = t('Save field settings');
249 249
         if (module_exists('fieldgroup')) {
250
-          // Avoid undefined index error by always creating this.
251
-          $field_state['values']['group'] = '';
252
-          $group_name = fieldgroup_get_group($form_values['type_name'], $field_name);
253
-          if (in_array($group_name, $groups)) {
250
+            // Avoid undefined index error by always creating this.
251
+            $field_state['values']['group'] = '';
252
+            $group_name = fieldgroup_get_group($form_values['type_name'], $field_name);
253
+            if (in_array($group_name, $groups)) {
254 254
             $field_state['values']['group'] = $group_name;
255
-          }
255
+            }
256 256
         }
257 257
         drupal_execute('content_field_edit_form', $field_state, $form_values['type_name'], $field_name);
258
-      }
258
+        }
259
+    }
259 260
     }
260
-  }
261 261
 
262
-  // Convert the macro array into formatted text.
263
-  $output = content_copy_get_macro();
262
+    // Convert the macro array into formatted text.
263
+    $output = content_copy_get_macro();
264 264
 
265
-  // Add weights of non-CCK fields.
266
-  if ($extra = variable_get('content_extra_weights_'. $form_values['type_name'], array())) {
265
+    // Add weights of non-CCK fields.
266
+    if ($extra = variable_get('content_extra_weights_'. $form_values['type_name'], array())) {
267 267
     $output .= "\$content['extra']  = ". var_export((array) $extra, TRUE) .";\n";
268
-  }
268
+    }
269 269
 
270
-  return $output;
270
+    return $output;
271 271
 }
272 272
 
273 273
 /**
@@ -294,37 +294,37 @@  discard block
 block discarded – undo
294 294
  * }
295 295
  */
296 296
 function content_copy_import_form(&$form_state, $type_name = '') {
297
-  include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc');
298
-  include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc');
297
+    include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc');
298
+    include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc');
299 299
 
300
-  $form['#prefix'] = t('This form will import field definitions exported from another content type or another database.<br/>Note that fields cannot be duplicated within the same content type, so imported fields will be added only if they do not already exist in the selected type.');
301
-  $form['type_name'] = array(
300
+    $form['#prefix'] = t('This form will import field definitions exported from another content type or another database.<br/>Note that fields cannot be duplicated within the same content type, so imported fields will be added only if they do not already exist in the selected type.');
301
+    $form['type_name'] = array(
302 302
     '#type' => 'select',
303 303
     '#options' => array('<create>' => t('<Create>')) + content_copy_types(),
304 304
     '#default_value' => $type_name,
305 305
     '#title' => t('Content type'),
306 306
     '#description' => t('Select the content type to import these fields into.<br/>Select &lt;Create&gt; to create a new content type to contain the fields.'),
307
-  );
308
-  $form['macro'] = array(
307
+    );
308
+    $form['macro'] = array(
309 309
     '#type' => 'textarea',
310 310
     '#rows' => 40,
311 311
     '#title' => t('Import data'),
312 312
     '#required' => TRUE,
313 313
     '#description' => t('Paste the text created by a content export into this field.'),
314
-  );
315
-  $form['submit'] = array(
314
+    );
315
+    $form['submit'] = array(
316 316
     '#type' => 'submit',
317 317
     '#value' => t('Import'),
318
-  );
319
-  // Read in a file if there is one and set it as the default macro value.
320
-  if (isset($_REQUEST['macro_file']) && $file = file_get_contents($_REQUEST['macro_file'])) {
318
+    );
319
+    // Read in a file if there is one and set it as the default macro value.
320
+    if (isset($_REQUEST['macro_file']) && $file = file_get_contents($_REQUEST['macro_file'])) {
321 321
     $form['macro']['#default_value'] = $file;
322 322
     if (isset($_REQUEST['type_name'])) {
323
-      $form['type_name']['#default_value'] = $_REQUEST['type_name'];
323
+        $form['type_name']['#default_value'] = $_REQUEST['type_name'];
324 324
     }
325 325
     $form['#prefix'] .= '<p class="error">'. t('A file has been pre-loaded for import.') .'</p>';
326
-  }
327
-  return $form;
326
+    }
327
+    return $form;
328 328
 }
329 329
 
330 330
 /**
@@ -334,90 +334,90 @@  discard block
 block discarded – undo
334 334
  *     2) execute the imported field macro to update the settings to the imported values
335 335
  */
336 336
 function content_copy_import_form_submit($form, &$form_state) {
337
-  $form_values = $form_state['values'];
337
+    $form_values = $form_state['values'];
338 338
 
339
-  // Get the content type we are importing into.
340
-  $type_name = $form_values['type_name'];
341
-  $type_label = node_get_types('name', $type_name);
339
+    // Get the content type we are importing into.
340
+    $type_name = $form_values['type_name'];
341
+    $type_label = node_get_types('name', $type_name);
342 342
 
343
-  $content = NULL;
344
-  // Convert the import formatted text back into a $content array.
345
-  // Return if errors generated or not an array.
346
-  // Use '@' to suppress errors about undefined constants in the macro.
347
-  @eval($form_values['macro']);
343
+    $content = NULL;
344
+    // Convert the import formatted text back into a $content array.
345
+    // Return if errors generated or not an array.
346
+    // Use '@' to suppress errors about undefined constants in the macro.
347
+    @eval($form_values['macro']);
348 348
 
349
-  // Preliminary error trapping, must have valid arrays to work with.
350
-  if (!isset($content) || !isset($content['type']) || !is_array($content) || !is_array($content['type'])) {
349
+    // Preliminary error trapping, must have valid arrays to work with.
350
+    if (!isset($content) || !isset($content['type']) || !is_array($content) || !is_array($content['type'])) {
351 351
     form_set_error('macro', t('The import data is not valid import text.'));
352 352
     return;
353
-  }
353
+    }
354 354
 
355
-  module_load_include('inc', 'content', 'includes/content.crud');
355
+    module_load_include('inc', 'content', 'includes/content.crud');
356 356
 
357
-  // Get all type and field info for this database.
358
-  $content_info = _content_type_info();
357
+    // Get all type and field info for this database.
358
+    $content_info = _content_type_info();
359 359
 
360
-  $imported_type = $content['type'];
361
-  $imported_type_name = $imported_type['type'];
362
-  $imported_type_label = $imported_type['name'];
360
+    $imported_type = $content['type'];
361
+    $imported_type_name = $imported_type['type'];
362
+    $imported_type_label = $imported_type['name'];
363 363
 
364
-  // It is allowed to import a type with no fields,
365
-  // so the fields array could be empty and must be cast as an array.
366
-  $imported_fields = isset($content['fields']) ? $content['fields'] : array();
364
+    // It is allowed to import a type with no fields,
365
+    // so the fields array could be empty and must be cast as an array.
366
+    $imported_fields = isset($content['fields']) ? $content['fields'] : array();
367 367
 
368
-  // Perform more pre-import error trapping.
369
-  // If there are potential problems, exit without doing the import.
370
-  $not_enabled = array();
368
+    // Perform more pre-import error trapping.
369
+    // If there are potential problems, exit without doing the import.
370
+    $not_enabled = array();
371 371
 
372
-  // The groups array could be empty and still valid, make sure to cast it as an array.
373
-  // If there are groups in the import, make sure the fieldgroup module is enabled.
374
-  $imported_groups = array();
375
-  if (isset($content['groups']) && module_exists('fieldgroup')) {
372
+    // The groups array could be empty and still valid, make sure to cast it as an array.
373
+    // If there are groups in the import, make sure the fieldgroup module is enabled.
374
+    $imported_groups = array();
375
+    if (isset($content['groups']) && module_exists('fieldgroup')) {
376 376
     $imported_groups = (array) $content['groups'];
377
-  }
378
-  elseif (isset($content['groups']) && is_array($content['groups'])) {
377
+    }
378
+    elseif (isset($content['groups']) && is_array($content['groups'])) {
379 379
     $not_enabled[] = 'fieldgroup';
380
-  }
380
+    }
381 381
 
382
-  // Make sure that all the field and widget modules in the import are enabled in this database.
383
-  foreach ($imported_fields as $import) {
382
+    // Make sure that all the field and widget modules in the import are enabled in this database.
383
+    foreach ($imported_fields as $import) {
384 384
     $field = content_field_instance_collapse($import);
385 385
     if (empty($field['module']) || empty($field['widget_module'])) {
386
-      $not_enabled[] = $field['field_name'];
386
+        $not_enabled[] = $field['field_name'];
387 387
     }
388 388
     else {
389
-      if (!module_exists($field['module'])) {
389
+        if (!module_exists($field['module'])) {
390 390
         $not_enabled[] = $field['module'];
391
-      }
392
-      if (!module_exists($field['widget_module'])) {
391
+        }
392
+        if (!module_exists($field['widget_module'])) {
393 393
         $not_enabled[] = $field['widget_module'];
394
-      }
394
+        }
395
+    }
395 396
     }
396
-  }
397 397
 
398
-  // If any required module is not enabled, set an error message and exit.
399
-  if ($not_enabled) {
398
+    // If any required module is not enabled, set an error message and exit.
399
+    if ($not_enabled) {
400 400
     form_set_error('macro', t('The following modules must be enabled for this import to work: %modules.', array(
401 401
         '%modules' => implode(', ', array_unique($not_enabled))
402 402
         )));
403
-  }
403
+    }
404 404
 
405
-  // Make sure the imported content type doesn't already exist in the database.
406
-  if ($form_values['type_name'] == '<create>') {
405
+    // Make sure the imported content type doesn't already exist in the database.
406
+    if ($form_values['type_name'] == '<create>') {
407 407
     if (in_array($imported_type_name, array_keys($content_info['content types']))) {
408
-      form_set_error('macro', t('The content type %type already exists in this database.', array(
408
+        form_set_error('macro', t('The content type %type already exists in this database.', array(
409 409
             '%type' => $imported_type_name
410 410
             )));
411 411
     }
412
-  }
412
+    }
413 413
 
414
-  if (form_get_errors()) {
414
+    if (form_get_errors()) {
415 415
     drupal_set_message(t('Exiting. No import performed.'), 'error');
416 416
     return;
417
-  }
417
+    }
418 418
 
419
-  // Create the content type, if requested.
420
-  if ($form_values['type_name'] == '<create>') {
419
+    // Create the content type, if requested.
420
+    if ($form_values['type_name'] == '<create>') {
421 421
 
422 422
     $type = (object) $imported_type;
423 423
     $values = $imported_type;
@@ -435,26 +435,26 @@  discard block
 block discarded – undo
435 435
     $content_info = _content_type_info();
436 436
 
437 437
     if (form_get_errors() || !isset($content_info['content types']) || !is_array($content_info['content types'][$type_name])) {
438
-       drupal_set_message(t('An error has occurred adding the content type %type.<br/>Please check the errors displayed for more details.', array(
438
+        drupal_set_message(t('An error has occurred adding the content type %type.<br/>Please check the errors displayed for more details.', array(
439 439
             '%type' => $imported_type_name
440 440
             )));
441
-       return;
441
+        return;
442
+    }
442 443
     }
443
-  }
444 444
 
445
-  // Create the groups for this type, if they don't already exist.
446
-  if (module_exists('fieldgroup') && $imported_groups) {
445
+    // Create the groups for this type, if they don't already exist.
446
+    if (module_exists('fieldgroup') && $imported_groups) {
447 447
     foreach ($imported_groups as $group) {
448
-      $group_name = $group['group_name'];
449
-      fieldgroup_save_group($type_name, $group);
448
+        $group_name = $group['group_name'];
449
+        fieldgroup_save_group($type_name, $group);
450 450
     }
451 451
     // Reset the static variable in fieldgroup_groups() with new data.
452 452
     fieldgroup_groups('', FALSE, TRUE);
453
-  }
453
+    }
454 454
 
455
-  // Iterate through the field forms in the import and execute each.
456
-  $rebuild = FALSE;
457
-  foreach ($imported_fields as $field) {
455
+    // Iterate through the field forms in the import and execute each.
456
+    $rebuild = FALSE;
457
+    foreach ($imported_fields as $field) {
458 458
 
459 459
     // Make sure the field doesn't already exist in the type.
460 460
     // If so, do nothing, fields can't be duplicated within a content type.
@@ -464,13 +464,13 @@  discard block
 block discarded – undo
464 464
     $field['type_name'] = $type_name;
465 465
 
466 466
     if (!empty($field['field_name']) && isset($content_info['content types'][$type_name]['fields'][$field_name])) {
467
-      drupal_set_message(t('The imported field %field_label (%field_name) was not added to %type because that field already exists in %type.', array(
467
+        drupal_set_message(t('The imported field %field_label (%field_name) was not added to %type because that field already exists in %type.', array(
468 468
         '%field_label' => $field['label'], '%field_name' => $field_name, '%type' => $type_label)));
469 469
     }
470 470
     else {
471
-      $field = content_field_instance_create($field, FALSE);
472
-      $rebuild = TRUE;
473
-      drupal_set_message(t('The field %field_label (%field_name) was added to the content type %type.', array(
471
+        $field = content_field_instance_create($field, FALSE);
472
+        $rebuild = TRUE;
473
+        drupal_set_message(t('The field %field_label (%field_name) was added to the content type %type.', array(
474 474
         '%field_label' => $field['widget']['label'], '%field_name' => $field_name, '%type' => $type_label)));
475 475
     }
476 476
 
@@ -480,20 +480,20 @@  discard block
 block discarded – undo
480 480
     // restored. Hence, we need to update field group data for newly imported
481 481
     // field, but also for fields that already exist.
482 482
     if (module_exists('fieldgroup') && isset($imported_groups)) {
483
-      fieldgroup_update_fields($field);
483
+        fieldgroup_update_fields($field);
484
+    }
484 485
     }
485
-  }
486 486
 
487
-  // Clear caches and rebuild menu only if any field has been created.
488
-  if ($rebuild) {
487
+    // Clear caches and rebuild menu only if any field has been created.
488
+    if ($rebuild) {
489 489
     content_clear_type_cache(TRUE);
490 490
     menu_rebuild();
491
-  }
491
+    }
492 492
 
493
-  // Import weights of non-CCK fields.
494
-  if (isset($content['extra'])) {
493
+    // Import weights of non-CCK fields.
494
+    if (isset($content['extra'])) {
495 495
     variable_set('content_extra_weights_'. $type_name, $content['extra']);
496
-  }
496
+    }
497 497
 }
498 498
 
499 499
 /**
@@ -501,22 +501,22 @@  discard block
 block discarded – undo
501 501
  * Intervene to run form through macro when doing export
502 502
  */
503 503
 function content_copy_form_alter(&$form, $form_state, $form_id) {
504
-  $alter_forms = array('node_type_form', 'content_field_edit_form', 'fieldgroup_group_edit_form');
505
-  if (isset($GLOBALS['content_copy']) && isset($GLOBALS['content_copy']['status']) && $GLOBALS['content_copy']['status'] == 'export' && in_array($form_id, $alter_forms)) {
504
+    $alter_forms = array('node_type_form', 'content_field_edit_form', 'fieldgroup_group_edit_form');
505
+    if (isset($GLOBALS['content_copy']) && isset($GLOBALS['content_copy']['status']) && $GLOBALS['content_copy']['status'] == 'export' && in_array($form_id, $alter_forms)) {
506 506
     $form['#submit'][] = 'content_copy_record_macro';
507
-  }
507
+    }
508 508
 }
509 509
 
510 510
 /**
511 511
  * Get all the *active* fields for a content type.
512 512
  */
513 513
 function content_copy_fields($type_name) {
514
-  $fields = array();
515
-  if (!$type_name) {
514
+    $fields = array();
515
+    if (!$type_name) {
516 516
     return $fields;
517
-  }
518
-  $content_info = _content_type_info();
519
-  foreach ($content_info['content types'][$type_name]['fields'] as $field_name => $field) {
517
+    }
518
+    $content_info = _content_type_info();
519
+    foreach ($content_info['content types'][$type_name]['fields'] as $field_name => $field) {
520 520
     // Omit fields from the export if their module is not currently installed
521 521
     // otherwise the system will generate errors when the macro tries to execute their forms.
522 522
     $field_types = _content_field_types();
@@ -525,125 +525,125 @@  discard block
 block discarded – undo
525 525
     $widget_module = $widget_types[$field['widget']['type']]['module'];
526 526
 
527 527
     if (!$field['locked'] && !empty($field_module) && module_exists($field_module) && !empty($widget_module) && module_exists($widget_module)) {
528
-      $fields[] = $field_name;
528
+        $fields[] = $field_name;
529 529
     }
530
-  }
531
-  return $fields;
530
+    }
531
+    return $fields;
532 532
 }
533 533
 
534 534
 /**
535 535
  *  Get all content types.
536 536
  */
537 537
 function content_copy_types() {
538
-  $types = array();
539
-  $content_info = _content_type_info();
540
-  foreach ($content_info['content types'] as $type_name => $val) {
538
+    $types = array();
539
+    $content_info = _content_type_info();
540
+    foreach ($content_info['content types'] as $type_name => $val) {
541 541
     $types[$type_name] = check_plain($val['name']) .' ('. $type_name .')';
542
-  }
543
-  return $types;
542
+    }
543
+    return $types;
544 544
 }
545 545
 
546 546
 /**
547 547
  * A handler that stores the form submissions into a $GLOBALS array
548 548
  */
549 549
 function content_copy_record_macro($form, &$form_state) {
550
-  $edit = $form_state['values'];
551
-  $subs = isset($GLOBALS['content_copy']['submissions']) ? $GLOBALS['content_copy']['submissions'] : array();
550
+    $edit = $form_state['values'];
551
+    $subs = isset($GLOBALS['content_copy']['submissions']) ? $GLOBALS['content_copy']['submissions'] : array();
552 552
 
553
-  // Get the form values and store them in a $GLOBALS['content_copy']['submissions'] array.
554
-  // Update $GLOBALS['content_copy']['count'] with an approximation of the number of rows in this item.
555
-  // Count is used to approximate necessary size of textarea in form.
553
+    // Get the form values and store them in a $GLOBALS['content_copy']['submissions'] array.
554
+    // Update $GLOBALS['content_copy']['count'] with an approximation of the number of rows in this item.
555
+    // Count is used to approximate necessary size of textarea in form.
556 556
 
557
-  $form_id = $form_state['values']['form_id'];
558
-  if (isset($edit['type_name']) || isset($edit['submit']) || isset($edit['delete']) || isset($edit['form_id'])) {
557
+    $form_id = $form_state['values']['form_id'];
558
+    if (isset($edit['type_name']) || isset($edit['submit']) || isset($edit['delete']) || isset($edit['form_id'])) {
559 559
     unset($edit['type_name'], $edit['submit'], $edit['delete'], $edit['form_id'], $edit['previous_field']);
560
-  }
561
-  switch ($form_id) {
560
+    }
561
+    switch ($form_id) {
562 562
     case 'node_type_form':
563 563
       $subs['type'] = $edit;
564
-      $GLOBALS['content_copy']['count'] += sizeof($edit) + 5;
565
-      break;
564
+        $GLOBALS['content_copy']['count'] += sizeof($edit) + 5;
565
+        break;
566 566
 
567 567
     case 'fieldgroup_group_edit_form':
568 568
       $subs['groups'][] = $edit;
569
-      $GLOBALS['content_copy']['count'] += sizeof($edit) + 5;
570
-      break;
569
+        $GLOBALS['content_copy']['count'] += sizeof($edit) + 5;
570
+        break;
571 571
 
572 572
     default:
573 573
       if (isset($edit['field_widget_type'])) {
574 574
         $tmp = explode('-', $edit['field_widget_type']);
575 575
         $field_name = $tmp[0];
576
-      }
577
-      else {
576
+        }
577
+        else {
578 578
         $field_name = isset($edit['field_name']) ? $edit['field_name'] : '';
579
-      }
579
+        }
580 580
 
581
-      // The display settings are being fetched directly from the DB. During import,
582
-      // we'll re-insert the data directly as well.
583
-      //
584
-      $query = 'SELECT display_settings FROM {'. content_instance_tablename() .'} WHERE field_name = \'%s\'';
585
-      $row_info = db_fetch_array(db_query($query, $field_name));
581
+        // The display settings are being fetched directly from the DB. During import,
582
+        // we'll re-insert the data directly as well.
583
+        //
584
+        $query = 'SELECT display_settings FROM {'. content_instance_tablename() .'} WHERE field_name = \'%s\'';
585
+        $row_info = db_fetch_array(db_query($query, $field_name));
586 586
 
587
-      // If an error occurs, notify the user.
588
-      if ($db_err = db_error()) {
587
+        // If an error occurs, notify the user.
588
+        if ($db_err = db_error()) {
589 589
         drupal_set_message(t("An error occurred when exporting the 'display settings' data for the field %field_name.<br/>The db error is: '%db_err'.", array(
590
-             '%field_name' => $field_name,
591
-             '%db_err' => $db_err
590
+                '%field_name' => $field_name,
591
+                '%db_err' => $db_err
592 592
         )));
593
-      }
594
-      else {
593
+        }
594
+        else {
595 595
         // The db fetch occurred successfully, unserialize the data blob and
596 596
         // insert it into a new "display_settings" field of the data.
597 597
         if ($display_settings = unserialize($row_info['display_settings'])) {
598
-          $edit['display_settings'] = $display_settings;
598
+            $edit['display_settings'] = $display_settings;
599 599
         }
600
-      }
601
-      $subs['fields'][] = $edit;
602
-      $GLOBALS['content_copy']['count'] += sizeof($edit) + 5;
603
-      break;
604
-  }
600
+        }
601
+        $subs['fields'][] = $edit;
602
+        $GLOBALS['content_copy']['count'] += sizeof($edit) + 5;
603
+        break;
604
+    }
605 605
 
606
-  $GLOBALS['content_copy']['submissions'] = $subs;
606
+    $GLOBALS['content_copy']['submissions'] = $subs;
607 607
 }
608 608
 
609 609
 /**
610 610
  * @return a code representation of the recorded macro.
611 611
  */
612 612
 function content_copy_get_macro() {
613
-  // Define the indexes for the evaluated code.
614
-  $string = "";
615
-  if (array_key_exists('submissions', $GLOBALS['content_copy'])) {
613
+    // Define the indexes for the evaluated code.
614
+    $string = "";
615
+    if (array_key_exists('submissions', $GLOBALS['content_copy'])) {
616 616
     foreach ($GLOBALS['content_copy']['submissions'] as $form_type => $form) {
617
-      $string .= "\$content['$form_type']  = ". var_export((array) $form, TRUE) .";\n";
617
+        $string .= "\$content['$form_type']  = ". var_export((array) $form, TRUE) .";\n";
618 618
     }
619 619
     return $string;
620
-  }
620
+    }
621 621
 }
622 622
 
623 623
 function template_preprocess_content_copy_export_form($vars) {
624
-  $form = &$vars['form'];
624
+    $form = &$vars['form'];
625 625
 
626
-  if ($form['#step'] == 2) {
626
+    if ($form['#step'] == 2) {
627 627
     $order = _content_overview_order($form, $form['#fields'], $form['#groups']);
628 628
 
629 629
     $rows = array();
630 630
     foreach ($order as $key) {
631
-      $element = &$form[$key];
632
-      $row = new stdClass();
631
+        $element = &$form[$key];
632
+        $row = new stdClass();
633 633
 
634
-      $row->row_type = $element['#row_type'];
635
-      $checkbox_key = $element['#row_type'] == 'field' ? 'fields' : 'groups';
636
-      $row->checkbox = drupal_render($form[$checkbox_key][$key]);
637
-      foreach (element_children($element) as $child) {
634
+        $row->row_type = $element['#row_type'];
635
+        $checkbox_key = $element['#row_type'] == 'field' ? 'fields' : 'groups';
636
+        $row->checkbox = drupal_render($form[$checkbox_key][$key]);
637
+        foreach (element_children($element) as $child) {
638 638
         $row->{$child} = drupal_render($element[$child]);
639
-      }
640
-      $row->label_class = in_array($key, $form['#groups']) ? 'label-group' : 'label-field';
641
-      $row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0);
639
+        }
640
+        $row->label_class = in_array($key, $form['#groups']) ? 'label-group' : 'label-field';
641
+        $row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0);
642 642
 
643
-      $rows[] = $row;
643
+        $rows[] = $row;
644 644
     }
645 645
     $vars['rows'] = $rows;
646
-  }
646
+    }
647 647
 
648
-  $vars['submit'] = drupal_render($form);
648
+    $vars['submit'] = drupal_render($form);
649 649
 }
650 650
\ No newline at end of file
Please login to merge, or discard this patch.
modules/contrib/cck/modules/content_permissions/content_permissions.module 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@  discard block
 block discarded – undo
5 5
  *  Implementation of hook_perm().
6 6
  */
7 7
 function content_permissions_perm() {
8
-  $perms = array();
9
-  foreach (content_fields() as $field) {
8
+    $perms = array();
9
+    foreach (content_fields() as $field) {
10 10
     $perms[] = 'edit '. $field['field_name'];
11 11
     $perms[] = 'view '. $field['field_name'];
12
-  }
13
-  return $perms;
12
+    }
13
+    return $perms;
14 14
 }
15 15
 
16 16
 /**
@@ -19,10 +19,10 @@  discard block
 block discarded – undo
19 19
  * @see content_access().
20 20
  */
21 21
 function content_permissions_field_access($op, $field, $account, $node = NULL) {
22
-  switch ($op) {
22
+    switch ($op) {
23 23
     case 'view':
24 24
     case 'edit':
25 25
       return user_access($op .' '. $field['field_name'], $account);
26
-  }
27
-  return TRUE;
26
+    }
27
+    return TRUE;
28 28
 }
Please login to merge, or discard this patch.
drupal/sites/default/boinc/modules/contrib/cck/modules/text/text.module 1 patch
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -10,101 +10,101 @@  discard block
 block discarded – undo
10 10
  * Implementation of hook_theme().
11 11
  */
12 12
 function text_theme() {
13
-  return array(
13
+    return array(
14 14
     'text_textarea' => array(
15
-      'arguments' => array('element' => NULL),
15
+        'arguments' => array('element' => NULL),
16 16
     ),
17 17
     'text_textfield' => array(
18
-      'arguments' => array('element' => NULL),
18
+        'arguments' => array('element' => NULL),
19 19
     ),
20 20
     'text_formatter_default' => array(
21
-      'arguments' => array('element' => NULL),
21
+        'arguments' => array('element' => NULL),
22 22
     ),
23 23
     'text_formatter_plain' => array(
24
-      'arguments' => array('element' => NULL),
24
+        'arguments' => array('element' => NULL),
25 25
     ),
26 26
     'text_formatter_trimmed' => array(
27
-      'arguments' => array('element' => NULL),
27
+        'arguments' => array('element' => NULL),
28 28
     ),
29 29
     'text_formatter_foo' => array(
30
-      'arguments' => array('element' => NULL),
30
+        'arguments' => array('element' => NULL),
31 31
     ),
32
-  );
32
+    );
33 33
 }
34 34
 
35 35
 /**
36 36
  * Implementation of hook_field_info().
37 37
  */
38 38
 function text_field_info() {
39
-  return array(
39
+    return array(
40 40
     'text' => array(
41
-      'label' => t('Text'),
42
-      'description' => t('Store text in the database.'),
41
+        'label' => t('Text'),
42
+        'description' => t('Store text in the database.'),
43 43
 //      'content_icon' => 'icon_content_text.png',
44 44
     ),
45
-  );
45
+    );
46 46
 }
47 47
 
48 48
 /**
49 49
  * Implementation of hook_field_settings().
50 50
  */
51 51
 function text_field_settings($op, $field) {
52
-  switch ($op) {
52
+    switch ($op) {
53 53
     case 'form':
54 54
       $form = array();
55
-      $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)'));
56
-      $form['text_processing'] = array(
55
+        $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)'));
56
+        $form['text_processing'] = array(
57 57
         '#type' => 'radios',
58 58
         '#title' => t('Text processing'),
59 59
         '#default_value' => is_numeric($field['text_processing']) ? $field['text_processing'] : 0,
60 60
         '#options' => $options,
61
-      );
62
-      $form['max_length'] = array(
61
+        );
62
+        $form['max_length'] = array(
63 63
         '#type' => 'textfield',
64 64
         '#title' => t('Maximum length'),
65 65
         '#default_value' => is_numeric($field['max_length']) ? $field['max_length'] : '',
66 66
         '#required' => FALSE,
67 67
         '#element_validate' => array('_element_validate_integer_positive'),
68 68
         '#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'),
69
-      );
70
-      $form['allowed_values_fieldset'] = array(
69
+        );
70
+        $form['allowed_values_fieldset'] = array(
71 71
         '#type' => 'fieldset',
72 72
         '#title' => t('Allowed values'),
73 73
         '#collapsible' => TRUE,
74 74
         '#collapsed' => TRUE,
75
-      );
76
-      $form['allowed_values_fieldset']['allowed_values'] = array(
75
+        );
76
+        $form['allowed_values_fieldset']['allowed_values'] = array(
77 77
         '#type' => 'textarea',
78 78
         '#title' => t('Allowed values list'),
79 79
         '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '',
80 80
         '#required' => FALSE,
81 81
         '#rows' => 10,
82 82
         '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())),
83
-      );
84
-      $form['allowed_values_fieldset']['advanced_options'] = array(
83
+        );
84
+        $form['allowed_values_fieldset']['advanced_options'] = array(
85 85
         '#type' => 'fieldset',
86 86
         '#title' => t('PHP code'),
87 87
         '#collapsible' => TRUE,
88 88
         '#collapsed' => empty($field['allowed_values_php']),
89
-      );
90
-      if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
89
+        );
90
+        if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
91 91
         $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array(
92
-          '#type' => 'textarea',
93
-          '#title' => t('Code'),
94
-          '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '',
95
-          '#rows' => 6,
96
-          '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
92
+            '#type' => 'textarea',
93
+            '#title' => t('Code'),
94
+            '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '',
95
+            '#rows' => 6,
96
+            '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
97 97
         );
98
-      }
99
-      else {
98
+        }
99
+        else {
100 100
         $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array(
101
-          '#type' => 'item',
102
-          '#title' => t('Code'),
103
-          '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('&lt;none&gt;'),
104
-          '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'),
101
+            '#type' => 'item',
102
+            '#title' => t('Code'),
103
+            '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('&lt;none&gt;'),
104
+            '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'),
105 105
         );
106
-      }
107
-      return $form;
106
+        }
107
+        return $form;
108 108
 
109 109
     case 'save':
110 110
       return array('text_processing', 'max_length', 'allowed_values', 'allowed_values_php');
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
     case 'database columns':
113 113
       if (empty($field['max_length']) || $field['max_length'] > 255) {
114 114
         $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE);
115
-      }
116
-      else {
115
+        }
116
+        else {
117 117
         $columns['value'] = array('type' => 'varchar', 'length' => $field['max_length'], 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE);
118
-      }
119
-      if (!empty($field['text_processing'])) {
118
+        }
119
+        if (!empty($field['text_processing'])) {
120 120
         $columns['format'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'views' => FALSE);
121
-      }
122
-      return $columns;
121
+        }
122
+        return $columns;
123 123
 
124 124
     case 'views data':
125 125
       $allowed_values = content_allowed_values($field);
126
-      if (count($allowed_values)) {
126
+        if (count($allowed_values)) {
127 127
         $data = content_views_field_views_data($field);
128 128
         $db_info = content_database_info($field);
129 129
         $table_alias = content_views_tablename($field);
@@ -137,106 +137,106 @@  discard block
 block discarded – undo
137 137
         // Argument : swap the handler to the 'many to one' operator.
138 138
         $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one';
139 139
         return $data;
140
-      }
141
-  }
140
+        }
141
+    }
142 142
 }
143 143
 
144 144
 /**
145 145
  * Implementation of hook_field().
146 146
  */
147 147
 function text_field($op, &$node, $field, &$items, $teaser, $page) {
148
-  switch ($op) {
148
+    switch ($op) {
149 149
     case 'validate':
150 150
       $allowed_values = content_allowed_values($field);
151
-      if (is_array($items)) {
151
+        if (is_array($items)) {
152 152
         foreach ($items as $delta => $item) {
153
-          $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
154
-          if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']);
155
-          if (!empty($item['value'])) {
153
+            $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
154
+            if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']);
155
+            if (!empty($item['value'])) {
156 156
             if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) {
157
-              form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label']))));
157
+                form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label']))));
158 158
             }
159 159
             if (!empty($field['max_length']) && drupal_strlen($item['value']) > $field['max_length']) {
160
-              form_set_error($error_element, t('%name: the value may not be longer than %max characters.', array('%name' => $field['widget']['label'], '%max' => $field['max_length'])));
160
+                form_set_error($error_element, t('%name: the value may not be longer than %max characters.', array('%name' => $field['widget']['label'], '%max' => $field['max_length'])));
161
+            }
161 162
             }
162
-          }
163 163
         }
164
-      }
165
-      return $items;
164
+        }
165
+        return $items;
166 166
 
167 167
     case 'sanitize':
168 168
       foreach ($items as $delta => $item) {
169 169
         if (!empty($field['text_processing'])) {
170
-          $text = isset($item['value']) ? check_markup($item['value'], $item['format'], FALSE) : '';
170
+            $text = isset($item['value']) ? check_markup($item['value'], $item['format'], FALSE) : '';
171 171
         }
172 172
         else {
173
-          $text = isset($item['value']) ? check_plain($item['value']) : '';
173
+            $text = isset($item['value']) ? check_plain($item['value']) : '';
174 174
         }
175 175
         $items[$delta]['safe'] = $text;
176
-      }
177
-  }
176
+        }
177
+    }
178 178
 }
179 179
 
180 180
 /**
181 181
  * Implementation of hook_content_is_empty().
182 182
  */
183 183
 function text_content_is_empty($item, $field) {
184
-  if (empty($item['value']) && (string)$item['value'] !== '0') {
184
+    if (empty($item['value']) && (string)$item['value'] !== '0') {
185 185
     return TRUE;
186
-  }
187
-  return FALSE;
186
+    }
187
+    return FALSE;
188 188
 }
189 189
 
190 190
 /**
191 191
  * Implementation of hook_field_formatter_info().
192 192
  */
193 193
 function text_field_formatter_info() {
194
-  return array(
194
+    return array(
195 195
     'default' => array(
196
-      'label' => t('Default'),
197
-      'field types' => array('text'),
198
-      'multiple values' => CONTENT_HANDLE_CORE,
196
+        'label' => t('Default'),
197
+        'field types' => array('text'),
198
+        'multiple values' => CONTENT_HANDLE_CORE,
199 199
     ),
200 200
     'plain' => array(
201
-      'label' => t('Plain text'),
202
-      'field types' => array('text'),
203
-      'multiple values' => CONTENT_HANDLE_CORE,
201
+        'label' => t('Plain text'),
202
+        'field types' => array('text'),
203
+        'multiple values' => CONTENT_HANDLE_CORE,
204 204
     ),
205 205
     'trimmed' => array(
206
-      'label' => t('Trimmed'),
207
-      'field types' => array('text'),
208
-      'multiple values' => CONTENT_HANDLE_CORE,
206
+        'label' => t('Trimmed'),
207
+        'field types' => array('text'),
208
+        'multiple values' => CONTENT_HANDLE_CORE,
209 209
     ),
210
-  );
210
+    );
211 211
 }
212 212
 
213 213
 /**
214 214
  * Theme function for 'default' text field formatter.
215 215
  */
216 216
 function theme_text_formatter_default($element) {
217
-  return ($allowed =_text_allowed_values($element)) ? $allowed : $element['#item']['safe'];
217
+    return ($allowed =_text_allowed_values($element)) ? $allowed : $element['#item']['safe'];
218 218
 }
219 219
 
220 220
 /**
221 221
  * Theme function for 'plain' text field formatter.
222 222
  */
223 223
 function theme_text_formatter_plain($element) {
224
-  return ($allowed =_text_allowed_values($element)) ? $allowed : strip_tags($element['#item']['safe']);
224
+    return ($allowed =_text_allowed_values($element)) ? $allowed : strip_tags($element['#item']['safe']);
225 225
 }
226 226
 
227 227
 /**
228 228
  * Theme function for 'trimmed' text field formatter.
229 229
  */
230 230
 function theme_text_formatter_trimmed($element) {
231
-  $field = content_fields($element['#field_name'], $element['#type_name']);
232
-  return ($allowed =_text_allowed_values($element)) ? $allowed : node_teaser($element['#item']['safe'], $field['text_processing'] ? $element['#item']['format'] : NULL);
231
+    $field = content_fields($element['#field_name'], $element['#type_name']);
232
+    return ($allowed =_text_allowed_values($element)) ? $allowed : node_teaser($element['#item']['safe'], $field['text_processing'] ? $element['#item']['format'] : NULL);
233 233
 }
234 234
 
235 235
 function _text_allowed_values($element) {
236
-  $field = content_fields($element['#field_name'], $element['#type_name']);
237
-  if (($allowed_values = content_allowed_values($field)) && isset($allowed_values[$element['#item']['value']])) {
236
+    $field = content_fields($element['#field_name'], $element['#type_name']);
237
+    if (($allowed_values = content_allowed_values($field)) && isset($allowed_values[$element['#item']['value']])) {
238 238
     return $allowed_values[$element['#item']['value']];
239
-  }
239
+    }
240 240
 }
241 241
 
242 242
 /**
@@ -251,24 +251,24 @@  discard block
 block discarded – undo
251 251
  * differently.
252 252
  */
253 253
 function text_widget_info() {
254
-  return array(
254
+    return array(
255 255
     'text_textfield' => array(
256
-      'label' => t('Text field'),
257
-      'field types' => array('text'),
258
-      'multiple values' => CONTENT_HANDLE_CORE,
259
-      'callbacks' => array(
256
+        'label' => t('Text field'),
257
+        'field types' => array('text'),
258
+        'multiple values' => CONTENT_HANDLE_CORE,
259
+        'callbacks' => array(
260 260
         'default value' => CONTENT_CALLBACK_DEFAULT,
261
-      ),
261
+        ),
262 262
     ),
263 263
     'text_textarea' => array(
264
-      'label' => t('Text area (multiple rows)'),
265
-      'field types' => array('text'),
266
-      'multiple values' => CONTENT_HANDLE_CORE,
267
-      'callbacks' => array(
264
+        'label' => t('Text area (multiple rows)'),
265
+        'field types' => array('text'),
266
+        'multiple values' => CONTENT_HANDLE_CORE,
267
+        'callbacks' => array(
268 268
         'default value' => CONTENT_CALLBACK_DEFAULT,
269
-      ),
269
+        ),
270 270
     ),
271
-  );
271
+    );
272 272
 }
273 273
 
274 274
 /**
@@ -284,56 +284,56 @@  discard block
 block discarded – undo
284 284
  * (see nodereference and userreference).
285 285
  */
286 286
 function text_elements() {
287
-  return array(
287
+    return array(
288 288
     'text_textfield' => array(
289
-      '#input' => TRUE,
290
-      '#columns' => array('value'), '#delta' => 0,
291
-      '#process' => array('text_textfield_process'),
292
-      '#autocomplete_path' => FALSE,
289
+        '#input' => TRUE,
290
+        '#columns' => array('value'), '#delta' => 0,
291
+        '#process' => array('text_textfield_process'),
292
+        '#autocomplete_path' => FALSE,
293 293
     ),
294 294
     'text_textarea' => array(
295
-      '#input' => TRUE,
296
-      '#columns' => array('value', 'format'), '#delta' => 0,
297
-      '#process' => array('text_textarea_process'),
298
-      '#filter_value' => FILTER_FORMAT_DEFAULT,
295
+        '#input' => TRUE,
296
+        '#columns' => array('value', 'format'), '#delta' => 0,
297
+        '#process' => array('text_textarea_process'),
298
+        '#filter_value' => FILTER_FORMAT_DEFAULT,
299 299
     ),
300
-  );
300
+    );
301 301
 }
302 302
 
303 303
 /**
304 304
  * Implementation of hook_widget_settings().
305 305
  */
306 306
 function text_widget_settings($op, $widget) {
307
-  switch ($op) {
307
+    switch ($op) {
308 308
     case 'form':
309 309
       $form = array();
310
-      $rows = (isset($widget['rows']) && is_numeric($widget['rows'])) ? $widget['rows'] : 5;
311
-      $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
312
-      if ($widget['type'] == 'text_textfield') {
310
+        $rows = (isset($widget['rows']) && is_numeric($widget['rows'])) ? $widget['rows'] : 5;
311
+        $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
312
+        if ($widget['type'] == 'text_textfield') {
313 313
         $form['rows'] = array('#type' => 'hidden', '#value' => $rows);
314 314
         $form['size'] = array(
315
-          '#type' => 'textfield',
316
-          '#title' => t('Size of textfield'),
317
-          '#default_value' => $size,
318
-          '#element_validate' => array('_element_validate_integer_positive'),
319
-          '#required' => TRUE,
315
+            '#type' => 'textfield',
316
+            '#title' => t('Size of textfield'),
317
+            '#default_value' => $size,
318
+            '#element_validate' => array('_element_validate_integer_positive'),
319
+            '#required' => TRUE,
320 320
         );
321
-      }
322
-      else {
321
+        }
322
+        else {
323 323
         $form['rows'] = array(
324
-          '#type' => 'textfield',
325
-          '#title' => t('Rows'),
326
-          '#default_value' => $rows,
327
-          '#element_validate' => array('_element_validate_integer_positive'),
328
-          '#required' => TRUE,
324
+            '#type' => 'textfield',
325
+            '#title' => t('Rows'),
326
+            '#default_value' => $rows,
327
+            '#element_validate' => array('_element_validate_integer_positive'),
328
+            '#required' => TRUE,
329 329
         );
330 330
         $form['size'] = array('#type' => 'hidden', '#value' => $size);
331
-      }
332
-      return $form;
331
+        }
332
+        return $form;
333 333
 
334 334
     case 'save':
335 335
       return array('rows', 'size');
336
-  }
336
+    }
337 337
 }
338 338
 
339 339
 /**
@@ -368,11 +368,11 @@  discard block
 block discarded – undo
368 368
  *   the form item for a single element for this field
369 369
  */
370 370
 function text_widget(&$form, &$form_state, $field, $items, $delta = 0) {
371
-  $element = array(
371
+    $element = array(
372 372
     '#type' => $field['widget']['type'],
373 373
     '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
374
-  );
375
-  return $element;
374
+    );
375
+    return $element;
376 376
 }
377 377
 
378 378
 /**
@@ -384,10 +384,10 @@  discard block
 block discarded – undo
384 384
  * The $fields array is in $form['#field_info'][$element['#field_name']].
385 385
  */
386 386
 function text_textfield_process($element, $edit, $form_state, $form) {
387
-  $field = $form['#field_info'][$element['#field_name']];
388
-  $field_key = $element['#columns'][0];
389
-  $delta = $element['#delta'];
390
-  $element[$field_key] = array(
387
+    $field = $form['#field_info'][$element['#field_name']];
388
+    $field_key = $element['#columns'][0];
389
+    $delta = $element['#delta'];
390
+    $element[$field_key] = array(
391 391
     '#type' => 'textfield',
392 392
     '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
393 393
     '#autocomplete_path' => $element['#autocomplete_path'],
@@ -402,24 +402,24 @@  discard block
 block discarded – undo
402 402
     '#type_name' => $element['#type_name'],
403 403
     '#delta' => $element['#delta'],
404 404
     '#columns' => $element['#columns'],
405
-  );
405
+    );
406 406
 
407
-  $element[$field_key]['#maxlength'] = !empty($field['max_length']) ? $field['max_length'] : NULL;
407
+    $element[$field_key]['#maxlength'] = !empty($field['max_length']) ? $field['max_length'] : NULL;
408 408
 
409
-  if (!empty($field['text_processing'])) {
409
+    if (!empty($field['text_processing'])) {
410 410
     $filter_key = $element['#columns'][1];
411 411
     $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT;
412 412
     $parents = array_merge($element['#parents'] , array($filter_key));
413 413
     $element[$filter_key] = filter_form($format, 1, $parents);
414
-  }
414
+    }
415 415
 
416
-  // Used so that hook_field('validate') knows where to flag an error.
417
-  $element['_error_element'] = array(
416
+    // Used so that hook_field('validate') knows where to flag an error.
417
+    $element['_error_element'] = array(
418 418
     '#type' => 'value',
419 419
     '#value' => implode('][', array_merge($element['#parents'], array($field_key))),
420
-  );
420
+    );
421 421
 
422
-  return $element;
422
+    return $element;
423 423
 }
424 424
 
425 425
 /**
@@ -431,9 +431,9 @@  discard block
 block discarded – undo
431 431
  * The $fields array is in $form['#field_info'][$element['#field_name']].
432 432
  */
433 433
 function text_textarea_process($element, $edit, $form_state, $form) {
434
-  $field = $form['#field_info'][$element['#field_name']];
435
-  $field_key   = $element['#columns'][0];
436
-  $element[$field_key] = array(
434
+    $field = $form['#field_info'][$element['#field_name']];
435
+    $field_key   = $element['#columns'][0];
436
+    $element[$field_key] = array(
437 437
     '#type' => 'textarea',
438 438
     '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
439 439
     '#rows' => !empty($field['widget']['rows']) ? $field['widget']['rows'] : 10,
@@ -447,22 +447,22 @@  discard block
 block discarded – undo
447 447
     '#type_name' => $element['#type_name'],
448 448
     '#delta' => $element['#delta'],
449 449
     '#columns' => $element['#columns'],
450
-  );
450
+    );
451 451
 
452
-  if (!empty($field['text_processing'])) {
452
+    if (!empty($field['text_processing'])) {
453 453
     $filter_key  = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format';
454 454
     $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT;
455 455
     $parents = array_merge($element['#parents'] , array($filter_key));
456 456
     $element[$filter_key] = filter_form($format, 1, $parents);
457
-  }
457
+    }
458 458
 
459
-  // Used so that hook_field('validate') knows where to flag an error.
460
-  $element['_error_element'] = array(
459
+    // Used so that hook_field('validate') knows where to flag an error.
460
+    $element['_error_element'] = array(
461 461
     '#type' => 'value',
462 462
     '#value' => implode('][', array_merge($element['#parents'], array($field_key))),
463
-  );
463
+    );
464 464
 
465
-  return $element;
465
+    return $element;
466 466
 }
467 467
 
468 468
 /**
@@ -477,9 +477,9 @@  discard block
 block discarded – undo
477 477
  * $element['#delta]  is the position of this element in the group
478 478
  */
479 479
 function theme_text_textfield($element) {
480
-  return $element['#children'];
480
+    return $element['#children'];
481 481
 }
482 482
 
483 483
 function theme_text_textarea($element) {
484
-  return $element['#children'];
484
+    return $element['#children'];
485 485
 }
Please login to merge, or discard this patch.
cck/modules/userreference/panels/relationships/user_from_userref.inc 1 patch
Indentation   +18 added lines, -18 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 userreference_user_from_userref_ctools_relationships() {
13
-  return array(
13
+    return array(
14 14
     'title' => t('User from reference'),
15 15
     'keyword' => 'userreference',
16 16
     'description' => t('Adds a user from a user reference in a node context; if multiple users are referenced, this will get the first referenced user only.'),
@@ -18,48 +18,48 @@  discard block
 block discarded – undo
18 18
     'context' => 'userreference_user_from_userref_context',
19 19
     'settings form' => 'userreference_user_from_userref_settings_form',
20 20
     'settings form validate' => 'userreference_user_from_userref_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 userreference_user_from_userref_context($context, $conf) {
28
-  // If unset it wants a generic, unfilled context, which is just NULL.
29
-  if (empty($context->data)) {
28
+    // If unset it wants a generic, unfilled context, which is just NULL.
29
+    if (empty($context->data)) {
30 30
     return ctools_context_create_empty('user', NULL);
31
-  }
31
+    }
32 32
 
33
-  // Prevent whitescreens on stale data.
34
-  if (empty($conf)) {
33
+    // Prevent whitescreens on stale data.
34
+    if (empty($conf)) {
35 35
     return ctools_context_create_empty('user', NULL);
36
-  }
36
+    }
37 37
 
38
-  if (isset($context->data->{$conf['field_name']}[0]['uid']) && ($uid = $context->data->{$conf['field_name']}[0]['uid'])) {
38
+    if (isset($context->data->{$conf['field_name']}[0]['uid']) && ($uid = $context->data->{$conf['field_name']}[0]['uid'])) {
39 39
     if ($account = user_load(array('uid' => $uid))) {
40
-      return ctools_context_create('user', $account);
40
+        return ctools_context_create('user', $account);
41
+    }
41 42
     }
42
-  }
43 43
 }
44 44
 
45 45
 /**
46 46
  * Settings form for the ctools relationship.
47 47
  */
48 48
 function userreference_user_from_userref_settings_form($conf) {
49
-  $options = array();
50
-  foreach (content_fields() as $field) {
49
+    $options = array();
50
+    foreach (content_fields() as $field) {
51 51
     if ($field['type'] == 'userreference') {
52
-      $options[$field['field_name']] = t($field['widget']['label']);
52
+        $options[$field['field_name']] = t($field['widget']['label']);
53
+    }
53 54
     }
54
-  }
55
-  $form['field_name'] = array(
55
+    $form['field_name'] = array(
56 56
     '#title' => t('User reference field'),
57 57
     '#type' => 'select',
58 58
     '#options' => $options,
59 59
     '#default_value' => isset($conf['field_name']) ? $conf['field_name'] : '',
60 60
     '#prefix' => '<div class="clear-block">',
61 61
     '#suffix' => '</div>',
62
-  );
62
+    );
63 63
 
64
-  return $form;
64
+    return $form;
65 65
 }
Please login to merge, or discard this patch.
boinc/modules/contrib/cck/modules/userreference/userreference.rules.inc 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -10,39 +10,39 @@  discard block
 block discarded – undo
10 10
  * Implementation of hook_rules_action_info()
11 11
  */
12 12
 function userreference_rules_action_info() {
13
-  $info = array();
14
-  $info['userreference_rules_action_load'] = array(
13
+    $info = array();
14
+    $info['userreference_rules_action_load'] = array(
15 15
     'label' => t('Load a referenced user'),
16 16
     'arguments' => array(
17
-      'node' => array(
17
+        'node' => array(
18 18
         'type' => 'node',
19 19
         'label' => t('Content containing the user reference field'),
20
-      ),
20
+        ),
21 21
     ),
22 22
     'new variables' => array(
23
-      'referenced_user' => array(
23
+        'referenced_user' => array(
24 24
         'type' => 'user',
25 25
         'label' => t('Referenced user'),
26
-      ),
26
+        ),
27 27
     ),
28 28
     'module' => 'CCK',
29 29
     'help' => t('Note that if the field has multiple values, only the first user will be loaded.'),
30
-  );
31
-  return $info;
30
+    );
31
+    return $info;
32 32
 }
33 33
 
34 34
 function userreference_rules_action_load($node, $settings) {
35
-  $uid = $node->{$settings['field']}[0]['uid'];
36
-  if (isset($uid)) {
35
+    $uid = $node->{$settings['field']}[0]['uid'];
36
+    if (isset($uid)) {
37 37
     $user = user_load(array('uid' => $uid));
38 38
     return array('referenced_user' => $user);
39
-  }
39
+    }
40 40
 }
41 41
 
42 42
 function userreference_rules_action_load_form($settings, &$form) {
43
-  $settings += array('field' => '');
44
-  $options = content_rules_get_field_names_by_type('userreference');
45
-  $form['settings']['field'] = array(
43
+    $settings += array('field' => '');
44
+    $options = content_rules_get_field_names_by_type('userreference');
45
+    $form['settings']['field'] = array(
46 46
     '#type' => 'select',
47 47
     '#title' => t('Field'),
48 48
     '#default_value' => $settings['field'],
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     '#required' => TRUE,
51 51
     '#disabled' => empty($options),
52 52
     '#description' => empty($options) ? t('There are no userreference fields defined.') : '',
53
-  );
53
+    );
54 54
 }
55 55
 
56 56
 /**
@@ -58,5 +58,5 @@  discard block
 block discarded – undo
58 58
  * "workflow_ng_action_load_referenced_user" to the equivalent rules action.
59 59
  */
60 60
 function workflow_ng_action_load_referenced_user_upgrade(&$element) {
61
-  $element['#name'] = 'userreference_rules_action_load';
61
+    $element['#name'] = 'userreference_rules_action_load';
62 62
 }
Please login to merge, or discard this patch.
boinc/modules/contrib/cck/modules/userreference/userreference.module 1 patch
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -10,258 +10,258 @@  discard block
 block discarded – undo
10 10
  * Implementation of hook_menu().
11 11
  */
12 12
 function userreference_menu() {
13
-  $items = array();
14
-  $items['userreference/autocomplete'] = array(
13
+    $items = array();
14
+    $items['userreference/autocomplete'] = array(
15 15
     'title' => 'Userreference autocomplete',
16 16
     'page callback' => 'userreference_autocomplete',
17 17
     'access arguments' => array('access content'),
18 18
     'type' => MENU_CALLBACK
19
-  );
20
-  return $items;
19
+    );
20
+    return $items;
21 21
 }
22 22
 
23 23
 /**
24 24
  * Implementation of hook_theme().
25 25
  */
26 26
 function userreference_theme() {
27
-  return array(
27
+    return array(
28 28
     'userreference_select' => array(
29
-      'arguments' => array('element' => NULL),
29
+        'arguments' => array('element' => NULL),
30 30
     ),
31 31
     'userreference_buttons' => array(
32
-      'arguments' => array('element' => NULL),
32
+        'arguments' => array('element' => NULL),
33 33
     ),
34 34
     'userreference_autocomplete' => array(
35
-      'arguments' => array('element' => NULL),
35
+        'arguments' => array('element' => NULL),
36 36
     ),
37 37
     'userreference_formatter_default' => array(
38
-      'arguments' => array('element'),
38
+        'arguments' => array('element'),
39 39
     ),
40 40
     'userreference_formatter_plain' => array(
41
-      'arguments' => array('element'),
41
+        'arguments' => array('element'),
42 42
     ),
43
-  );
43
+    );
44 44
 }
45 45
 
46 46
 /**
47 47
  * Implementaion of hook_ctools_plugin_directory().
48 48
  */
49 49
 function userreference_ctools_plugin_directory($module, $plugin) {
50
-  if ($module == 'ctools' && $plugin == 'relationships') {
50
+    if ($module == 'ctools' && $plugin == 'relationships') {
51 51
     return 'panels/' . $plugin;
52
-  }
52
+    }
53 53
 }
54 54
 
55 55
 /**
56 56
  * Implementation of hook_field_info().
57 57
  */
58 58
 function userreference_field_info() {
59
-  return array(
59
+    return array(
60 60
     'userreference' => array(
61
-      'label' => t('User reference'),
62
-      'description' => t('Store the ID of a related user as an integer value.'),
61
+        'label' => t('User reference'),
62
+        'description' => t('Store the ID of a related user as an integer value.'),
63 63
 //      'content_icon' => 'icon_content_noderef.png',
64 64
     ),
65
-  );
65
+    );
66 66
 }
67 67
 
68 68
 /**
69 69
  * Implementation of hook_field_settings().
70 70
  */
71 71
 function userreference_field_settings($op, $field) {
72
-  switch ($op) {
72
+    switch ($op) {
73 73
     case 'form':
74 74
       $form = array();
75
-      $form['referenceable_roles'] = array(
75
+        $form['referenceable_roles'] = array(
76 76
         '#type' => 'checkboxes',
77 77
         '#title' => t('User roles that can be referenced'),
78 78
         '#default_value' => isset($field['referenceable_roles']) && is_array($field['referenceable_roles']) ? array_filter($field['referenceable_roles']) : array(),
79 79
         '#options' => user_roles(1),
80
-      );
81
-      $form['referenceable_status'] = array(
80
+        );
81
+        $form['referenceable_status'] = array(
82 82
         '#type' => 'radios',
83 83
         '#title' => t('User status that can be referenced'),
84 84
         '#default_value' => isset($field['referenceable_status']) ? $field['referenceable_status'] : '',
85 85
         '#options' => array('' => t('All users'), 1 => t('Active users'), 0 => t('Blocked users')),
86
-      );
87
-      if (module_exists('views')) {
86
+        );
87
+        if (module_exists('views')) {
88 88
         $views = array('--' => '--');
89 89
         $all_views = views_get_all_views();
90 90
         foreach ($all_views as $view) {
91
-          // Only 'users' views that have fields will work for our purpose.
92
-          if ($view->base_table == 'users' && !empty($view->display['default']->display_options['fields'])) {
91
+            // Only 'users' views that have fields will work for our purpose.
92
+            if ($view->base_table == 'users' && !empty($view->display['default']->display_options['fields'])) {
93 93
             if ($view->type == 'Default') {
94
-              $views[t('Default Views')][$view->name] = $view->name;
94
+                $views[t('Default Views')][$view->name] = $view->name;
95 95
             }
96 96
             else {
97
-              $views[t('Existing Views')][$view->name] = $view->name;
97
+                $views[t('Existing Views')][$view->name] = $view->name;
98
+            }
98 99
             }
99
-          }
100 100
         }
101 101
 
102 102
         $form['advanced'] = array(
103
-           '#type' => 'fieldset',
104
-           '#title' => t('Advanced - Users that can be referenced (View)'),
105
-           '#collapsible' => TRUE,
106
-           '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--',
107
-         );
103
+            '#type' => 'fieldset',
104
+            '#title' => t('Advanced - Users that can be referenced (View)'),
105
+            '#collapsible' => TRUE,
106
+            '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--',
107
+            );
108 108
         if (count($views) > 1) {
109
-          $form['advanced']['advanced_view'] = array(
109
+            $form['advanced']['advanced_view'] = array(
110 110
             '#type' => 'select',
111 111
             '#title' => t('View used to select the users'),
112 112
             '#options' => $views,
113 113
             '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--',
114 114
             '#description' =>  t('<p>Choose the "Views module" view that selects the users that can be referenced.<br />Note:</p>') .
115
-              t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'),
116
-          );
117
-          $form['advanced']['advanced_view_args'] = array(
115
+                t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'),
116
+            );
117
+            $form['advanced']['advanced_view_args'] = array(
118 118
             '#type' => 'textfield',
119 119
             '#title' => t('View arguments'),
120 120
             '#default_value' => isset($field['advanced_view_args']) ? $field['advanced_view_args'] : '',
121 121
             '#required' => FALSE,
122 122
             '#description' => t('Provide a comma separated list of arguments to pass to the view.'),
123
-          );
123
+            );
124 124
         }
125 125
         else {
126
-          $form['advanced']['no_view_help'] = array(
126
+            $form['advanced']['no_view_help'] = array(
127 127
             '#value' => t('<p>The list of user that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') .
128
-              t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'),
129
-          );
128
+                t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'),
129
+            );
130
+        }
130 131
         }
131
-      }
132
-      return $form;
132
+        return $form;
133 133
 
134 134
     case 'save':
135 135
       $settings = array('referenceable_roles', 'referenceable_status');
136
-      if (module_exists('views')) {
136
+        if (module_exists('views')) {
137 137
         $settings[] = 'advanced_view';
138 138
         $settings[] = 'advanced_view_args';
139
-      }
140
-      return $settings;
139
+        }
140
+        return $settings;
141 141
 
142 142
     case 'database columns':
143 143
       $columns = array(
144 144
         'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'index' => TRUE),
145
-      );
146
-      return $columns;
145
+        );
146
+        return $columns;
147 147
 
148 148
     case 'views data':
149 149
       $data = content_views_field_views_data($field);
150
-      $db_info = content_database_info($field);
151
-      $table_alias = content_views_tablename($field);
152
-
153
-      // Filter : swap the handler to the 'in' operator.
154
-      $data[$table_alias][$field['field_name'] .'_uid']['filter']['handler'] = 'content_handler_filter_many_to_one';
155
-      // Argument: get the user name for summaries.
156
-      // We need to join a new instance of the users table.
157
-      $data["users_$table_alias"]['table']['join']['node'] = array(
150
+        $db_info = content_database_info($field);
151
+        $table_alias = content_views_tablename($field);
152
+
153
+        // Filter : swap the handler to the 'in' operator.
154
+        $data[$table_alias][$field['field_name'] .'_uid']['filter']['handler'] = 'content_handler_filter_many_to_one';
155
+        // Argument: get the user name for summaries.
156
+        // We need to join a new instance of the users table.
157
+        $data["users_$table_alias"]['table']['join']['node'] = array(
158 158
         'table' => 'users',
159 159
         'field' => 'uid',
160 160
         'left_table' => $table_alias,
161 161
         'left_field' => $field['field_name'] .'_uid',
162
-      );
163
-      $data[$table_alias][$field['field_name'] .'_uid']['argument']['handler'] = 'content_handler_argument_reference';
164
-      $data[$table_alias][$field['field_name'] .'_uid']['argument']['name table'] = "users_$table_alias";
165
-      $data[$table_alias][$field['field_name'] .'_uid']['argument']['name field'] = 'name';
166
-      // Relationship: Add a relationship for related user.
167
-      $data[$table_alias][$field['field_name'] .'_uid']['relationship'] = array(
162
+        );
163
+        $data[$table_alias][$field['field_name'] .'_uid']['argument']['handler'] = 'content_handler_argument_reference';
164
+        $data[$table_alias][$field['field_name'] .'_uid']['argument']['name table'] = "users_$table_alias";
165
+        $data[$table_alias][$field['field_name'] .'_uid']['argument']['name field'] = 'name';
166
+        // Relationship: Add a relationship for related user.
167
+        $data[$table_alias][$field['field_name'] .'_uid']['relationship'] = array(
168 168
         'base' => 'users',
169 169
         'field' => $db_info['columns']['uid']['column'],
170 170
         'handler' => 'content_handler_relationship',
171 171
         'label' => t($field['widget']['label']),
172 172
         'content_field_name' => $field['field_name'],
173
-      );
174
-      return $data;
173
+        );
174
+        return $data;
175 175
 
176
-  }
176
+    }
177 177
 }
178 178
 
179 179
 /**
180 180
  * Implementation of hook_field().
181 181
  */
182 182
 function userreference_field($op, &$node, $field, &$items, $teaser, $page) {
183
-  switch ($op) {
183
+    switch ($op) {
184 184
     case 'validate':
185 185
       // Extract uids to check.
186 186
       $ids = array();
187
-      foreach ($items as $delta => $item) {
187
+        foreach ($items as $delta => $item) {
188 188
         if (is_array($item) && !empty($item['uid'])) {
189
-          if (is_numeric($item['uid'])) {
189
+            if (is_numeric($item['uid'])) {
190 190
             $ids[] = $item['uid'];
191
-          }
192
-          else {
191
+            }
192
+            else {
193 193
             $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
194 194
             if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']);
195 195
             form_set_error($error_element, t('%name: invalid input.', array('%name' => t($field['widget']['label']))));
196
-          }
196
+            }
197
+        }
197 198
         }
198
-      }
199
-      // Prevent performance hog if there are no ids to check.
200
-      if ($ids) {
199
+        // Prevent performance hog if there are no ids to check.
200
+        if ($ids) {
201 201
         $refs = _userreference_potential_references($field, '', NULL, $ids);
202 202
         foreach ($items as $delta => $item) {
203
-          if (is_array($item)) {
203
+            if (is_array($item)) {
204 204
             $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
205 205
             if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']);
206 206
             if (!empty($item['uid']) && !isset($refs[$item['uid']])) {
207
-              form_set_error($error_element, t('%name: invalid user.', array('%name' => t($field['widget']['label']))));
207
+                form_set_error($error_element, t('%name: invalid user.', array('%name' => t($field['widget']['label']))));
208
+            }
208 209
             }
209
-          }
210 210
         }
211
-      }
212
-      return $items;
213
-  }
211
+        }
212
+        return $items;
213
+    }
214 214
 }
215 215
 
216 216
 /**
217 217
  * Implementation of hook_content_is_empty().
218 218
  */
219 219
 function userreference_content_is_empty($item, $field) {
220
-  if (empty($item['uid'])) {
220
+    if (empty($item['uid'])) {
221 221
     return TRUE;
222
-  }
223
-  return FALSE;
222
+    }
223
+    return FALSE;
224 224
 }
225 225
 
226 226
 /**
227 227
  * Implementation of hook_field_formatter_info().
228 228
  */
229 229
 function userreference_field_formatter_info() {
230
-  return array(
230
+    return array(
231 231
     'default' => array(
232
-      'label' => t('Default'),
233
-      'field types' => array('userreference'),
234
-      'multiple values' => CONTENT_HANDLE_CORE,
232
+        'label' => t('Default'),
233
+        'field types' => array('userreference'),
234
+        'multiple values' => CONTENT_HANDLE_CORE,
235 235
     ),
236 236
     'plain' => array(
237
-      'label' => t('Plain text'),
238
-      'field types' => array('userreference'),
239
-      'multiple values' => CONTENT_HANDLE_CORE,
237
+        'label' => t('Plain text'),
238
+        'field types' => array('userreference'),
239
+        'multiple values' => CONTENT_HANDLE_CORE,
240 240
     ),
241
-  );
241
+    );
242 242
 }
243 243
 
244 244
 /**
245 245
  * Theme function for 'default' userreference field formatter.
246 246
  */
247 247
 function theme_userreference_formatter_default($element) {
248
-  $output = '';
248
+    $output = '';
249 249
 
250
-  if (isset($element['#item']['uid']) && $account = user_load(array('uid' => $element['#item']['uid']))) {
250
+    if (isset($element['#item']['uid']) && $account = user_load(array('uid' => $element['#item']['uid']))) {
251 251
     $output = theme('username', $account);
252
-  }
253
-  return $output;
252
+    }
253
+    return $output;
254 254
 }
255 255
 
256 256
 /**
257 257
  * Theme function for 'plain' userreference field formatter.
258 258
  */
259 259
 function theme_userreference_formatter_plain($element) {
260
-  $output = '';
261
-  if (isset($element['#item']['uid']) && $account = user_load(array('uid' => $element['#item']['uid']))) {
260
+    $output = '';
261
+    if (isset($element['#item']['uid']) && $account = user_load(array('uid' => $element['#item']['uid']))) {
262 262
     $output = $account->name;
263
-  }
264
-  return $output;
263
+    }
264
+    return $output;
265 265
 }
266 266
 
267 267
 /**
@@ -279,32 +279,32 @@  discard block
 block discarded – undo
279 279
  * differently.
280 280
  */
281 281
 function userreference_widget_info() {
282
-  return array(
282
+    return array(
283 283
     'userreference_select' => array(
284
-      'label' => t('Select list'),
285
-      'field types' => array('userreference'),
286
-      'multiple values' => CONTENT_HANDLE_MODULE,
287
-      'callbacks' => array(
284
+        'label' => t('Select list'),
285
+        'field types' => array('userreference'),
286
+        'multiple values' => CONTENT_HANDLE_MODULE,
287
+        'callbacks' => array(
288 288
         'default value' => CONTENT_CALLBACK_DEFAULT,
289
-      ),
289
+        ),
290 290
     ),
291 291
     'userreference_buttons' => array(
292
-      'label' => t('Check boxes/radio buttons'),
293
-      'field types' => array('userreference'),
294
-      'multiple values' => CONTENT_HANDLE_MODULE,
295
-      'callbacks' => array(
292
+        'label' => t('Check boxes/radio buttons'),
293
+        'field types' => array('userreference'),
294
+        'multiple values' => CONTENT_HANDLE_MODULE,
295
+        'callbacks' => array(
296 296
         'default value' => CONTENT_CALLBACK_DEFAULT,
297
-      ),
297
+        ),
298 298
     ),
299 299
     'userreference_autocomplete' => array(
300
-      'label' => t('Autocomplete text field'),
301
-      'field types' => array('userreference'),
302
-      'multiple values' => CONTENT_HANDLE_CORE,
303
-      'callbacks' => array(
300
+        'label' => t('Autocomplete text field'),
301
+        'field types' => array('userreference'),
302
+        'multiple values' => CONTENT_HANDLE_CORE,
303
+        'callbacks' => array(
304 304
         'default value' => CONTENT_CALLBACK_DEFAULT,
305
-      ),
305
+        ),
306 306
     ),
307
-  );
307
+    );
308 308
 }
309 309
 
310 310
 /**
@@ -320,23 +320,23 @@  discard block
 block discarded – undo
320 320
  * (see nodereference and userreference).
321 321
  */
322 322
 function userreference_elements() {
323
-  return array(
323
+    return array(
324 324
     'userreference_select' => array(
325
-      '#input' => TRUE,
326
-      '#columns' => array('uid'), '#delta' => 0,
327
-      '#process' => array('userreference_select_process'),
325
+        '#input' => TRUE,
326
+        '#columns' => array('uid'), '#delta' => 0,
327
+        '#process' => array('userreference_select_process'),
328 328
     ),
329 329
     'userreference_buttons' => array(
330
-      '#input' => TRUE,
331
-      '#columns' => array('uid'), '#delta' => 0,
332
-      '#process' => array('userreference_buttons_process'),
330
+        '#input' => TRUE,
331
+        '#columns' => array('uid'), '#delta' => 0,
332
+        '#process' => array('userreference_buttons_process'),
333 333
     ),
334 334
     'userreference_autocomplete' => array(
335
-      '#input' => TRUE,
336
-      '#columns' => array('name'), '#delta' => 0,
337
-      '#process' => array('userreference_autocomplete_process'),
338
-      '#autocomplete_path' => FALSE,
339
-      ),
335
+        '#input' => TRUE,
336
+        '#columns' => array('name'), '#delta' => 0,
337
+        '#process' => array('userreference_autocomplete_process'),
338
+        '#autocomplete_path' => FALSE,
339
+        ),
340 340
     );
341 341
 }
342 342
 
@@ -344,45 +344,45 @@  discard block
 block discarded – undo
344 344
  * Implementation of hook_widget_settings().
345 345
  */
346 346
 function userreference_widget_settings($op, $widget) {
347
-  switch ($op) {
347
+    switch ($op) {
348 348
     case 'form':
349 349
       $form = array();
350
-      $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains';
351
-      $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
352
-      if ($widget['type'] == 'userreference_autocomplete') {
350
+        $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains';
351
+        $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
352
+        if ($widget['type'] == 'userreference_autocomplete') {
353 353
         $form['autocomplete_match'] = array(
354
-          '#type' => 'select',
355
-          '#title' => t('Autocomplete matching'),
356
-          '#default_value' => $match,
357
-          '#options' => array(
354
+            '#type' => 'select',
355
+            '#title' => t('Autocomplete matching'),
356
+            '#default_value' => $match,
357
+            '#options' => array(
358 358
             'starts_with' => t('Starts with'),
359 359
             'contains' => t('Contains'),
360
-          ),
361
-          '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of users.'),
360
+            ),
361
+            '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of users.'),
362 362
         );
363 363
         $form['size'] = array(
364
-          '#type' => 'textfield',
365
-          '#title' => t('Size of textfield'),
366
-          '#default_value' => $size,
367
-          '#element_validate' => array('_element_validate_integer_positive'),
368
-          '#required' => TRUE,
364
+            '#type' => 'textfield',
365
+            '#title' => t('Size of textfield'),
366
+            '#default_value' => $size,
367
+            '#element_validate' => array('_element_validate_integer_positive'),
368
+            '#required' => TRUE,
369 369
         );
370
-      }
371
-      else {
370
+        }
371
+        else {
372 372
         $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match);
373 373
         $form['size'] = array('#type' => 'hidden', '#value' => $size);
374
-      }
375
-      $form['reverse_link'] = array(
374
+        }
375
+        $form['reverse_link'] = array(
376 376
         '#type' => 'checkbox',
377 377
         '#title' => t('Reverse link'),
378 378
         '#default_value' => isset($widget['reverse_link']) ? $widget['reverse_link'] : 0,
379 379
         '#description' => t('If selected, a reverse link back to the referencing node will displayed on the referenced user record.'),
380
-      );
381
-      return $form;
380
+        );
381
+        return $form;
382 382
 
383 383
     case 'save':
384 384
       return array('autocomplete_match', 'size', 'reverse_link');
385
-  }
385
+    }
386 386
 }
387 387
 
388 388
 /**
@@ -417,30 +417,30 @@  discard block
 block discarded – undo
417 417
  *   the form item for a single element for this field
418 418
  */
419 419
 function userreference_widget(&$form, &$form_state, $field, $items, $delta = 0) {
420
-  switch ($field['widget']['type']) {
420
+    switch ($field['widget']['type']) {
421 421
     case 'userreference_select':
422 422
       $element = array(
423 423
         '#type' => 'userreference_select',
424 424
         '#default_value' => $items,
425
-      );
426
-      break;
425
+        );
426
+        break;
427 427
 
428 428
     case 'userreference_buttons':
429 429
       $element = array(
430 430
         '#type' => 'userreference_buttons',
431 431
         '#default_value' => $items,
432
-      );
433
-      break;
432
+        );
433
+        break;
434 434
 
435 435
     case 'userreference_autocomplete':
436 436
       $element = array(
437 437
         '#type' => 'userreference_autocomplete',
438 438
         '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
439 439
         '#value_callback' => 'userreference_autocomplete_value',
440
-      );
441
-      break;
442
-  }
443
-  return $element;
440
+        );
441
+        break;
442
+    }
443
+    return $element;
444 444
 }
445 445
 
446 446
 /**
@@ -449,12 +449,12 @@  discard block
 block discarded – undo
449 449
  * Substitute in the user name for the uid.
450 450
  */
451 451
 function userreference_autocomplete_value($element, $edit = FALSE) {
452
-  $field_key  = $element['#columns'][0];
453
-  if (!empty($element['#default_value'][$field_key])) {
452
+    $field_key  = $element['#columns'][0];
453
+    if (!empty($element['#default_value'][$field_key])) {
454 454
     $value = db_result(db_query("SELECT name FROM {users} WHERE uid = '%d'", $element['#default_value'][$field_key]));
455 455
     return array($field_key => $value);
456
-  }
457
-  return array($field_key => NULL);
456
+    }
457
+    return array($field_key => NULL);
458 458
 }
459 459
 
460 460
 /**
@@ -466,11 +466,11 @@  discard block
 block discarded – undo
466 466
  * The $fields array is in $form['#field_info'][$element['#field_name']].
467 467
  */
468 468
 function userreference_select_process($element, $edit, $form_state, $form) {
469
-  // The userreference_select widget doesn't need to create its own
470
-  // element, it can wrap around the optionwidgets_select element.
471
-  // Add a validation step where the value can be unwrapped.
472
-  $field_key  = $element['#columns'][0];
473
-  $element[$field_key] = array(
469
+    // The userreference_select widget doesn't need to create its own
470
+    // element, it can wrap around the optionwidgets_select element.
471
+    // Add a validation step where the value can be unwrapped.
472
+    $field_key  = $element['#columns'][0];
473
+    $element[$field_key] = array(
474 474
     '#type' => 'optionwidgets_select',
475 475
     '#default_value' => isset($element['#value']) ? $element['#value'] : '',
476 476
     // The following values were set by the content module and need
@@ -482,12 +482,12 @@  discard block
 block discarded – undo
482 482
     '#type_name' => $element['#type_name'],
483 483
     '#delta' => $element['#delta'],
484 484
     '#columns' => $element['#columns'],
485
-  );
486
-  if (empty($element[$field_key]['#element_validate'])) {
485
+    );
486
+    if (empty($element[$field_key]['#element_validate'])) {
487 487
     $element[$field_key]['#element_validate'] = array();
488
-  }
489
-  array_unshift($element[$field_key]['#element_validate'], 'userreference_optionwidgets_validate');
490
-  return $element;
488
+    }
489
+    array_unshift($element[$field_key]['#element_validate'], 'userreference_optionwidgets_validate');
490
+    return $element;
491 491
 }
492 492
 
493 493
 /**
@@ -499,11 +499,11 @@  discard block
 block discarded – undo
499 499
  * The $fields array is in $form['#field_info'][$element['#field_name']].
500 500
  */
501 501
 function userreference_buttons_process($element, $edit, $form_state, $form) {
502
-  // The userreference_select widget doesn't need to create its own
503
-  // element, it can wrap around the optionwidgets_select element.
504
-  // Add a validation step where the value can be unwrapped.
505
-  $field_key  = $element['#columns'][0];
506
-  $element[$field_key] = array(
502
+    // The userreference_select widget doesn't need to create its own
503
+    // element, it can wrap around the optionwidgets_select element.
504
+    // Add a validation step where the value can be unwrapped.
505
+    $field_key  = $element['#columns'][0];
506
+    $element[$field_key] = array(
507 507
     '#type' => 'optionwidgets_buttons',
508 508
     '#default_value' => isset($element['#value']) ? $element['#value'] : '',
509 509
     // The following values were set by the content module and need
@@ -515,12 +515,12 @@  discard block
 block discarded – undo
515 515
     '#type_name' => $element['#type_name'],
516 516
     '#delta' => $element['#delta'],
517 517
     '#columns' => $element['#columns'],
518
-  );
519
-  if (empty($element[$field_key]['#element_validate'])) {
518
+    );
519
+    if (empty($element[$field_key]['#element_validate'])) {
520 520
     $element[$field_key]['#element_validate'] = array();
521
-  }
522
-  array_unshift($element[$field_key]['#element_validate'], 'userreference_optionwidgets_validate');
523
-  return $element;
521
+    }
522
+    array_unshift($element[$field_key]['#element_validate'], 'userreference_optionwidgets_validate');
523
+    return $element;
524 524
 }
525 525
 
526 526
 /**
@@ -531,13 +531,13 @@  discard block
 block discarded – undo
531 531
  *
532 532
  */
533 533
 function userreference_autocomplete_process($element, $edit, $form_state, $form) {
534
-  // The userreference autocomplete widget doesn't need to create its own
535
-  // element, it can wrap around the text_textfield element and add an autocomplete
536
-  // path and some extra processing to it.
537
-  // Add a validation step where the value can be unwrapped.
538
-  $field_key  = $element['#columns'][0];
534
+    // The userreference autocomplete widget doesn't need to create its own
535
+    // element, it can wrap around the text_textfield element and add an autocomplete
536
+    // path and some extra processing to it.
537
+    // Add a validation step where the value can be unwrapped.
538
+    $field_key  = $element['#columns'][0];
539 539
 
540
-  $element[$field_key] = array(
540
+    $element[$field_key] = array(
541 541
     '#type' => 'text_textfield',
542 542
     '#default_value' => isset($element['#value']) ? $element['#value'] : '',
543 543
     '#autocomplete_path' => 'userreference/autocomplete/'. $element['#field_name'],
@@ -550,20 +550,20 @@  discard block
 block discarded – undo
550 550
     '#type_name' => $element['#type_name'],
551 551
     '#delta' => $element['#delta'],
552 552
     '#columns' => $element['#columns'],
553
-  );
554
-  if (empty($element[$field_key]['#element_validate'])) {
553
+    );
554
+    if (empty($element[$field_key]['#element_validate'])) {
555 555
     $element[$field_key]['#element_validate'] = array();
556
-  }
557
-  array_unshift($element[$field_key]['#element_validate'], 'userreference_autocomplete_validate');
556
+    }
557
+    array_unshift($element[$field_key]['#element_validate'], 'userreference_autocomplete_validate');
558 558
 
559
-  // Used so that hook_field('validate') knows where to flag an error.
560
-  $element['_error_element'] = array(
559
+    // Used so that hook_field('validate') knows where to flag an error.
560
+    $element['_error_element'] = array(
561 561
     '#type' => 'value',
562 562
     // Wrapping the element around a text_textfield element creates a
563 563
     // nested element, so the final id will look like 'field-name-0-uid-uid'.
564 564
     '#value' => implode('][', array_merge($element['#parents'], array($field_key, $field_key))),
565
-  );
566
-  return $element;
565
+    );
566
+    return $element;
567 567
 }
568 568
 
569 569
 /**
@@ -578,20 +578,20 @@  discard block
 block discarded – undo
578 578
  * like optionwidgets are using #element_validate to alter the value.
579 579
  */
580 580
 function userreference_optionwidgets_validate($element, &$form_state) {
581
-  $field_key  = $element['#columns'][0];
581
+    $field_key  = $element['#columns'][0];
582 582
 
583
-  $value = $form_state['values'];
584
-  $new_parents = array();
585
-  foreach ($element['#parents'] as $parent) {
583
+    $value = $form_state['values'];
584
+    $new_parents = array();
585
+    foreach ($element['#parents'] as $parent) {
586 586
     $value = $value[$parent];
587 587
     // Use === to be sure we get right results if parent is a zero (delta) value.
588 588
     if ($parent === $field_key) {
589
-      $element['#parents'] = $new_parents;
590
-      form_set_value($element, $value, $form_state);
591
-      break;
589
+        $element['#parents'] = $new_parents;
590
+        form_set_value($element, $value, $form_state);
591
+        break;
592 592
     }
593 593
     $new_parents[] = $parent;
594
-  }
594
+    }
595 595
 }
596 596
 
597 597
 /**
@@ -602,36 +602,36 @@  discard block
 block discarded – undo
602 602
  * back to its original location, 'field-name-0-uid'.
603 603
  */
604 604
 function userreference_autocomplete_validate($element, &$form_state) {
605
-  $field_name = $element['#field_name'];
606
-  $type_name = $element['#type_name'];
607
-  $field = content_fields($field_name, $type_name);
608
-  $field_key = $element['#columns'][0];
609
-  $value = $element['#value'][$field_key];
610
-  $uid = NULL;
611
-  if (!empty($value)) {
605
+    $field_name = $element['#field_name'];
606
+    $type_name = $element['#type_name'];
607
+    $field = content_fields($field_name, $type_name);
608
+    $field_key = $element['#columns'][0];
609
+    $value = $element['#value'][$field_key];
610
+    $uid = NULL;
611
+    if (!empty($value)) {
612 612
     $reference = _userreference_potential_references($field, $value, 'equals', NULL, 1);
613 613
     if (empty($reference)) {
614
-      form_error($element[$field_key], t('%name: found no valid user with that name.', array('%name' => t($field['widget']['label']))));
614
+        form_error($element[$field_key], t('%name: found no valid user with that name.', array('%name' => t($field['widget']['label']))));
615 615
     }
616 616
     else {
617
-      $uid = key($reference);
617
+        $uid = key($reference);
618
+    }
618 619
     }
619
-  }
620
-  form_set_value($element, $uid, $form_state);
620
+    form_set_value($element, $uid, $form_state);
621 621
 }
622 622
 
623 623
 /**
624 624
  * Implementation of hook_allowed_values().
625 625
  */
626 626
 function userreference_allowed_values($field) {
627
-  $references = _userreference_potential_references($field);
627
+    $references = _userreference_potential_references($field);
628 628
 
629
-  $options = array();
630
-  foreach ($references as $key => $value) {
629
+    $options = array();
630
+    foreach ($references as $key => $value) {
631 631
     $options[$key] = $value['rendered'];
632
-  }
632
+    }
633 633
 
634
-  return $options;
634
+    return $options;
635 635
 }
636 636
 
637 637
 /**
@@ -667,26 +667,26 @@  discard block
 block discarded – undo
667 667
  *   )
668 668
  */
669 669
 function _userreference_potential_references($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) {
670
-  static $results = array();
670
+    static $results = array();
671 671
 
672
-  // Create unique id for static cache.
673
-  $cid = $field['field_name'] .':'. $match .':'. ($string !== '' ? $string : implode('-', $ids)) .':'. $limit;
674
-  if (!isset($results[$cid])) {
672
+    // Create unique id for static cache.
673
+    $cid = $field['field_name'] .':'. $match .':'. ($string !== '' ? $string : implode('-', $ids)) .':'. $limit;
674
+    if (!isset($results[$cid])) {
675 675
     $references = FALSE;
676 676
     if (module_exists('views') && !empty($field['advanced_view']) && $field['advanced_view'] != '--') {
677
-      $references = _userreference_potential_references_views($field, $string, $match, $ids, $limit);
677
+        $references = _userreference_potential_references_views($field, $string, $match, $ids, $limit);
678 678
     }
679 679
     // If the view doesn't exist, we got FALSE, and fallback to the regular 'standard mode'.
680 680
 
681 681
     if ($references === FALSE) {
682
-      $references = _userreference_potential_references_standard($field, $string, $match, $ids, $limit);
682
+        $references = _userreference_potential_references_standard($field, $string, $match, $ids, $limit);
683 683
     }
684 684
 
685 685
     // Store the results.
686 686
     $results[$cid] = !empty($references) ? $references : array();
687
-  }
687
+    }
688 688
 
689
-  return $results[$cid];
689
+    return $results[$cid];
690 690
 }
691 691
 
692 692
 /**
@@ -694,9 +694,9 @@  discard block
 block discarded – undo
694 694
  * case of Views-defined referenceable users.
695 695
  */
696 696
 function _userreference_potential_references_views($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) {
697
-  $view_name = $field['advanced_view'];
697
+    $view_name = $field['advanced_view'];
698 698
 
699
-  if ($view = views_get_view($view_name)) {
699
+    if ($view = views_get_view($view_name)) {
700 700
     // We add a display, and let it derive from the 'default' display.
701 701
     // TODO: We should let the user pick a display in the fields settings - sort of requires AHAH...
702 702
     $display = $view->add_display('content_references');
@@ -713,12 +713,12 @@  discard block
 block discarded – undo
713 713
     // Additional options to let content_plugin_display_references::query()
714 714
     // narrow the results.
715 715
     $options = array(
716
-      'table' => 'users',
717
-      'field_string' => 'name',
718
-      'string' => $string,
719
-      'match' => $match,
720
-      'field_id' => 'uid',
721
-      'ids' => $ids,
716
+        'table' => 'users',
717
+        'field_string' => 'name',
718
+        'string' => $string,
719
+        'match' => $match,
720
+        'field_id' => 'uid',
721
+        'ids' => $ids,
722 722
     );
723 723
     $view->display_handler->set_option('content_options', $options);
724 724
 
@@ -731,26 +731,26 @@  discard block
 block discarded – undo
731 731
 
732 732
     // Get arguments for the view.
733 733
     if (!empty($field['advanced_view_args'])) {
734
-      // TODO: Support Tokens using token.module ?
735
-      $view_args = array_map('trim', explode(',', $field['advanced_view_args']));
734
+        // TODO: Support Tokens using token.module ?
735
+        $view_args = array_map('trim', explode(',', $field['advanced_view_args']));
736 736
     }
737 737
     else {
738
-      $view_args = array();
738
+        $view_args = array();
739 739
     }
740 740
 
741 741
     // We do need name field, so add it if not present (unlikely, but...)
742 742
     $fields = $view->get_items('field', $display);
743 743
     if (!isset($fields['name'])) {
744
-      $view->add_item($display, 'field', 'users', 'name');
744
+        $view->add_item($display, 'field', 'users', 'name');
745 745
     }
746 746
 
747 747
     // If not set, make all fields inline and define a separator.
748 748
     $options = $view->display_handler->get_option('row_options');
749 749
     if (empty($options['inline'])) {
750
-      $options['inline'] = drupal_map_assoc(array_keys($view->get_items('field', $display)));
750
+        $options['inline'] = drupal_map_assoc(array_keys($view->get_items('field', $display)));
751 751
     }
752 752
     if (empty($options['separator'])) {
753
-      $options['separator'] = '-';
753
+        $options['separator'] = '-';
754 754
     }
755 755
     $view->display_handler->set_option('row_options', $options);
756 756
 
@@ -759,12 +759,12 @@  discard block
 block discarded – undo
759 759
 
760 760
     // Get the results.
761 761
     $result = $view->execute_display($display, $view_args);
762
-  }
763
-  else {
762
+    }
763
+    else {
764 764
     $result = FALSE;
765
-  }
765
+    }
766 766
 
767
-  return $result;
767
+    return $result;
768 768
 }
769 769
 
770 770
 /**
@@ -772,112 +772,112 @@  discard block
 block discarded – undo
772 772
  * referenceable users defined by user role and status
773 773
  */
774 774
 function _userreference_potential_references_standard($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) {
775
-  $where = array();
776
-  $args = array();
777
-  $join = array();
775
+    $where = array();
776
+    $args = array();
777
+    $join = array();
778 778
 
779
-  if ($string !== '') {
779
+    if ($string !== '') {
780 780
     $like = $GLOBALS["db_type"] == 'pgsql' ? "ILIKE" : "LIKE";
781 781
     $match_clauses = array(
782
-      'contains' => "$like '%%%s%%'",
783
-      'equals' => "= '%s'",
784
-      'starts_with' => "$like '%s%%'",
782
+        'contains' => "$like '%%%s%%'",
783
+        'equals' => "= '%s'",
784
+        'starts_with' => "$like '%s%%'",
785 785
     );
786 786
     $where[] = 'u.name '. (isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']);
787 787
     $args[] = $string;
788
-  }
789
-  elseif ($ids) {
788
+    }
789
+    elseif ($ids) {
790 790
     $where[] = 'u.uid IN (' . db_placeholders($ids) . ')';
791 791
     $args = array_merge($args, $ids);
792
-  }
793
-  else {
792
+    }
793
+    else {
794 794
     $where[] = "u.uid > 0";
795
-  }
795
+    }
796 796
 
797
-  $roles = array();
798
-  if (isset($field['referenceable_roles']) && is_array($field['referenceable_roles'])) {
797
+    $roles = array();
798
+    if (isset($field['referenceable_roles']) && is_array($field['referenceable_roles'])) {
799 799
     // keep only selected checkboxes
800 800
     $roles = array_filter($field['referenceable_roles']);
801 801
     // filter invalid values that seems to get through sometimes ??
802 802
     $roles = array_intersect(array_keys(user_roles(1)), $roles);
803
-  }
804
-  if (!empty($roles) && !in_array(DRUPAL_AUTHENTICATED_RID, $roles)) {
803
+    }
804
+    if (!empty($roles) && !in_array(DRUPAL_AUTHENTICATED_RID, $roles)) {
805 805
     $where[] = "r.rid IN (". implode($roles, ',') .")";
806 806
     $join[] = 'LEFT JOIN {users_roles} r ON u.uid = r.uid';
807
-  }
807
+    }
808 808
 
809
-  if (isset($field['referenceable_status']) && is_numeric($field['referenceable_status'])) {
809
+    if (isset($field['referenceable_status']) && is_numeric($field['referenceable_status'])) {
810 810
     $where[] = 'u.status = %d';
811 811
     $args[] = $field['referenceable_status'];
812
-  }
812
+    }
813 813
 
814
-  $users = array();
815
-  $where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : '';
816
-  $result = db_query('SELECT u.name, u.uid FROM {users} u '. implode(' ', $join) ." $where_clause ORDER BY u.name ASC", $args);
817
-  while ($user = db_fetch_object($result)) {
814
+    $users = array();
815
+    $where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : '';
816
+    $result = db_query('SELECT u.name, u.uid FROM {users} u '. implode(' ', $join) ." $where_clause ORDER BY u.name ASC", $args);
817
+    while ($user = db_fetch_object($result)) {
818 818
     $users[$user->uid] = array(
819
-      'title' => $user->name,
820
-      'rendered' => check_plain($user->name),
819
+        'title' => $user->name,
820
+        'rendered' => check_plain($user->name),
821 821
     );
822
-  }
823
-  return $users;
822
+    }
823
+    return $users;
824 824
 }
825 825
 
826 826
 /**
827 827
  * Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing users
828 828
  */
829 829
 function userreference_autocomplete($field_name, $string = '') {
830
-  $fields = content_fields();
831
-  $field = $fields[$field_name];
832
-  $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains';
833
-  $matches = array();
830
+    $fields = content_fields();
831
+    $field = $fields[$field_name];
832
+    $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains';
833
+    $matches = array();
834 834
 
835
-  $references = _userreference_potential_references($field, $string, $match, array(), 10);
836
-  foreach ($references as $id => $row) {
835
+    $references = _userreference_potential_references($field, $string, $match, array(), 10);
836
+    foreach ($references as $id => $row) {
837 837
     // Add a class wrapper for a few required CSS overrides.
838 838
     $matches[$row['title']] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>';
839
-  }
840
-  drupal_json($matches);
839
+    }
840
+    drupal_json($matches);
841 841
 }
842 842
 
843 843
 /**
844 844
  * Implementation of hook_user().
845 845
  */
846 846
 function userreference_user($type, &$edit, &$account) {
847
-  switch ($type) {
847
+    switch ($type) {
848 848
     case 'load':
849 849
       // Only add links if we are on the user 'view' page.
850 850
       if (arg(0) != 'user' || arg(2)) {
851 851
         return;
852
-      }
853
-      // find CCK userreference field tables
854
-      // search through them for matching user ids and load those nodes
855
-      $additions = array();
856
-      $types = content_types();
857
-
858
-      // Find the table and columns to search through, if the same
859
-      // table comes up in more than one content type, we only need
860
-      // to search it once.
861
-      $search_tables = array();
862
-      foreach ($types as $type_name => $type) {
852
+        }
853
+        // find CCK userreference field tables
854
+        // search through them for matching user ids and load those nodes
855
+        $additions = array();
856
+        $types = content_types();
857
+
858
+        // Find the table and columns to search through, if the same
859
+        // table comes up in more than one content type, we only need
860
+        // to search it once.
861
+        $search_tables = array();
862
+        foreach ($types as $type_name => $type) {
863 863
         foreach ($type['fields'] as $field) {
864
-          // Only add tables when reverse link has been selected.
865
-          if ($field['type'] == 'userreference' && !empty($field['widget']['reverse_link'])) {
864
+            // Only add tables when reverse link has been selected.
865
+            if ($field['type'] == 'userreference' && !empty($field['widget']['reverse_link'])) {
866 866
             $db_info = content_database_info($field);
867 867
             $search_tables[$db_info['table']][] = $db_info['columns']['uid']['column'];
868
-          }
868
+            }
869
+        }
869 870
         }
870
-      }
871
-      foreach ($search_tables as $table => $columns) {
871
+        foreach ($search_tables as $table => $columns) {
872 872
         foreach ($columns as $column) {
873
-          $ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid), n.title, n.type FROM {node} n LEFT JOIN {". $table ."} f ON n.vid = f.vid WHERE f.". $column ."=". $account->uid. " AND n.status = 1"));
874
-          while ($data = db_fetch_object($ids)) {
873
+            $ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid), n.title, n.type FROM {node} n LEFT JOIN {". $table ."} f ON n.vid = f.vid WHERE f.". $column ."=". $account->uid. " AND n.status = 1"));
874
+            while ($data = db_fetch_object($ids)) {
875 875
             $additions[$data->type][$data->nid] = $data->title;
876
-          }
876
+            }
877 877
         }
878
-      }
879
-      $account->userreference = $additions;
880
-      break;
878
+        }
879
+        $account->userreference = $additions;
880
+        break;
881 881
 
882 882
     case 'view':
883 883
       if (!empty($account->userreference)) {
@@ -885,28 +885,28 @@  discard block
 block discarded – undo
885 885
         $additions = array();
886 886
         $values = array();
887 887
         foreach ($account->userreference as $node_type => $nodes) {
888
-          foreach ($nodes as $nid => $title) {
888
+            foreach ($nodes as $nid => $title) {
889 889
             $values[$node_type][] = l($title, 'node/'. $nid);
890
-          }
891
-          if (isset($values[$node_type])) {
890
+            }
891
+            if (isset($values[$node_type])) {
892 892
             $additions[] = array(
893
-              '#type' => 'user_profile_item',
894
-              '#title' => check_plain($node_types[$node_type]['name']),
895
-              '#value' => theme('item_list', $values[$node_type]),
893
+                '#type' => 'user_profile_item',
894
+                '#title' => check_plain($node_types[$node_type]['name']),
895
+                '#value' => theme('item_list', $values[$node_type]),
896 896
             );
897
-          }
897
+            }
898 898
         }
899 899
         if ($additions) {
900
-          $account->content['userreference'] = $additions + array(
900
+            $account->content['userreference'] = $additions + array(
901 901
             '#type' => 'user_profile_category',
902 902
             '#attributes' => array('class' => 'user-member'),
903 903
             '#title' => t('Related content'),
904 904
             '#weight' => 10,
905
-          );
905
+            );
906 906
         }
907
-      }
908
-      break;
909
-  }
907
+        }
908
+        break;
909
+    }
910 910
 }
911 911
 
912 912
 /**
@@ -921,13 +921,13 @@  discard block
 block discarded – undo
921 921
  * $element['#delta]  is the position of this element in the group
922 922
  */
923 923
 function theme_userreference_select($element) {
924
-  return $element['#children'];
924
+    return $element['#children'];
925 925
 }
926 926
 
927 927
 function theme_userreference_buttons($element) {
928
-  return $element['#children'];
928
+    return $element['#children'];
929 929
 }
930 930
 
931 931
 function theme_userreference_autocomplete($element) {
932
-  return $element['#children'];
932
+    return $element['#children'];
933 933
 }
934 934
\ No newline at end of file
Please login to merge, or discard this patch.