@@ -10,8 +10,8 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -32,174 +32,174 @@ discard block |
||
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 |
||
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 |
||
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 <Create> 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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -5,12 +5,12 @@ discard block |
||
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 |
||
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 | } |
@@ -10,101 +10,101 @@ discard block |
||
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 <?php ?> 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 <?php ?> 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('<none>'), |
|
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('<none>'), |
|
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -10,7 +10,7 @@ discard block |
||
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 |
||
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 | } |
@@ -10,39 +10,39 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -10,258 +10,258 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -6,43 +6,43 @@ discard block |
||
6 | 6 | * Theme preprocess function for content-admin-field-overview-form.tpl.php. |
7 | 7 | */ |
8 | 8 | function template_preprocess_content_field_overview_form(&$vars) { |
9 | - $form = &$vars['form']; |
|
9 | + $form = &$vars['form']; |
|
10 | 10 | |
11 | - $vars['help'] = theme('advanced_help_topic', 'content', 'manage-fields') . t('Add fields and groups to the content type, and arrange them on content display and input forms.'); |
|
12 | - if (module_exists('fieldgroup')) { |
|
11 | + $vars['help'] = theme('advanced_help_topic', 'content', 'manage-fields') . t('Add fields and groups to the content type, and arrange them on content display and input forms.'); |
|
12 | + if (module_exists('fieldgroup')) { |
|
13 | 13 | $vars['help'] .= '<br/>'. t('You can add a field to a group by dragging it below and to the right of the group.'); |
14 | - } |
|
15 | - if (!module_exists('advanced_help')) { |
|
14 | + } |
|
15 | + if (!module_exists('advanced_help')) { |
|
16 | 16 | $vars['help'] .= '<br/>' . t('Note: Installing the <a href="!adv_help">Advanced help</a> module will let you access more and better help.', array('!adv_help' => 'http://drupal.org/project/advanced_help')); |
17 | - } |
|
17 | + } |
|
18 | 18 | |
19 | - $order = _content_overview_order($form, $form['#field_rows'], $form['#group_rows']); |
|
20 | - $rows = array(); |
|
19 | + $order = _content_overview_order($form, $form['#field_rows'], $form['#group_rows']); |
|
20 | + $rows = array(); |
|
21 | 21 | |
22 | - // Identify the 'new item' keys in the form, they look like |
|
23 | - // _add_new_field, add_new_group. |
|
24 | - $keys = array_keys($form); |
|
25 | - $add_rows = array(); |
|
26 | - foreach ($keys as $key) { |
|
22 | + // Identify the 'new item' keys in the form, they look like |
|
23 | + // _add_new_field, add_new_group. |
|
24 | + $keys = array_keys($form); |
|
25 | + $add_rows = array(); |
|
26 | + foreach ($keys as $key) { |
|
27 | 27 | if (substr($key, 0, 4) == '_add') { |
28 | - $add_rows[] = $key; |
|
28 | + $add_rows[] = $key; |
|
29 | + } |
|
29 | 30 | } |
30 | - } |
|
31 | - while ($order) { |
|
31 | + while ($order) { |
|
32 | 32 | $key = reset($order); |
33 | 33 | $element = &$form[$key]; |
34 | 34 | |
35 | 35 | // Only display the 'Add' separator if the 'add' rows are still |
36 | 36 | // at the end of the table. |
37 | 37 | if (!isset($added_separator)) { |
38 | - $remaining_rows = array_diff($order, $add_rows); |
|
39 | - if (empty($remaining_rows) && empty($element['#depth'])) { |
|
38 | + $remaining_rows = array_diff($order, $add_rows); |
|
39 | + if (empty($remaining_rows) && empty($element['#depth'])) { |
|
40 | 40 | $row = new stdClass(); |
41 | 41 | $row->row_type = 'separator'; |
42 | 42 | $row->class = 'tabledrag-leaf region'; |
43 | 43 | $rows[] = $row; |
44 | 44 | $added_separator = TRUE; |
45 | - } |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | $row = new stdClass(); |
@@ -53,18 +53,18 @@ discard block |
||
53 | 53 | $element['hidden_name']['#attributes']['class'] = 'field-name'; |
54 | 54 | // Add target classes for the update selects behavior. |
55 | 55 | switch ($element['#row_type']) { |
56 | - case 'add_new_field': |
|
56 | + case 'add_new_field': |
|
57 | 57 | $element['type']['#attributes']['class'] = 'content-field-type-select'; |
58 | 58 | $element['widget_type']['#attributes']['class'] = 'content-widget-type-select'; |
59 | 59 | break; |
60 | - case 'add_existing_field': |
|
60 | + case 'add_existing_field': |
|
61 | 61 | $element['field_name']['#attributes']['class'] = 'content-field-select'; |
62 | 62 | $element['widget_type']['#attributes']['class'] = 'content-widget-type-select'; |
63 | 63 | $element['label']['#attributes']['class'] = 'content-label-textfield'; |
64 | 64 | break; |
65 | 65 | } |
66 | 66 | foreach (element_children($element) as $child) { |
67 | - $row->{$child} = drupal_render($element[$child]); |
|
67 | + $row->{$child} = drupal_render($element[$child]); |
|
68 | 68 | } |
69 | 69 | $row->label_class = 'label-'. strtr($element['#row_type'], '_', '-'); |
70 | 70 | $row->row_type = $element['#row_type']; |
@@ -77,69 +77,69 @@ discard block |
||
77 | 77 | |
78 | 78 | $rows[] = $row; |
79 | 79 | array_shift($order); |
80 | - } |
|
81 | - $vars['rows'] = $rows; |
|
82 | - $vars['submit'] = drupal_render($form); |
|
80 | + } |
|
81 | + $vars['rows'] = $rows; |
|
82 | + $vars['submit'] = drupal_render($form); |
|
83 | 83 | |
84 | - // Add tabledrag behavior. |
|
84 | + // Add tabledrag behavior. |
|
85 | 85 | // drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', FALSE, 1); |
86 | - drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', TRUE, 1); |
|
86 | + drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', TRUE, 1); |
|
87 | 87 | // drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight', NULL, NULL, FALSE); |
88 | - drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight'); |
|
88 | + drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight'); |
|
89 | 89 | |
90 | - // Add settings for the update selects behavior. |
|
91 | - $js_fields = array(); |
|
92 | - foreach (array_keys(content_existing_field_options($form['#type_name'])) as $field_name) { |
|
90 | + // Add settings for the update selects behavior. |
|
91 | + $js_fields = array(); |
|
92 | + foreach (array_keys(content_existing_field_options($form['#type_name'])) as $field_name) { |
|
93 | 93 | $field = content_fields($field_name); |
94 | 94 | $js_fields[$field_name] = array('label' => $field['widget']['label'], 'type' => $field['type'], 'widget' => $field['widget']['type']); |
95 | - } |
|
96 | - drupal_add_js(array('contentWidgetTypes' => content_widget_type_options(), 'contentFields' => $js_fields), 'setting'); |
|
97 | - drupal_add_js(drupal_get_path('module', 'content') .'/content.js'); |
|
95 | + } |
|
96 | + drupal_add_js(array('contentWidgetTypes' => content_widget_type_options(), 'contentFields' => $js_fields), 'setting'); |
|
97 | + drupal_add_js(drupal_get_path('module', 'content') .'/content.js'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Theme preprocess function for content-admin-display-overview-form.tpl.php. |
102 | 102 | */ |
103 | 103 | function template_preprocess_content_display_overview_form(&$vars) { |
104 | - $form = &$vars['form']; |
|
104 | + $form = &$vars['form']; |
|
105 | 105 | |
106 | - $contexts_selector = $form['#contexts']; |
|
107 | - $vars['basic'] = $contexts_selector == 'basic'; |
|
108 | - $vars['contexts'] = content_build_modes($contexts_selector); |
|
106 | + $contexts_selector = $form['#contexts']; |
|
107 | + $vars['basic'] = $contexts_selector == 'basic'; |
|
108 | + $vars['contexts'] = content_build_modes($contexts_selector); |
|
109 | 109 | |
110 | - if ($contexts_selector == 'basic') { |
|
110 | + if ($contexts_selector == 'basic') { |
|
111 | 111 | $help = t("Configure how this content type's fields and field labels should be displayed when it's viewed in teaser and full-page mode."); |
112 | - } |
|
113 | - else { |
|
112 | + } |
|
113 | + else { |
|
114 | 114 | $help = t("Configure how this content type's fields should be displayed when it's rendered in the following contexts."); |
115 | - } |
|
116 | - $help .= ' '. t("Use the 'Exclude' checkbox to exclude an item from the !content value passed to the node template.", array('!content' => '$content')); |
|
117 | - $vars['help'] = $help; |
|
115 | + } |
|
116 | + $help .= ' '. t("Use the 'Exclude' checkbox to exclude an item from the !content value passed to the node template.", array('!content' => '$content')); |
|
117 | + $vars['help'] = $help; |
|
118 | 118 | |
119 | - $order = _content_overview_order($form, $form['#fields'], $form['#groups']); |
|
120 | - if (empty($order)) { |
|
119 | + $order = _content_overview_order($form, $form['#fields'], $form['#groups']); |
|
120 | + if (empty($order)) { |
|
121 | 121 | $vars['rows'] = array(); |
122 | 122 | $vars['submit'] = ''; |
123 | 123 | return; |
124 | - } |
|
124 | + } |
|
125 | 125 | |
126 | - $rows = array(); |
|
127 | - foreach ($order as $key) { |
|
126 | + $rows = array(); |
|
127 | + foreach ($order as $key) { |
|
128 | 128 | $element = &$form[$key]; |
129 | 129 | $row = new stdClass(); |
130 | 130 | foreach (element_children($element) as $child) { |
131 | - if (!array_key_exists('exclude', $element[$child])) { |
|
131 | + if (!array_key_exists('exclude', $element[$child])) { |
|
132 | 132 | $row->{$child} = drupal_render($element[$child]); |
133 | - } |
|
134 | - else { |
|
133 | + } |
|
134 | + else { |
|
135 | 135 | $row->{$child}->format = drupal_render($element[$child]['format']); |
136 | 136 | $row->{$child}->exclude = drupal_render($element[$child]['exclude']); |
137 | - } |
|
137 | + } |
|
138 | 138 | } |
139 | 139 | $row->label_class = in_array($key, $form['#groups']) ? 'label-group' : 'label-field'; |
140 | 140 | $row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0); |
141 | 141 | $rows[] = $row; |
142 | - } |
|
143 | - $vars['rows'] = $rows; |
|
144 | - $vars['submit'] = drupal_render($form); |
|
142 | + } |
|
143 | + $vars['rows'] = $rows; |
|
144 | + $vars['submit'] = drupal_render($form); |
|
145 | 145 | } |
146 | 146 | \ No newline at end of file |
@@ -16,88 +16,88 @@ discard block |
||
16 | 16 | define('CONTENT_HANDLE_MODULE', 0x0002); |
17 | 17 | |
18 | 18 | function content_help($path, $arg) { |
19 | - switch ($path) { |
|
19 | + switch ($path) { |
|
20 | 20 | case 'admin/help#content': |
21 | 21 | $output = '<p>'. t('The content module, a required component of the Content Construction Kit (CCK), allows administrators to associate custom fields with content types. In Drupal, content types are used to define the characteristics of a post, including the title and description of the fields displayed on its add and edit pages. Using the content module (and the other helper modules included in CCK), custom fields beyond the default "Title" and "Body" may be added. CCK features are accessible through tabs on the <a href="@content-types">content types administration page</a>. (See the <a href="@node-help">node module help page</a> for more information about content types.)', array('@content-types' => url('admin/content/types'), '@node-help' => url('admin/help/node'))) .'</p>'; |
22 | - $output .= '<p>'. t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.') .'</p>'; |
|
23 | - $output .= '<p>'. t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array('@modules' => url('admin/build/modules'))) .'</p>'; |
|
24 | - $output .= '<ul>'; |
|
25 | - $output .= '<li>'. t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.') .'</li>'; |
|
26 | - $output .= '<li>'. t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.") .'</li>'; |
|
27 | - $output .= '<li>'. t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).') .'</li>'; |
|
28 | - $output .= '<li>'. t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.') .'</li>'; |
|
29 | - $output .= '<li>'. t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.') .'</li>'; |
|
30 | - $output .= '</ul>'; |
|
31 | - $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array('@handbook-cck' => 'http://drupal.org/handbook/modules/cck', '@project-cck' => 'http://drupal.org/project/cck')) .'</p>'; |
|
32 | - return $output; |
|
33 | - } |
|
22 | + $output .= '<p>'. t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.') .'</p>'; |
|
23 | + $output .= '<p>'. t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array('@modules' => url('admin/build/modules'))) .'</p>'; |
|
24 | + $output .= '<ul>'; |
|
25 | + $output .= '<li>'. t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.') .'</li>'; |
|
26 | + $output .= '<li>'. t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.") .'</li>'; |
|
27 | + $output .= '<li>'. t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).') .'</li>'; |
|
28 | + $output .= '<li>'. t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.') .'</li>'; |
|
29 | + $output .= '<li>'. t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.') .'</li>'; |
|
30 | + $output .= '</ul>'; |
|
31 | + $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array('@handbook-cck' => 'http://drupal.org/handbook/modules/cck', '@project-cck' => 'http://drupal.org/project/cck')) .'</p>'; |
|
32 | + return $output; |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Implementation of hook_flush_caches. |
38 | 38 | */ |
39 | 39 | function content_flush_caches() { |
40 | - return array(content_cache_tablename()); |
|
40 | + return array(content_cache_tablename()); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Implementation of hook_init(). |
45 | 45 | */ |
46 | 46 | function content_init() { |
47 | - drupal_add_css(drupal_get_path('module', 'content') .'/theme/content-module.css'); |
|
48 | - if (module_exists('token') && !function_exists('content_token_values')) { |
|
47 | + drupal_add_css(drupal_get_path('module', 'content') .'/theme/content-module.css'); |
|
48 | + if (module_exists('token') && !function_exists('content_token_values')) { |
|
49 | 49 | module_load_include('inc', 'content', 'includes/content.token'); |
50 | - } |
|
51 | - if (module_exists('diff') && !function_exists('content_diff')) { |
|
50 | + } |
|
51 | + if (module_exists('diff') && !function_exists('content_diff')) { |
|
52 | 52 | module_load_include('inc', 'content', 'includes/content.diff'); |
53 | - } |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Implementation of hook_perm(). |
58 | 58 | */ |
59 | 59 | function content_perm() { |
60 | - return array('Use PHP input for field settings (dangerous - grant with care)'); |
|
60 | + return array('Use PHP input for field settings (dangerous - grant with care)'); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Implementation of hook_menu_alter(). |
65 | 65 | */ |
66 | 66 | function content_menu_alter(&$items) { |
67 | - // Customize the content types page with our own callback |
|
68 | - $items['admin/content/types']['page callback'] = 'content_types_overview'; |
|
69 | - $items['admin/content/types']['file'] = 'content.admin.inc'; |
|
70 | - $items['admin/content/types']['file path'] = drupal_get_path('module', 'content') .'/includes'; |
|
67 | + // Customize the content types page with our own callback |
|
68 | + $items['admin/content/types']['page callback'] = 'content_types_overview'; |
|
69 | + $items['admin/content/types']['file'] = 'content.admin.inc'; |
|
70 | + $items['admin/content/types']['file path'] = drupal_get_path('module', 'content') .'/includes'; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Implementation of hook_menu(). |
75 | 75 | */ |
76 | 76 | function content_menu() { |
77 | - $items = array(); |
|
78 | - $items['admin/content/types/fields'] = array( |
|
77 | + $items = array(); |
|
78 | + $items['admin/content/types/fields'] = array( |
|
79 | 79 | 'title' => 'Fields', |
80 | 80 | 'page callback' => 'content_fields_list', |
81 | 81 | 'access arguments' => array('administer content types'), |
82 | 82 | 'file' => 'includes/content.admin.inc', |
83 | 83 | 'type' => MENU_LOCAL_TASK, |
84 | - ); |
|
85 | - // Callback for AHAH add more buttons. |
|
86 | - $items['content/js_add_more'] = array( |
|
84 | + ); |
|
85 | + // Callback for AHAH add more buttons. |
|
86 | + $items['content/js_add_more'] = array( |
|
87 | 87 | 'page callback' => 'content_add_more_js', |
88 | 88 | 'access arguments' => array('access content'), |
89 | 89 | 'file' => 'includes/content.node_form.inc', |
90 | 90 | 'type' => MENU_CALLBACK, |
91 | - ); |
|
91 | + ); |
|
92 | 92 | |
93 | - // Make sure this doesn't fire until content_types is working, |
|
94 | - // and tables are updated, needed to avoid errors on initial installation. |
|
95 | - if (!defined('MAINTENANCE_MODE') && variable_get('content_schema_version', -1) >= 6007) { |
|
93 | + // Make sure this doesn't fire until content_types is working, |
|
94 | + // and tables are updated, needed to avoid errors on initial installation. |
|
95 | + if (!defined('MAINTENANCE_MODE') && variable_get('content_schema_version', -1) >= 6007) { |
|
96 | 96 | foreach (node_get_types() as $type) { |
97 | - $type_name = $type->type; |
|
98 | - $content_type = content_types($type_name); |
|
99 | - $type_url_str = $content_type['url_str']; |
|
100 | - $items['admin/content/node-type/'. $type_url_str .'/fields'] = array( |
|
97 | + $type_name = $type->type; |
|
98 | + $content_type = content_types($type_name); |
|
99 | + $type_url_str = $content_type['url_str']; |
|
100 | + $items['admin/content/node-type/'. $type_url_str .'/fields'] = array( |
|
101 | 101 | 'title' => 'Manage fields', |
102 | 102 | 'page callback' => 'drupal_get_form', |
103 | 103 | 'page arguments' => array('content_field_overview_form', $type_name), |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | 'file' => 'includes/content.admin.inc', |
106 | 106 | 'type' => MENU_LOCAL_TASK, |
107 | 107 | 'weight' => 1, |
108 | - ); |
|
109 | - $items['admin/content/node-type/'. $type_url_str .'/display'] = array( |
|
108 | + ); |
|
109 | + $items['admin/content/node-type/'. $type_url_str .'/display'] = array( |
|
110 | 110 | 'title' => 'Display fields', |
111 | 111 | 'page callback' => 'drupal_get_form', |
112 | 112 | 'page arguments' => array('content_display_overview_form', $type_name), |
@@ -114,41 +114,41 @@ discard block |
||
114 | 114 | 'file' => 'includes/content.admin.inc', |
115 | 115 | 'type' => MENU_LOCAL_TASK, |
116 | 116 | 'weight' => 2, |
117 | - ); |
|
118 | - $contexts = content_build_modes('_tabs'); |
|
119 | - foreach ($contexts as $key => $tab) { |
|
117 | + ); |
|
118 | + $contexts = content_build_modes('_tabs'); |
|
119 | + foreach ($contexts as $key => $tab) { |
|
120 | 120 | $items['admin/content/node-type/'. $type_url_str .'/display/'. $key] = array( |
121 | - 'title' => $tab['title'], |
|
122 | - 'page arguments' => array('content_display_overview_form', $type_name, $key), |
|
123 | - 'access arguments' => array('administer content types'), |
|
124 | - 'type' => $key == 'basic' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, |
|
125 | - 'weight' => $key == 'basic' ? 0 : 1, |
|
121 | + 'title' => $tab['title'], |
|
122 | + 'page arguments' => array('content_display_overview_form', $type_name, $key), |
|
123 | + 'access arguments' => array('administer content types'), |
|
124 | + 'type' => $key == 'basic' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, |
|
125 | + 'weight' => $key == 'basic' ? 0 : 1, |
|
126 | 126 | ); |
127 | - } |
|
128 | - // Cast as an array in case this is called before any fields have |
|
129 | - // been added, like when a new content type is created. |
|
130 | - foreach ((array) $content_type['fields'] as $field) { |
|
127 | + } |
|
128 | + // Cast as an array in case this is called before any fields have |
|
129 | + // been added, like when a new content type is created. |
|
130 | + foreach ((array) $content_type['fields'] as $field) { |
|
131 | 131 | $field_name = $field['field_name']; |
132 | 132 | $items['admin/content/node-type/'. $type_url_str .'/fields/'. $field_name] = array( |
133 | - 'title' => $field['widget']['label'], |
|
134 | - 'page callback' => 'drupal_get_form', |
|
135 | - 'page arguments' => array('content_field_edit_form', $type_name, $field_name), |
|
136 | - 'access arguments' => array('administer content types'), |
|
137 | - 'file' => 'includes/content.admin.inc', |
|
138 | - 'type' => MENU_LOCAL_TASK, |
|
133 | + 'title' => $field['widget']['label'], |
|
134 | + 'page callback' => 'drupal_get_form', |
|
135 | + 'page arguments' => array('content_field_edit_form', $type_name, $field_name), |
|
136 | + 'access arguments' => array('administer content types'), |
|
137 | + 'file' => 'includes/content.admin.inc', |
|
138 | + 'type' => MENU_LOCAL_TASK, |
|
139 | 139 | ); |
140 | 140 | $items['admin/content/node-type/'. $type_url_str .'/fields/'. $field_name .'/remove'] = array( |
141 | - 'title' => 'Remove field', |
|
142 | - 'page callback' => 'drupal_get_form', |
|
143 | - 'page arguments' => array('content_field_remove_form', $type_name, $field_name), |
|
144 | - 'access arguments' => array('administer content types'), |
|
145 | - 'file' => 'includes/content.admin.inc', |
|
146 | - 'type' => MENU_CALLBACK, |
|
141 | + 'title' => 'Remove field', |
|
142 | + 'page callback' => 'drupal_get_form', |
|
143 | + 'page arguments' => array('content_field_remove_form', $type_name, $field_name), |
|
144 | + 'access arguments' => array('administer content types'), |
|
145 | + 'file' => 'includes/content.admin.inc', |
|
146 | + 'type' => MENU_CALLBACK, |
|
147 | 147 | ); |
148 | - } |
|
148 | + } |
|
149 | + } |
|
149 | 150 | } |
150 | - } |
|
151 | - return $items; |
|
151 | + return $items; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -163,69 +163,69 @@ discard block |
||
163 | 163 | * the same name as the hook_elements key. |
164 | 164 | */ |
165 | 165 | function content_elements() { |
166 | - return array( |
|
166 | + return array( |
|
167 | 167 | 'content_multiple_values' => array(), |
168 | 168 | 'content_field' => array(), |
169 | - ); |
|
169 | + ); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Implementation of hook_theme(). |
174 | 174 | */ |
175 | 175 | function content_theme() { |
176 | - $path = drupal_get_path('module', 'content') .'/theme'; |
|
177 | - require_once "./$path/theme.inc"; |
|
176 | + $path = drupal_get_path('module', 'content') .'/theme'; |
|
177 | + require_once "./$path/theme.inc"; |
|
178 | 178 | |
179 | - return array( |
|
179 | + return array( |
|
180 | 180 | 'content_field' => array( |
181 | - 'template' => 'content-field', |
|
182 | - 'arguments' => array('element' => NULL), |
|
183 | - 'path' => $path, |
|
181 | + 'template' => 'content-field', |
|
182 | + 'arguments' => array('element' => NULL), |
|
183 | + 'path' => $path, |
|
184 | 184 | ), |
185 | 185 | 'content_overview_links' => array( |
186 | - 'arguments' => array(), |
|
186 | + 'arguments' => array(), |
|
187 | 187 | ), |
188 | 188 | 'content_field_overview_form' => array( |
189 | - 'template' => 'content-admin-field-overview-form', |
|
190 | - 'file' => 'theme.inc', |
|
191 | - 'path' => $path, |
|
192 | - 'arguments' => array('form' => NULL), |
|
189 | + 'template' => 'content-admin-field-overview-form', |
|
190 | + 'file' => 'theme.inc', |
|
191 | + 'path' => $path, |
|
192 | + 'arguments' => array('form' => NULL), |
|
193 | 193 | ), |
194 | 194 | 'content_display_overview_form' => array( |
195 | - 'template' => 'content-admin-display-overview-form', |
|
196 | - 'file' => 'theme.inc', |
|
197 | - 'path' => $path, |
|
198 | - 'arguments' => array('form' => NULL), |
|
195 | + 'template' => 'content-admin-display-overview-form', |
|
196 | + 'file' => 'theme.inc', |
|
197 | + 'path' => $path, |
|
198 | + 'arguments' => array('form' => NULL), |
|
199 | 199 | ), |
200 | 200 | 'content_exclude' => array( |
201 | - 'arguments' => array('content' => NULL, 'object' => array(), 'context' => NULL), |
|
201 | + 'arguments' => array('content' => NULL, 'object' => array(), 'context' => NULL), |
|
202 | 202 | ), |
203 | 203 | 'content_view_multiple_field' => array( |
204 | - 'arguments' => array('items' => NULL, 'field' => NULL, 'data' => NULL), |
|
204 | + 'arguments' => array('items' => NULL, 'field' => NULL, 'data' => NULL), |
|
205 | 205 | ), |
206 | 206 | 'content_multiple_values' => array( |
207 | - 'arguments' => array('element' => NULL), |
|
207 | + 'arguments' => array('element' => NULL), |
|
208 | 208 | ), |
209 | - ); |
|
209 | + ); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
213 | 213 | * Implementation of hook_views_api(). |
214 | 214 | */ |
215 | 215 | function content_views_api() { |
216 | - return array( |
|
216 | + return array( |
|
217 | 217 | 'api' => 2, |
218 | 218 | 'path' => drupal_get_path('module', 'content') . '/includes/views', |
219 | - ); |
|
219 | + ); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * Implementation of hook_ctools_plugin_directory(). |
224 | 224 | */ |
225 | 225 | function content_ctools_plugin_directory($module, $plugin) { |
226 | - if ($module == 'ctools' && $plugin == 'content_types') { |
|
226 | + if ($module == 'ctools' && $plugin == 'content_types') { |
|
227 | 227 | return 'includes/panels/' . $plugin; |
228 | - } |
|
228 | + } |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -237,28 +237,28 @@ discard block |
||
237 | 237 | * cache the loaded object structure and invalidate it during the update process. |
238 | 238 | */ |
239 | 239 | function content_load(&$node) { |
240 | - $cid = 'content:'. $node->nid .':'. $node->vid; |
|
241 | - if ($cached = cache_get($cid, content_cache_tablename())) { |
|
240 | + $cid = 'content:'. $node->nid .':'. $node->vid; |
|
241 | + if ($cached = cache_get($cid, content_cache_tablename())) { |
|
242 | 242 | foreach ($cached->data as $key => $value) { |
243 | - $node->$key = $value; |
|
243 | + $node->$key = $value; |
|
244 | 244 | } |
245 | - } |
|
246 | - else { |
|
245 | + } |
|
246 | + else { |
|
247 | 247 | $default_additions = _content_field_invoke_default('load', $node); |
248 | 248 | if ($default_additions) { |
249 | - foreach ($default_additions as $key => $value) { |
|
249 | + foreach ($default_additions as $key => $value) { |
|
250 | 250 | $node->$key = $value; |
251 | - } |
|
251 | + } |
|
252 | 252 | } |
253 | 253 | $additions = _content_field_invoke('load', $node); |
254 | 254 | if ($additions) { |
255 | - foreach ($additions as $key => $value) { |
|
255 | + foreach ($additions as $key => $value) { |
|
256 | 256 | $node->$key = $value; |
257 | 257 | $default_additions[$key] = $value; |
258 | - } |
|
258 | + } |
|
259 | 259 | } |
260 | 260 | cache_set($cid, $default_additions, content_cache_tablename()); |
261 | - } |
|
261 | + } |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | * |
267 | 267 | */ |
268 | 268 | function content_validate(&$node, $form = NULL) { |
269 | - _content_field_invoke('validate', $node, $form); |
|
270 | - _content_field_invoke_default('validate', $node, $form); |
|
269 | + _content_field_invoke('validate', $node, $form); |
|
270 | + _content_field_invoke_default('validate', $node, $form); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | * |
276 | 276 | */ |
277 | 277 | function content_presave(&$node) { |
278 | - _content_field_invoke('presave', $node); |
|
279 | - _content_field_invoke_default('presave', $node); |
|
278 | + _content_field_invoke('presave', $node); |
|
279 | + _content_field_invoke_default('presave', $node); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | * Insert node type fields. |
286 | 286 | */ |
287 | 287 | function content_insert(&$node) { |
288 | - _content_field_invoke('insert', $node); |
|
289 | - _content_field_invoke_default('insert', $node); |
|
288 | + _content_field_invoke('insert', $node); |
|
289 | + _content_field_invoke_default('insert', $node); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | * Update node type fields. |
296 | 296 | */ |
297 | 297 | function content_update(&$node) { |
298 | - _content_field_invoke('update', $node); |
|
299 | - _content_field_invoke_default('update', $node); |
|
300 | - cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename()); |
|
298 | + _content_field_invoke('update', $node); |
|
299 | + _content_field_invoke_default('update', $node); |
|
300 | + cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename()); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -306,9 +306,9 @@ discard block |
||
306 | 306 | * Delete node type fields. |
307 | 307 | */ |
308 | 308 | function content_delete(&$node) { |
309 | - _content_field_invoke('delete', $node); |
|
310 | - _content_field_invoke_default('delete', $node); |
|
311 | - cache_clear_all('content:'. $node->nid .':', content_cache_tablename(), TRUE); |
|
309 | + _content_field_invoke('delete', $node); |
|
310 | + _content_field_invoke_default('delete', $node); |
|
311 | + cache_clear_all('content:'. $node->nid .':', content_cache_tablename(), TRUE); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -317,9 +317,9 @@ discard block |
||
317 | 317 | * Delete node type fields for a revision. |
318 | 318 | */ |
319 | 319 | function content_delete_revision(&$node) { |
320 | - _content_field_invoke('delete revision', $node); |
|
321 | - _content_field_invoke_default('delete revision', $node); |
|
322 | - cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename()); |
|
320 | + _content_field_invoke('delete revision', $node); |
|
321 | + _content_field_invoke_default('delete revision', $node); |
|
322 | + cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename()); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -328,12 +328,12 @@ discard block |
||
328 | 328 | * Generate field render arrays. |
329 | 329 | */ |
330 | 330 | function content_view(&$node, $teaser = FALSE, $page = FALSE) { |
331 | - // Let field modules sanitize their data for output. |
|
332 | - _content_field_invoke('sanitize', $node, $teaser, $page); |
|
331 | + // Let field modules sanitize their data for output. |
|
332 | + _content_field_invoke('sanitize', $node, $teaser, $page); |
|
333 | 333 | |
334 | - // Merge fields. |
|
335 | - $additions = _content_field_invoke_default('view', $node, $teaser, $page); |
|
336 | - $node->content = array_merge((array) $node->content, $additions); |
|
334 | + // Merge fields. |
|
335 | + $additions = _content_field_invoke_default('view', $node, $teaser, $page); |
|
336 | + $node->content = array_merge((array) $node->content, $additions); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | * The themed output for the field. |
362 | 362 | */ |
363 | 363 | function content_view_field($field, $node, $teaser = FALSE, $page = FALSE) { |
364 | - $output = ''; |
|
365 | - if (isset($node->$field['field_name'])) { |
|
364 | + $output = ''; |
|
365 | + if (isset($node->$field['field_name'])) { |
|
366 | 366 | $items = $node->$field['field_name']; |
367 | 367 | |
368 | 368 | // Use 'full'/'teaser' if not specified otherwise. |
@@ -373,16 +373,16 @@ discard block |
||
373 | 373 | $module = $field_types[$field['type']]['module']; |
374 | 374 | $function = $module .'_field'; |
375 | 375 | if (function_exists($function)) { |
376 | - $function('sanitize', $node, $field, $items, $teaser, $page); |
|
377 | - $node->$field['field_name'] = $items; |
|
376 | + $function('sanitize', $node, $field, $items, $teaser, $page); |
|
377 | + $node->$field['field_name'] = $items; |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | $view = content_field('view', $node, $field, $items, $teaser, $page); |
381 | 381 | // content_field('view') adds a wrapper to handle variables and 'excluded' |
382 | 382 | // fields for node templates. We bypass it and render the actual field. |
383 | 383 | $output = drupal_render($view[$field['field_name']]['field']); |
384 | - } |
|
385 | - return $output; |
|
384 | + } |
|
385 | + return $output; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * so that node templates can use it. |
393 | 393 | */ |
394 | 394 | function content_alter(&$node, $teaser = FALSE, $page = FALSE) { |
395 | - _content_field_invoke_default('alter', $node, $teaser, $page); |
|
395 | + _content_field_invoke_default('alter', $node, $teaser, $page); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -401,70 +401,70 @@ discard block |
||
401 | 401 | * Generate field render arrays. |
402 | 402 | */ |
403 | 403 | function content_prepare_translation(&$node) { |
404 | - $default_additions = _content_field_invoke_default('prepare translation', $node); |
|
405 | - $additions = _content_field_invoke('prepare translation', $node); |
|
406 | - // Merge module additions after the default ones to enable overriding |
|
407 | - // of field values. |
|
408 | - $node = (object) array_merge((array) $node, $default_additions, $additions); |
|
404 | + $default_additions = _content_field_invoke_default('prepare translation', $node); |
|
405 | + $additions = _content_field_invoke('prepare translation', $node); |
|
406 | + // Merge module additions after the default ones to enable overriding |
|
407 | + // of field values. |
|
408 | + $node = (object) array_merge((array) $node, $default_additions, $additions); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
412 | 412 | * Implementation of hook_nodeapi(). |
413 | 413 | */ |
414 | 414 | function content_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
415 | - // Prevent against invalid 'nodes' built by broken 3rd party code. |
|
416 | - if (isset($node->type)) { |
|
415 | + // Prevent against invalid 'nodes' built by broken 3rd party code. |
|
416 | + if (isset($node->type)) { |
|
417 | 417 | $type = content_types($node->type); |
418 | 418 | // Save cycles if the type has no CCK fields. |
419 | 419 | if (!empty($type['fields'])) { |
420 | - $callback = 'content_'. str_replace(' ', '_', $op); |
|
421 | - if (function_exists($callback)) { |
|
420 | + $callback = 'content_'. str_replace(' ', '_', $op); |
|
421 | + if (function_exists($callback)) { |
|
422 | 422 | $callback($node, $a3, $a4); |
423 | - } |
|
423 | + } |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | // Special case for 'view' op, we want to adjust weights of non-cck fields |
427 | 427 | // even if there are no actual fields for this type. |
428 | 428 | if ($op == 'view') { |
429 | - $node->content['#pre_render'][] = 'content_alter_extra_weights'; |
|
430 | - $node->content['#content_extra_fields'] = $type['extra']; |
|
429 | + $node->content['#pre_render'][] = 'content_alter_extra_weights'; |
|
430 | + $node->content['#content_extra_fields'] = $type['extra']; |
|
431 | + } |
|
431 | 432 | } |
432 | - } |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
436 | 436 | * Implementation of hook_form_alter(). |
437 | 437 | */ |
438 | 438 | function content_form_alter(&$form, $form_state, $form_id) { |
439 | - if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
439 | + if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
440 | 440 | $type = content_types($form['#node']->type); |
441 | 441 | if (!empty($type['fields'])) { |
442 | - module_load_include('inc', 'content', 'includes/content.node_form'); |
|
443 | - // Merge field widgets. |
|
444 | - $form = array_merge($form, content_form($form, $form_state)); |
|
442 | + module_load_include('inc', 'content', 'includes/content.node_form'); |
|
443 | + // Merge field widgets. |
|
444 | + $form = array_merge($form, content_form($form, $form_state)); |
|
445 | 445 | } |
446 | 446 | $form['#pre_render'][] = 'content_alter_extra_weights'; |
447 | 447 | $form['#content_extra_fields'] = $type['extra']; |
448 | - } |
|
448 | + } |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
452 | 452 | * Pre-render callback to adjust weights of non-CCK fields. |
453 | 453 | */ |
454 | 454 | function content_alter_extra_weights($elements) { |
455 | - if (isset($elements['#content_extra_fields'])) { |
|
455 | + if (isset($elements['#content_extra_fields'])) { |
|
456 | 456 | foreach ($elements['#content_extra_fields'] as $key => $value) { |
457 | - // Some core 'fields' use a different key in node forms and in 'view' |
|
458 | - // render arrays. Check we're not on a form first. |
|
459 | - if (!isset($elements['#build_id']) && isset($value['view']) && isset($elements[$value['view']])) { |
|
457 | + // Some core 'fields' use a different key in node forms and in 'view' |
|
458 | + // render arrays. Check we're not on a form first. |
|
459 | + if (!isset($elements['#build_id']) && isset($value['view']) && isset($elements[$value['view']])) { |
|
460 | 460 | $elements[$value['view']]['#weight'] = $value['weight']; |
461 | - } |
|
462 | - elseif (isset($elements[$key])) { |
|
461 | + } |
|
462 | + elseif (isset($elements[$key])) { |
|
463 | 463 | $elements[$key]['#weight'] = $value['weight']; |
464 | - } |
|
464 | + } |
|
465 | + } |
|
465 | 466 | } |
466 | - } |
|
467 | - return $elements; |
|
467 | + return $elements; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | * included yet when the form is processed and invokes the callback. |
473 | 473 | */ |
474 | 474 | function content_add_more_submit_proxy($form, &$form_state) { |
475 | - module_load_include('inc', 'content', 'includes/content.node_form'); |
|
476 | - content_add_more_submit($form, $form_state); |
|
475 | + module_load_include('inc', 'content', 'includes/content.node_form'); |
|
476 | + content_add_more_submit($form, $form_state); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -482,21 +482,21 @@ discard block |
||
482 | 482 | * Combine multiple values into a table with drag-n-drop reordering. |
483 | 483 | */ |
484 | 484 | function theme_content_multiple_values($element) { |
485 | - $field_name = $element['#field_name']; |
|
486 | - $field = content_fields($field_name); |
|
487 | - $output = ''; |
|
485 | + $field_name = $element['#field_name']; |
|
486 | + $field = content_fields($field_name); |
|
487 | + $output = ''; |
|
488 | 488 | |
489 | - if ($field['multiple'] >= 1) { |
|
489 | + if ($field['multiple'] >= 1) { |
|
490 | 490 | $table_id = $element['#field_name'] .'_values'; |
491 | 491 | $order_class = $element['#field_name'] .'-delta-order'; |
492 | 492 | $required = !empty($element['#required']) ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : ''; |
493 | 493 | |
494 | 494 | $header = array( |
495 | - array( |
|
495 | + array( |
|
496 | 496 | 'data' => t('!title: !required', array('!title' => $element['#title'], '!required' => $required)), |
497 | 497 | 'colspan' => 2 |
498 | - ), |
|
499 | - t('Order'), |
|
498 | + ), |
|
499 | + t('Order'), |
|
500 | 500 | ); |
501 | 501 | $rows = array(); |
502 | 502 | |
@@ -504,25 +504,25 @@ discard block |
||
504 | 504 | // preview or failed validation) |
505 | 505 | $items = array(); |
506 | 506 | foreach (element_children($element) as $key) { |
507 | - if ($key !== $element['#field_name'] .'_add_more') { |
|
507 | + if ($key !== $element['#field_name'] .'_add_more') { |
|
508 | 508 | $items[] = &$element[$key]; |
509 | - } |
|
509 | + } |
|
510 | 510 | } |
511 | 511 | usort($items, '_content_sort_items_value_helper'); |
512 | 512 | |
513 | 513 | // Add the items as table rows. |
514 | 514 | foreach ($items as $key => $item) { |
515 | - $item['_weight']['#attributes']['class'] = $order_class; |
|
516 | - $delta_element = drupal_render($item['_weight']); |
|
517 | - $cells = array( |
|
515 | + $item['_weight']['#attributes']['class'] = $order_class; |
|
516 | + $delta_element = drupal_render($item['_weight']); |
|
517 | + $cells = array( |
|
518 | 518 | array('data' => '', 'class' => 'content-multiple-drag'), |
519 | 519 | drupal_render($item), |
520 | 520 | array('data' => $delta_element, 'class' => 'delta-order'), |
521 | - ); |
|
522 | - $rows[] = array( |
|
521 | + ); |
|
522 | + $rows[] = array( |
|
523 | 523 | 'data' => $cells, |
524 | 524 | 'class' => 'draggable', |
525 | - ); |
|
525 | + ); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | $output .= theme('table', $header, $rows, array('id' => $table_id, 'class' => 'content-multiple-table')); |
@@ -530,14 +530,14 @@ discard block |
||
530 | 530 | $output .= drupal_render($element[$element['#field_name'] .'_add_more']); |
531 | 531 | |
532 | 532 | drupal_add_tabledrag($table_id, 'order', 'sibling', $order_class); |
533 | - } |
|
534 | - else { |
|
533 | + } |
|
534 | + else { |
|
535 | 535 | foreach (element_children($element) as $key) { |
536 | - $output .= drupal_render($element[$key]); |
|
536 | + $output .= drupal_render($element[$key]); |
|
537 | + } |
|
537 | 538 | } |
538 | - } |
|
539 | 539 | |
540 | - return $output; |
|
540 | + return $output; |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | /** |
@@ -552,29 +552,29 @@ discard block |
||
552 | 552 | * field modules are installed, uninstalled, enabled or disabled. |
553 | 553 | */ |
554 | 554 | function content_notify($op, $module) { |
555 | - switch ($op) { |
|
555 | + switch ($op) { |
|
556 | 556 | case 'install': |
557 | 557 | content_clear_type_cache(); |
558 | - break; |
|
558 | + break; |
|
559 | 559 | case 'uninstall': |
560 | 560 | module_load_include('inc', 'content', 'includes/content.crud'); |
561 | - content_module_delete($module); |
|
562 | - break; |
|
561 | + content_module_delete($module); |
|
562 | + break; |
|
563 | 563 | case 'enable': |
564 | 564 | content_associate_fields($module); |
565 | - content_clear_type_cache(); |
|
566 | - break; |
|
565 | + content_clear_type_cache(); |
|
566 | + break; |
|
567 | 567 | case 'disable': |
568 | 568 | // When CCK modules are disabled before content module's update is run |
569 | 569 | // to add the active column, we can't do this. |
570 | 570 | if (variable_get('content_schema_version', -1) < 6007) { |
571 | 571 | return FALSE; |
572 | - } |
|
573 | - db_query("UPDATE {". content_field_tablename() ."} SET active=0 WHERE module='%s'", $module); |
|
574 | - db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_module='%s'", $module); |
|
575 | - content_clear_type_cache(TRUE); |
|
576 | - break; |
|
577 | - } |
|
572 | + } |
|
573 | + db_query("UPDATE {". content_field_tablename() ."} SET active=0 WHERE module='%s'", $module); |
|
574 | + db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_module='%s'", $module); |
|
575 | + content_clear_type_cache(TRUE); |
|
576 | + break; |
|
577 | + } |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | /** |
@@ -584,39 +584,39 @@ discard block |
||
584 | 584 | * The name of the module to update on. |
585 | 585 | */ |
586 | 586 | function content_associate_fields($module) { |
587 | - // When CCK modules are enabled before content module's update is run, |
|
588 | - // to add module and active columns, we can't do this. |
|
589 | - if (variable_get('content_schema_version', -1) < 6007) { |
|
587 | + // When CCK modules are enabled before content module's update is run, |
|
588 | + // to add module and active columns, we can't do this. |
|
589 | + if (variable_get('content_schema_version', -1) < 6007) { |
|
590 | 590 | return FALSE; |
591 | - } |
|
592 | - $module_fields = module_invoke($module, 'field_info'); |
|
593 | - if ($module_fields) { |
|
591 | + } |
|
592 | + $module_fields = module_invoke($module, 'field_info'); |
|
593 | + if ($module_fields) { |
|
594 | 594 | foreach ($module_fields as $name => $field_info) { |
595 | - watchdog('content', 'Updating field type %type with module %module.', array('%type' => $name, '%module' => $module)); |
|
596 | - db_query("UPDATE {". content_field_tablename() ."} SET module = '%s', active = %d WHERE type = '%s'", $module, 1, $name); |
|
595 | + watchdog('content', 'Updating field type %type with module %module.', array('%type' => $name, '%module' => $module)); |
|
596 | + db_query("UPDATE {". content_field_tablename() ."} SET module = '%s', active = %d WHERE type = '%s'", $module, 1, $name); |
|
597 | 597 | } |
598 | - } |
|
599 | - $module_widgets = module_invoke($module, 'widget_info'); |
|
600 | - if ($module_widgets) { |
|
598 | + } |
|
599 | + $module_widgets = module_invoke($module, 'widget_info'); |
|
600 | + if ($module_widgets) { |
|
601 | 601 | foreach ($module_widgets as $name => $widget_info) { |
602 | - watchdog('content', 'Updating widget type %type with module %module.', array('%type' => $name, '%module' => $module)); |
|
603 | - db_query("UPDATE {". content_instance_tablename() ."} SET widget_module = '%s', widget_active = %d WHERE widget_type = '%s'", $module, 1, $name); |
|
604 | - } |
|
605 | - } |
|
606 | - // This is called from updates and installs, so get the install-safe |
|
607 | - // version of a fields array. |
|
608 | - $fields_set = array(); |
|
609 | - module_load_include('install', 'content'); |
|
610 | - $types = content_types_install(); |
|
611 | - foreach ($types as $type_name => $fields) { |
|
602 | + watchdog('content', 'Updating widget type %type with module %module.', array('%type' => $name, '%module' => $module)); |
|
603 | + db_query("UPDATE {". content_instance_tablename() ."} SET widget_module = '%s', widget_active = %d WHERE widget_type = '%s'", $module, 1, $name); |
|
604 | + } |
|
605 | + } |
|
606 | + // This is called from updates and installs, so get the install-safe |
|
607 | + // version of a fields array. |
|
608 | + $fields_set = array(); |
|
609 | + module_load_include('install', 'content'); |
|
610 | + $types = content_types_install(); |
|
611 | + foreach ($types as $type_name => $fields) { |
|
612 | 612 | foreach ($fields as $field) { |
613 | - if ($field['module'] == $module && !in_array($field['field_name'], $fields_set)) { |
|
613 | + if ($field['module'] == $module && !in_array($field['field_name'], $fields_set)) { |
|
614 | 614 | $columns = (array) module_invoke($field['module'], 'field_settings', 'database columns', $field); |
615 | 615 | db_query("UPDATE {". content_field_tablename() ."} SET db_columns = '%s' WHERE field_name = '%s'", serialize($columns), $field['field_name']); |
616 | 616 | $fields_set[] = $field['field_name']; |
617 | - } |
|
617 | + } |
|
618 | + } |
|
618 | 619 | } |
619 | - } |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | * ); |
685 | 685 | */ |
686 | 686 | function content_field($op, &$node, $field, &$items, $teaser, $page) { |
687 | - switch ($op) { |
|
687 | + switch ($op) { |
|
688 | 688 | case 'validate': |
689 | 689 | // TODO: here we could validate that the number of multiple data is correct ? |
690 | 690 | // We're controlling the number of fields to fill out and saving empty |
@@ -699,107 +699,107 @@ discard block |
||
699 | 699 | include_once('./'. drupal_get_path('module', 'content') .'/includes/content.devel.inc'); |
700 | 700 | content_generate_fields($node, $field); |
701 | 701 | $items = $node->{$field['field_name']}; |
702 | - } |
|
703 | - |
|
704 | - // Manual node_save calls might not have all fields filled in. |
|
705 | - // On node insert, we need to make sure all tables get at least an empty |
|
706 | - // record, or subsequent edits, using drupal_write_record() in update mode, |
|
707 | - // won't insert any data. |
|
708 | - // Missing fields on node update are handled in content_storage(). |
|
709 | - if (empty($items) && !isset($node->nid)) { |
|
702 | + } |
|
703 | + |
|
704 | + // Manual node_save calls might not have all fields filled in. |
|
705 | + // On node insert, we need to make sure all tables get at least an empty |
|
706 | + // record, or subsequent edits, using drupal_write_record() in update mode, |
|
707 | + // won't insert any data. |
|
708 | + // Missing fields on node update are handled in content_storage(). |
|
709 | + if (empty($items) && !isset($node->nid)) { |
|
710 | 710 | foreach (array_keys($field['columns']) as $column) { |
711 | - $items[0][$column] = NULL; |
|
711 | + $items[0][$column] = NULL; |
|
712 | 712 | } |
713 | 713 | $node->$field['field_name'] = $items; |
714 | - } |
|
714 | + } |
|
715 | 715 | |
716 | - // If there was an AHAH add more button in this field, don't save it. |
|
717 | - // TODO: is it still needed ? |
|
718 | - unset($items[$field['field_name'] .'_add_more']); |
|
716 | + // If there was an AHAH add more button in this field, don't save it. |
|
717 | + // TODO: is it still needed ? |
|
718 | + unset($items[$field['field_name'] .'_add_more']); |
|
719 | 719 | |
720 | - if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
720 | + if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
721 | 721 | // Reorder items to account for drag-n-drop reordering. |
722 | 722 | $items = _content_sort_items($field, $items); |
723 | - } |
|
723 | + } |
|
724 | 724 | |
725 | - // Filter out empty values. |
|
726 | - $items = content_set_empty($field, $items); |
|
725 | + // Filter out empty values. |
|
726 | + $items = content_set_empty($field, $items); |
|
727 | 727 | |
728 | - break; |
|
728 | + break; |
|
729 | 729 | |
730 | 730 | case 'view': |
731 | 731 | $addition = array(); |
732 | 732 | |
733 | - // Previewed nodes bypass the 'presave' op, so we need to some massaging. |
|
734 | - if ($node->build_mode == NODE_BUILD_PREVIEW && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
733 | + // Previewed nodes bypass the 'presave' op, so we need to some massaging. |
|
734 | + if ($node->build_mode == NODE_BUILD_PREVIEW && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
735 | 735 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
736 | - // Reorder items to account for drag-n-drop reordering. |
|
737 | - $items = _content_sort_items($field, $items); |
|
736 | + // Reorder items to account for drag-n-drop reordering. |
|
737 | + $items = _content_sort_items($field, $items); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | // Filter out empty values. |
741 | 741 | $items = content_set_empty($field, $items); |
742 | - } |
|
742 | + } |
|
743 | 743 | |
744 | - // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
745 | - if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
744 | + // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
745 | + if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
746 | 746 | $context = $teaser ? 'teaser' : 'full'; |
747 | - } |
|
748 | - else { |
|
747 | + } |
|
748 | + else { |
|
749 | 749 | $context = $node->build_mode; |
750 | - } |
|
751 | - // The field may be missing info for $contexts added by modules |
|
752 | - // enabled after the field was last edited. |
|
753 | - $formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default'; |
|
754 | - if ($formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
750 | + } |
|
751 | + // The field may be missing info for $contexts added by modules |
|
752 | + // enabled after the field was last edited. |
|
753 | + $formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default'; |
|
754 | + if ($formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
755 | 755 | $theme = $formatter['module'] .'_formatter_'. $formatter_name; |
756 | 756 | $single = (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE); |
757 | 757 | |
758 | 758 | $label_display = isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above'; |
759 | 759 | // Do not include field labels when indexing content. |
760 | 760 | if ($context == NODE_BUILD_SEARCH_INDEX) { |
761 | - $label_display = 'hidden'; |
|
761 | + $label_display = 'hidden'; |
|
762 | 762 | } |
763 | 763 | |
764 | 764 | $element = array( |
765 | - '#type' => 'content_field', |
|
766 | - '#title' => check_plain(t($field['widget']['label'])), |
|
767 | - '#field_name' => $field['field_name'], |
|
768 | - '#access' => $formatter_name != 'hidden' && content_access('view', $field, NULL, $node), |
|
769 | - '#label_display' => $label_display, |
|
770 | - '#node' => $node, |
|
771 | - '#teaser' => $teaser, |
|
772 | - '#page' => $page, |
|
773 | - '#context' => $context, |
|
774 | - '#single' => $single, |
|
775 | - 'items' => array(), |
|
765 | + '#type' => 'content_field', |
|
766 | + '#title' => check_plain(t($field['widget']['label'])), |
|
767 | + '#field_name' => $field['field_name'], |
|
768 | + '#access' => $formatter_name != 'hidden' && content_access('view', $field, NULL, $node), |
|
769 | + '#label_display' => $label_display, |
|
770 | + '#node' => $node, |
|
771 | + '#teaser' => $teaser, |
|
772 | + '#page' => $page, |
|
773 | + '#context' => $context, |
|
774 | + '#single' => $single, |
|
775 | + 'items' => array(), |
|
776 | 776 | ); |
777 | 777 | |
778 | 778 | // Fill-in items. |
779 | 779 | foreach ($items as $delta => $item) { |
780 | - $element['items'][$delta] = array( |
|
780 | + $element['items'][$delta] = array( |
|
781 | 781 | '#item' => $item, |
782 | 782 | '#weight' => $delta, |
783 | - ); |
|
783 | + ); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | // Append formatter information either on each item ('single-value' formatter) |
787 | 787 | // or at the upper 'items' level ('multiple-value' formatter) |
788 | 788 | $format_info = array( |
789 | - '#theme' => $theme, |
|
790 | - '#field_name' => $field['field_name'], |
|
791 | - '#type_name' => $node->type, |
|
792 | - '#formatter' => $formatter_name, |
|
793 | - '#node' => $node, |
|
789 | + '#theme' => $theme, |
|
790 | + '#field_name' => $field['field_name'], |
|
791 | + '#type_name' => $node->type, |
|
792 | + '#formatter' => $formatter_name, |
|
793 | + '#node' => $node, |
|
794 | 794 | ); |
795 | 795 | if ($single) { |
796 | - foreach ($items as $delta => $item) { |
|
796 | + foreach ($items as $delta => $item) { |
|
797 | 797 | $element['items'][$delta] += $format_info; |
798 | 798 | $element['items'][$delta]['#item']['#delta'] = $delta; |
799 | - } |
|
799 | + } |
|
800 | 800 | } |
801 | 801 | else { |
802 | - $element['items'] += $format_info; |
|
802 | + $element['items'] += $format_info; |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | // The wrapper lets us get the themed output for the whole field |
@@ -807,17 +807,17 @@ discard block |
||
807 | 807 | // and hide it from the $content variable if needed. |
808 | 808 | // See 'preprocess_node' op and theme_content_field_wrapper()? |
809 | 809 | $wrapper = array( |
810 | - 'field' => $element, |
|
811 | - '#weight' => $field['widget']['weight'], |
|
812 | - '#post_render' => array('content_field_wrapper_post_render'), |
|
813 | - '#field_name' => $field['field_name'], |
|
814 | - '#type_name' => $node->type, |
|
815 | - '#context' => $context, |
|
810 | + 'field' => $element, |
|
811 | + '#weight' => $field['widget']['weight'], |
|
812 | + '#post_render' => array('content_field_wrapper_post_render'), |
|
813 | + '#field_name' => $field['field_name'], |
|
814 | + '#type_name' => $node->type, |
|
815 | + '#context' => $context, |
|
816 | 816 | ); |
817 | 817 | |
818 | 818 | $addition = array($field['field_name'] => $wrapper); |
819 | - } |
|
820 | - return $addition; |
|
819 | + } |
|
820 | + return $addition; |
|
821 | 821 | |
822 | 822 | case 'alter': |
823 | 823 | // Add back the formatted values in the 'view' element, |
@@ -827,64 +827,64 @@ discard block |
||
827 | 827 | // The location of the field's rendered output depends on whether the |
828 | 828 | // field is in a fieldgroup or not. |
829 | 829 | $wrapper = NULL; |
830 | - if (isset($node->content[$field['field_name']])) { |
|
830 | + if (isset($node->content[$field['field_name']])) { |
|
831 | 831 | $wrapper = $node->content[$field['field_name']]; |
832 | - } |
|
833 | - elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
832 | + } |
|
833 | + elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
834 | 834 | $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
835 | - } |
|
835 | + } |
|
836 | 836 | |
837 | - if ($wrapper) { |
|
837 | + if ($wrapper) { |
|
838 | 838 | $element = $wrapper['field']; |
839 | 839 | // '#single' is not set if the field is hidden or inaccessible. |
840 | 840 | if (isset($element['#single'])) { |
841 | - if (!empty($element['#single'])) { |
|
841 | + if (!empty($element['#single'])) { |
|
842 | 842 | // Single value formatter. |
843 | 843 | foreach (element_children($element['items']) as $delta) { |
844 | - // '#chilren' is not set if the field is empty. |
|
845 | - $items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
844 | + // '#chilren' is not set if the field is empty. |
|
845 | + $items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
846 | + } |
|
846 | 847 | } |
847 | - } |
|
848 | - elseif (isset($element['items']['#children'])) { |
|
848 | + elseif (isset($element['items']['#children'])) { |
|
849 | 849 | // Multiple values formatter. |
850 | 850 | $items[0]['view'] = $element['items']['#children']; |
851 | - } |
|
851 | + } |
|
852 | 852 | } |
853 | 853 | else { |
854 | - // Hidden or inaccessible field. |
|
855 | - $items[0]['view'] = ''; |
|
854 | + // Hidden or inaccessible field. |
|
855 | + $items[0]['view'] = ''; |
|
856 | 856 | } |
857 | - } |
|
858 | - break; |
|
857 | + } |
|
858 | + break; |
|
859 | 859 | |
860 | 860 | case 'preprocess_node': |
861 | 861 | // Add $FIELD_NAME_rendered variables. |
862 | 862 | $addition = array(); |
863 | 863 | |
864 | - // The location of the field's rendered output depends on whether the |
|
865 | - // field is in a fieldgroup or not. |
|
866 | - $wrapper = NULL; |
|
867 | - if (isset($node->content[$field['field_name']])) { |
|
864 | + // The location of the field's rendered output depends on whether the |
|
865 | + // field is in a fieldgroup or not. |
|
866 | + $wrapper = NULL; |
|
867 | + if (isset($node->content[$field['field_name']])) { |
|
868 | 868 | $wrapper = $node->content[$field['field_name']]; |
869 | - } |
|
870 | - elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
869 | + } |
|
870 | + elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
871 | 871 | $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
872 | - } |
|
872 | + } |
|
873 | 873 | |
874 | - if ($wrapper) { |
|
874 | + if ($wrapper) { |
|
875 | 875 | // '#chilren' is not set if the field is empty. |
876 | 876 | $addition[$field['field_name'] .'_rendered'] = isset($wrapper['#children']) ? $wrapper['#children'] : ''; |
877 | - } |
|
877 | + } |
|
878 | 878 | |
879 | - return $addition; |
|
879 | + return $addition; |
|
880 | 880 | |
881 | 881 | case 'prepare translation': |
882 | 882 | $addition = array(); |
883 | - if (isset($node->translation_source->$field['field_name'])) { |
|
883 | + if (isset($node->translation_source->$field['field_name'])) { |
|
884 | 884 | $addition[$field['field_name']] = $node->translation_source->$field['field_name']; |
885 | - } |
|
886 | - return $addition; |
|
887 | - } |
|
885 | + } |
|
886 | + return $addition; |
|
887 | + } |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | /** |
@@ -899,24 +899,24 @@ discard block |
||
899 | 899 | * returns filtered and adjusted item array |
900 | 900 | */ |
901 | 901 | function content_set_empty($field, $items) { |
902 | - // Filter out empty values. |
|
903 | - $filtered = array(); |
|
904 | - $function = $field['module'] .'_content_is_empty'; |
|
905 | - foreach ((array) $items as $delta => $item) { |
|
902 | + // Filter out empty values. |
|
903 | + $filtered = array(); |
|
904 | + $function = $field['module'] .'_content_is_empty'; |
|
905 | + foreach ((array) $items as $delta => $item) { |
|
906 | 906 | if (!$function($item, $field)) { |
907 | - $filtered[] = $item; |
|
907 | + $filtered[] = $item; |
|
908 | + } |
|
908 | 909 | } |
909 | - } |
|
910 | 910 | |
911 | - // Make sure we store the right number of 'empty' values. |
|
912 | - $empty = array(); |
|
913 | - foreach (array_keys($field['columns']) as $column) { |
|
911 | + // Make sure we store the right number of 'empty' values. |
|
912 | + $empty = array(); |
|
913 | + foreach (array_keys($field['columns']) as $column) { |
|
914 | 914 | $empty[$column] = NULL; |
915 | - } |
|
916 | - $pad = $field['multiple'] > 1 ? $field['multiple'] : 1; |
|
917 | - $filtered = array_pad($filtered, $pad, $empty); |
|
915 | + } |
|
916 | + $pad = $field['multiple'] > 1 ? $field['multiple'] : 1; |
|
917 | + $filtered = array_pad($filtered, $pad, $empty); |
|
918 | 918 | |
919 | - return $filtered; |
|
919 | + return $filtered; |
|
920 | 920 | } |
921 | 921 | |
922 | 922 | /** |
@@ -924,15 +924,15 @@ discard block |
||
924 | 924 | * user drag-n-drop reordering. |
925 | 925 | */ |
926 | 926 | function _content_sort_items($field, $items) { |
927 | - if ($field['multiple'] >= 1 && isset($items[0]['_weight'])) { |
|
927 | + if ($field['multiple'] >= 1 && isset($items[0]['_weight'])) { |
|
928 | 928 | usort($items, '_content_sort_items_helper'); |
929 | 929 | foreach ($items as $delta => $item) { |
930 | - if (is_array($items[$delta])) { |
|
930 | + if (is_array($items[$delta])) { |
|
931 | 931 | unset($items[$delta]['_weight']); |
932 | - } |
|
932 | + } |
|
933 | + } |
|
933 | 934 | } |
934 | - } |
|
935 | - return $items; |
|
935 | + return $items; |
|
936 | 936 | } |
937 | 937 | |
938 | 938 | /** |
@@ -940,50 +940,50 @@ discard block |
||
940 | 940 | * (copied form element_sort(), which acts on #weight keys) |
941 | 941 | */ |
942 | 942 | function _content_sort_items_helper($a, $b) { |
943 | - $a_weight = (is_array($a) && isset($a['_weight'])) ? $a['_weight'] : 0; |
|
944 | - $b_weight = (is_array($b) && isset($b['_weight'])) ? $b['_weight'] : 0; |
|
945 | - if ($a_weight == $b_weight) { |
|
943 | + $a_weight = (is_array($a) && isset($a['_weight'])) ? $a['_weight'] : 0; |
|
944 | + $b_weight = (is_array($b) && isset($b['_weight'])) ? $b['_weight'] : 0; |
|
945 | + if ($a_weight == $b_weight) { |
|
946 | 946 | return 0; |
947 | - } |
|
948 | - return ($a_weight < $b_weight) ? -1 : 1; |
|
947 | + } |
|
948 | + return ($a_weight < $b_weight) ? -1 : 1; |
|
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
952 | 952 | * Same as above, using ['_weight']['#value'] |
953 | 953 | */ |
954 | 954 | function _content_sort_items_value_helper($a, $b) { |
955 | - $a_weight = (is_array($a) && isset($a['_weight']['#value'])) ? $a['_weight']['#value'] : 0; |
|
956 | - $b_weight = (is_array($b) && isset($b['_weight']['#value'])) ? $b['_weight']['#value'] : 0; |
|
957 | - if ($a_weight == $b_weight) { |
|
955 | + $a_weight = (is_array($a) && isset($a['_weight']['#value'])) ? $a['_weight']['#value'] : 0; |
|
956 | + $b_weight = (is_array($b) && isset($b['_weight']['#value'])) ? $b['_weight']['#value'] : 0; |
|
957 | + if ($a_weight == $b_weight) { |
|
958 | 958 | return 0; |
959 | - } |
|
960 | - return ($a_weight < $b_weight) ? -1 : 1; |
|
959 | + } |
|
960 | + return ($a_weight < $b_weight) ? -1 : 1; |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | /** |
964 | 964 | * Handle storage ops for _content_field_invoke_default(). |
965 | 965 | */ |
966 | 966 | function content_storage($op, $node) { |
967 | - // Don't try this before content module's update is run to add |
|
968 | - // the active and module columns. |
|
969 | - if (variable_get('content_schema_version', -1) < 6007) { |
|
967 | + // Don't try this before content module's update is run to add |
|
968 | + // the active and module columns. |
|
969 | + if (variable_get('content_schema_version', -1) < 6007) { |
|
970 | 970 | return FALSE; |
971 | - } |
|
971 | + } |
|
972 | 972 | |
973 | - $type_name = $node->type; |
|
974 | - $type = content_types($type_name); |
|
973 | + $type_name = $node->type; |
|
974 | + $type = content_types($type_name); |
|
975 | 975 | |
976 | - switch ($op) { |
|
976 | + switch ($op) { |
|
977 | 977 | case 'load': |
978 | 978 | // OPTIMIZE: load all non multiple fields in a single JOIN query ? |
979 | 979 | // warning: 61-join limit in MySQL ? |
980 | 980 | $additions = array(); |
981 | - // For each table used by this content type, |
|
982 | - foreach ($type['tables'] as $table) { |
|
981 | + // For each table used by this content type, |
|
982 | + foreach ($type['tables'] as $table) { |
|
983 | 983 | $schema = drupal_get_schema($table); |
984 | 984 | // The per-type table might not have any fields actually stored in it. |
985 | 985 | if (!$schema['content fields']) { |
986 | - continue; |
|
986 | + continue; |
|
987 | 987 | } |
988 | 988 | $query = 'SELECT * FROM {'. $table .'} WHERE vid = %d'; |
989 | 989 | |
@@ -994,25 +994,25 @@ discard block |
||
994 | 994 | |
995 | 995 | // For each table row, populate the fields. |
996 | 996 | while ($row = db_fetch_array($result)) { |
997 | - // For each field stored in the table, add the field item. |
|
998 | - foreach ($schema['content fields'] as $field_name) { |
|
997 | + // For each field stored in the table, add the field item. |
|
998 | + foreach ($schema['content fields'] as $field_name) { |
|
999 | 999 | $item = array(); |
1000 | 1000 | $field = content_fields($field_name, $type_name); |
1001 | 1001 | $db_info = content_database_info($field); |
1002 | 1002 | // For each column declared by the field, populate the item. |
1003 | 1003 | foreach ($db_info['columns'] as $column => $attributes) { |
1004 | - $item[$column] = $row[$attributes['column']]; |
|
1004 | + $item[$column] = $row[$attributes['column']]; |
|
1005 | 1005 | } |
1006 | 1006 | |
1007 | 1007 | // Add the item to the field values for the node. |
1008 | 1008 | if (!isset($additions[$field_name])) { |
1009 | - $additions[$field_name] = array(); |
|
1009 | + $additions[$field_name] = array(); |
|
1010 | 1010 | } |
1011 | 1011 | $additions[$field_name][] = $item; |
1012 | - } |
|
1012 | + } |
|
1013 | 1013 | } |
1014 | - } |
|
1015 | - return $additions; |
|
1014 | + } |
|
1015 | + return $additions; |
|
1016 | 1016 | |
1017 | 1017 | case 'insert': |
1018 | 1018 | case 'update': |
@@ -1020,17 +1020,17 @@ discard block |
||
1020 | 1020 | $schema = drupal_get_schema($table); |
1021 | 1021 | $record = array(); |
1022 | 1022 | foreach ($schema['content fields'] as $field_name) { |
1023 | - if (isset($node->$field_name)) { |
|
1023 | + if (isset($node->$field_name)) { |
|
1024 | 1024 | $field = content_fields($field_name, $type_name); |
1025 | 1025 | // Multiple fields need specific handling, we'll deal with them later on. |
1026 | 1026 | if ($field['multiple']) { |
1027 | - continue; |
|
1027 | + continue; |
|
1028 | 1028 | } |
1029 | 1029 | $db_info = content_database_info($field); |
1030 | 1030 | foreach ($db_info['columns'] as $column => $attributes) { |
1031 | - $record[$attributes['column']] = $node->{$field_name}[0][$column]; |
|
1031 | + $record[$attributes['column']] = $node->{$field_name}[0][$column]; |
|
1032 | + } |
|
1032 | 1033 | } |
1033 | - } |
|
1034 | 1034 | } |
1035 | 1035 | // $record might be empty because |
1036 | 1036 | // - the table stores a multiple field : |
@@ -1038,59 +1038,59 @@ discard block |
||
1038 | 1038 | // - this is the per-type table and no field is actually stored in it : |
1039 | 1039 | // we still store the nid and vid |
1040 | 1040 | if (count($record) || empty($schema['content fields'])) { |
1041 | - $record['nid'] = $node->nid; |
|
1042 | - $record['vid'] = $node->vid; |
|
1043 | - // Can't rely on the insert/update op of the node to decide if this |
|
1044 | - // is an insert or an update, a node or revision may have existed |
|
1045 | - // before any fields were created, so there may not be an entry here. |
|
1046 | - |
|
1047 | - // TODO - should we auto create an entry for all existing nodes when |
|
1048 | - // fields are added to content types -- either a NULL value |
|
1049 | - // or the default value? May need to offer the user an option of |
|
1050 | - // how to handle that. |
|
1051 | - if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE vid = %d", $node->vid))) { |
|
1041 | + $record['nid'] = $node->nid; |
|
1042 | + $record['vid'] = $node->vid; |
|
1043 | + // Can't rely on the insert/update op of the node to decide if this |
|
1044 | + // is an insert or an update, a node or revision may have existed |
|
1045 | + // before any fields were created, so there may not be an entry here. |
|
1046 | + |
|
1047 | + // TODO - should we auto create an entry for all existing nodes when |
|
1048 | + // fields are added to content types -- either a NULL value |
|
1049 | + // or the default value? May need to offer the user an option of |
|
1050 | + // how to handle that. |
|
1051 | + if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE vid = %d", $node->vid))) { |
|
1052 | 1052 | content_write_record($table, $record, array('vid')); |
1053 | - } |
|
1054 | - else { |
|
1053 | + } |
|
1054 | + else { |
|
1055 | 1055 | content_write_record($table, $record); |
1056 | - } |
|
1056 | + } |
|
1057 | + } |
|
1057 | 1058 | } |
1058 | - } |
|
1059 | 1059 | |
1060 | - // Handle multiple fields. |
|
1061 | - foreach ($type['fields'] as $field) { |
|
1060 | + // Handle multiple fields. |
|
1061 | + foreach ($type['fields'] as $field) { |
|
1062 | 1062 | if ($field['multiple'] && isset($node->$field['field_name'])) { |
1063 | - $db_info = content_database_info($field); |
|
1064 | - // Delete and insert, rather than update, in case a value was added. |
|
1065 | - if ($op == 'update') { |
|
1063 | + $db_info = content_database_info($field); |
|
1064 | + // Delete and insert, rather than update, in case a value was added. |
|
1065 | + if ($op == 'update') { |
|
1066 | 1066 | db_query('DELETE FROM {'. $db_info['table'] .'} WHERE vid = %d', $node->vid); |
1067 | - } |
|
1068 | - foreach ($node->$field['field_name'] as $delta => $item) { |
|
1067 | + } |
|
1068 | + foreach ($node->$field['field_name'] as $delta => $item) { |
|
1069 | 1069 | $record = array(); |
1070 | 1070 | foreach ($db_info['columns'] as $column => $attributes) { |
1071 | - $record[$attributes['column']] = $item[$column]; |
|
1071 | + $record[$attributes['column']] = $item[$column]; |
|
1072 | 1072 | } |
1073 | 1073 | $record['nid'] = $node->nid; |
1074 | 1074 | $record['vid'] = $node->vid; |
1075 | 1075 | $record['delta'] = $delta; |
1076 | 1076 | content_write_record($db_info['table'], $record); |
1077 | - } |
|
1077 | + } |
|
1078 | 1078 | } |
1079 | - } |
|
1080 | - break; |
|
1079 | + } |
|
1080 | + break; |
|
1081 | 1081 | |
1082 | 1082 | case 'delete': |
1083 | 1083 | foreach ($type['tables'] as $table) { |
1084 | 1084 | db_query('DELETE FROM {'. $table .'} WHERE nid = %d', $node->nid); |
1085 | - } |
|
1086 | - break; |
|
1085 | + } |
|
1086 | + break; |
|
1087 | 1087 | |
1088 | 1088 | case 'delete revision': |
1089 | 1089 | foreach ($type['tables'] as $table) { |
1090 | 1090 | db_query('DELETE FROM {'. $table .'} WHERE vid = %d', $node->vid); |
1091 | - } |
|
1092 | - break; |
|
1093 | - } |
|
1091 | + } |
|
1092 | + break; |
|
1093 | + } |
|
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | /** |
@@ -1125,108 +1125,108 @@ discard block |
||
1125 | 1125 | * a new node. |
1126 | 1126 | */ |
1127 | 1127 | function content_write_record($table, &$object, $update = array()) { |
1128 | - // Standardize $update to an array. |
|
1129 | - if (is_string($update)) { |
|
1128 | + // Standardize $update to an array. |
|
1129 | + if (is_string($update)) { |
|
1130 | 1130 | $update = array($update); |
1131 | - } |
|
1131 | + } |
|
1132 | 1132 | |
1133 | - // Convert to an object if needed. |
|
1134 | - if (is_array($object)) { |
|
1133 | + // Convert to an object if needed. |
|
1134 | + if (is_array($object)) { |
|
1135 | 1135 | $object = (object) $object; |
1136 | 1136 | $array = TRUE; |
1137 | - } |
|
1138 | - else { |
|
1137 | + } |
|
1138 | + else { |
|
1139 | 1139 | $array = FALSE; |
1140 | - } |
|
1140 | + } |
|
1141 | 1141 | |
1142 | - $schema = drupal_get_schema($table); |
|
1143 | - if (empty($schema)) { |
|
1142 | + $schema = drupal_get_schema($table); |
|
1143 | + if (empty($schema)) { |
|
1144 | 1144 | return FALSE; |
1145 | - } |
|
1145 | + } |
|
1146 | 1146 | |
1147 | - $fields = $defs = $values = $serials = $placeholders = array(); |
|
1147 | + $fields = $defs = $values = $serials = $placeholders = array(); |
|
1148 | 1148 | |
1149 | - // Go through our schema, build SQL, and when inserting, fill in defaults for |
|
1150 | - // fields that are not set. |
|
1151 | - foreach ($schema['fields'] as $field => $info) { |
|
1149 | + // Go through our schema, build SQL, and when inserting, fill in defaults for |
|
1150 | + // fields that are not set. |
|
1151 | + foreach ($schema['fields'] as $field => $info) { |
|
1152 | 1152 | // Special case -- skip serial types if we are updating. |
1153 | 1153 | if ($info['type'] == 'serial' && count($update)) { |
1154 | - continue; |
|
1154 | + continue; |
|
1155 | 1155 | } |
1156 | 1156 | |
1157 | 1157 | // For inserts, populate defaults from Schema if not already provided |
1158 | 1158 | if (!isset($object->$field) && !count($update) && isset($info['default'])) { |
1159 | - $object->$field = $info['default']; |
|
1159 | + $object->$field = $info['default']; |
|
1160 | 1160 | } |
1161 | 1161 | |
1162 | 1162 | // Track serial fields so we can helpfully populate them after the query. |
1163 | 1163 | if ($info['type'] == 'serial') { |
1164 | - $serials[] = $field; |
|
1165 | - // Ignore values for serials when inserting data. Unsupported. |
|
1166 | - unset($object->$field); |
|
1164 | + $serials[] = $field; |
|
1165 | + // Ignore values for serials when inserting data. Unsupported. |
|
1166 | + unset($object->$field); |
|
1167 | 1167 | } |
1168 | 1168 | |
1169 | 1169 | // Build arrays for the fields, placeholders, and values in our query. |
1170 | 1170 | if (isset($object->$field) || array_key_exists($field, $object)) { |
1171 | - $fields[] = $field; |
|
1172 | - if (isset($object->$field)) { |
|
1171 | + $fields[] = $field; |
|
1172 | + if (isset($object->$field)) { |
|
1173 | 1173 | $placeholders[] = db_type_placeholder($info['type']); |
1174 | 1174 | |
1175 | 1175 | if (empty($info['serialize'])) { |
1176 | - $values[] = $object->$field; |
|
1176 | + $values[] = $object->$field; |
|
1177 | 1177 | } |
1178 | 1178 | else { |
1179 | - $values[] = serialize($object->$field); |
|
1179 | + $values[] = serialize($object->$field); |
|
1180 | + } |
|
1180 | 1181 | } |
1181 | - } |
|
1182 | - else { |
|
1182 | + else { |
|
1183 | 1183 | $placeholders[] = 'NULL'; |
1184 | - } |
|
1184 | + } |
|
1185 | + } |
|
1185 | 1186 | } |
1186 | - } |
|
1187 | 1187 | |
1188 | - // Build the SQL. |
|
1189 | - $query = ''; |
|
1190 | - if (!count($update)) { |
|
1188 | + // Build the SQL. |
|
1189 | + $query = ''; |
|
1190 | + if (!count($update)) { |
|
1191 | 1191 | $query = "INSERT INTO {". $table ."} (". implode(', ', $fields) .') VALUES ('. implode(', ', $placeholders) .')'; |
1192 | 1192 | $return = SAVED_NEW; |
1193 | - } |
|
1194 | - else { |
|
1193 | + } |
|
1194 | + else { |
|
1195 | 1195 | $query = ''; |
1196 | 1196 | foreach ($fields as $id => $field) { |
1197 | - if ($query) { |
|
1197 | + if ($query) { |
|
1198 | 1198 | $query .= ', '; |
1199 | - } |
|
1200 | - $query .= $field .' = '. $placeholders[$id]; |
|
1199 | + } |
|
1200 | + $query .= $field .' = '. $placeholders[$id]; |
|
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | foreach ($update as $key) { |
1204 | - $conditions[] = "$key = ". db_type_placeholder($schema['fields'][$key]['type']); |
|
1205 | - $values[] = $object->$key; |
|
1204 | + $conditions[] = "$key = ". db_type_placeholder($schema['fields'][$key]['type']); |
|
1205 | + $values[] = $object->$key; |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | $query = "UPDATE {". $table ."} SET $query WHERE ". implode(' AND ', $conditions); |
1209 | 1209 | $return = SAVED_UPDATED; |
1210 | - } |
|
1210 | + } |
|
1211 | 1211 | |
1212 | - // Execute the SQL. |
|
1213 | - if (db_query($query, $values)) { |
|
1212 | + // Execute the SQL. |
|
1213 | + if (db_query($query, $values)) { |
|
1214 | 1214 | if ($serials) { |
1215 | - // Get last insert ids and fill them in. |
|
1216 | - foreach ($serials as $field) { |
|
1215 | + // Get last insert ids and fill them in. |
|
1216 | + foreach ($serials as $field) { |
|
1217 | 1217 | $object->$field = db_last_insert_id($table, $field); |
1218 | - } |
|
1218 | + } |
|
1219 | 1219 | } |
1220 | 1220 | |
1221 | 1221 | // If we began with an array, convert back so we don't surprise the caller. |
1222 | 1222 | if ($array) { |
1223 | - $object = (array) $object; |
|
1223 | + $object = (array) $object; |
|
1224 | 1224 | } |
1225 | 1225 | |
1226 | 1226 | return $return; |
1227 | - } |
|
1227 | + } |
|
1228 | 1228 | |
1229 | - return FALSE; |
|
1229 | + return FALSE; |
|
1230 | 1230 | } |
1231 | 1231 | |
1232 | 1232 | /** |
@@ -1236,12 +1236,12 @@ discard block |
||
1236 | 1236 | * called so that the default database handling can occur. |
1237 | 1237 | */ |
1238 | 1238 | function _content_field_invoke($op, &$node, $teaser = NULL, $page = NULL) { |
1239 | - $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); |
|
1240 | - $type = content_types($type_name); |
|
1241 | - $field_types = _content_field_types(); |
|
1239 | + $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); |
|
1240 | + $type = content_types($type_name); |
|
1241 | + $field_types = _content_field_types(); |
|
1242 | 1242 | |
1243 | - $return = array(); |
|
1244 | - foreach ($type['fields'] as $field) { |
|
1243 | + $return = array(); |
|
1244 | + foreach ($type['fields'] as $field) { |
|
1245 | 1245 | $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); |
1246 | 1246 | |
1247 | 1247 | // Make sure AHAH 'add more' button isn't sent to the fields for processing. |
@@ -1250,52 +1250,52 @@ discard block |
||
1250 | 1250 | $module = $field_types[$field['type']]['module']; |
1251 | 1251 | $function = $module .'_field'; |
1252 | 1252 | if (function_exists($function)) { |
1253 | - $result = $function($op, $node, $field, $items, $teaser, $page); |
|
1254 | - if (is_array($result)) { |
|
1253 | + $result = $function($op, $node, $field, $items, $teaser, $page); |
|
1254 | + if (is_array($result)) { |
|
1255 | 1255 | $return = array_merge($return, $result); |
1256 | - } |
|
1257 | - else if (isset($result)) { |
|
1256 | + } |
|
1257 | + else if (isset($result)) { |
|
1258 | 1258 | $return[] = $result; |
1259 | - } |
|
1259 | + } |
|
1260 | 1260 | } |
1261 | 1261 | // test for values in $items in case modules added items on insert |
1262 | 1262 | if (isset($node->$field['field_name']) || count($items)) { |
1263 | - $node->$field['field_name'] = $items; |
|
1263 | + $node->$field['field_name'] = $items; |
|
1264 | + } |
|
1264 | 1265 | } |
1265 | - } |
|
1266 | - return $return; |
|
1266 | + return $return; |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | 1269 | /** |
1270 | 1270 | * Invoke content.module's version of a field hook. |
1271 | 1271 | */ |
1272 | 1272 | function _content_field_invoke_default($op, &$node, $teaser = NULL, $page = NULL) { |
1273 | - $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); |
|
1274 | - $type = content_types($type_name); |
|
1275 | - $field_types = _content_field_types(); |
|
1276 | - |
|
1277 | - $return = array(); |
|
1278 | - // The operations involving database queries are better off handled by table |
|
1279 | - // rather than by field. |
|
1280 | - if (in_array($op, array('load', 'insert', 'update', 'delete', 'delete revision'))) { |
|
1273 | + $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); |
|
1274 | + $type = content_types($type_name); |
|
1275 | + $field_types = _content_field_types(); |
|
1276 | + |
|
1277 | + $return = array(); |
|
1278 | + // The operations involving database queries are better off handled by table |
|
1279 | + // rather than by field. |
|
1280 | + if (in_array($op, array('load', 'insert', 'update', 'delete', 'delete revision'))) { |
|
1281 | 1281 | return content_storage($op, $node); |
1282 | - } |
|
1283 | - else { |
|
1282 | + } |
|
1283 | + else { |
|
1284 | 1284 | foreach ($type['fields'] as $field) { |
1285 | - $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); |
|
1286 | - $result = content_field($op, $node, $field, $items, $teaser, $page); |
|
1287 | - if (is_array($result)) { |
|
1285 | + $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); |
|
1286 | + $result = content_field($op, $node, $field, $items, $teaser, $page); |
|
1287 | + if (is_array($result)) { |
|
1288 | 1288 | $return = array_merge($return, $result); |
1289 | - } |
|
1290 | - else if (isset($result)) { |
|
1289 | + } |
|
1290 | + else if (isset($result)) { |
|
1291 | 1291 | $return[] = $result; |
1292 | - } |
|
1293 | - if (isset($node->$field['field_name'])) { |
|
1292 | + } |
|
1293 | + if (isset($node->$field['field_name'])) { |
|
1294 | 1294 | $node->$field['field_name'] = $items; |
1295 | - } |
|
1295 | + } |
|
1296 | + } |
|
1296 | 1297 | } |
1297 | - } |
|
1298 | - return $return; |
|
1298 | + return $return; |
|
1299 | 1299 | } |
1300 | 1300 | |
1301 | 1301 | /** |
@@ -1308,19 +1308,19 @@ discard block |
||
1308 | 1308 | * info to avoid foreach errors elsewhere in the code. |
1309 | 1309 | */ |
1310 | 1310 | function content_types($type_name = NULL) { |
1311 | - // handle type name with either an underscore or a dash |
|
1312 | - $type_name = !empty($type_name) ? str_replace('-', '_', $type_name) : NULL; |
|
1311 | + // handle type name with either an underscore or a dash |
|
1312 | + $type_name = !empty($type_name) ? str_replace('-', '_', $type_name) : NULL; |
|
1313 | 1313 | |
1314 | - $info = _content_type_info(); |
|
1315 | - if (isset($info['content types'])) { |
|
1314 | + $info = _content_type_info(); |
|
1315 | + if (isset($info['content types'])) { |
|
1316 | 1316 | if (!isset($type_name)) { |
1317 | - return $info['content types']; |
|
1317 | + return $info['content types']; |
|
1318 | 1318 | } |
1319 | 1319 | if (isset($info['content types'][$type_name])) { |
1320 | - return $info['content types'][$type_name]; |
|
1320 | + return $info['content types'][$type_name]; |
|
1321 | + } |
|
1321 | 1322 | } |
1322 | - } |
|
1323 | - return array('tables' => array(), 'fields' => array(), 'extra' => array()); |
|
1323 | + return array('tables' => array(), 'fields' => array(), 'extra' => array()); |
|
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | /** |
@@ -1337,36 +1337,36 @@ discard block |
||
1337 | 1337 | * but empty, as sometimes happens in the formatter. |
1338 | 1338 | */ |
1339 | 1339 | function content_fields($field_name = NULL, $content_type_name = NULL) { |
1340 | - $info = _content_type_info(); |
|
1341 | - if (isset($info['fields'])) { |
|
1340 | + $info = _content_type_info(); |
|
1341 | + if (isset($info['fields'])) { |
|
1342 | 1342 | if (empty($field_name)) { |
1343 | - return $info['fields']; |
|
1343 | + return $info['fields']; |
|
1344 | 1344 | } |
1345 | 1345 | if (isset($info['fields'][$field_name])) { |
1346 | - if (empty($content_type_name)) { |
|
1346 | + if (empty($content_type_name)) { |
|
1347 | 1347 | return $info['fields'][$field_name]; |
1348 | - } |
|
1349 | - if (isset($info['content types'][$content_type_name]['fields'][$field_name])) { |
|
1348 | + } |
|
1349 | + if (isset($info['content types'][$content_type_name]['fields'][$field_name])) { |
|
1350 | 1350 | return $info['content types'][$content_type_name]['fields'][$field_name]; |
1351 | - } |
|
1351 | + } |
|
1352 | + } |
|
1352 | 1353 | } |
1353 | - } |
|
1354 | 1354 | } |
1355 | 1355 | |
1356 | 1356 | /** |
1357 | 1357 | * Return a list of field types. |
1358 | 1358 | */ |
1359 | 1359 | function _content_field_types() { |
1360 | - $info = _content_type_info(); |
|
1361 | - return isset($info['field types']) ? $info['field types'] : array(); |
|
1360 | + $info = _content_type_info(); |
|
1361 | + return isset($info['field types']) ? $info['field types'] : array(); |
|
1362 | 1362 | } |
1363 | 1363 | |
1364 | 1364 | /** |
1365 | 1365 | * Return a list of widget types. |
1366 | 1366 | */ |
1367 | 1367 | function _content_widget_types() { |
1368 | - $info = _content_type_info(); |
|
1369 | - return isset($info['widget types']) ? $info['widget types'] : array(); |
|
1368 | + $info = _content_type_info(); |
|
1369 | + return isset($info['widget types']) ? $info['widget types'] : array(); |
|
1370 | 1370 | } |
1371 | 1371 | |
1372 | 1372 | /** |
@@ -1374,16 +1374,16 @@ discard block |
||
1374 | 1374 | * defaulting to 'default' if none is found. |
1375 | 1375 | */ |
1376 | 1376 | function _content_get_formatter($formatter_name, $field_type) { |
1377 | - $field_types = _content_field_types(); |
|
1378 | - $formatters = $field_types[$field_type]['formatters']; |
|
1377 | + $field_types = _content_field_types(); |
|
1378 | + $formatters = $field_types[$field_type]['formatters']; |
|
1379 | 1379 | |
1380 | - if (!isset($formatters[$formatter_name]) && $formatter_name != 'hidden') { |
|
1380 | + if (!isset($formatters[$formatter_name]) && $formatter_name != 'hidden') { |
|
1381 | 1381 | // This might happen when the selected formatter has been renamed in the |
1382 | 1382 | // module, or if the module has been disabled since then. |
1383 | 1383 | $formatter_name = 'default'; |
1384 | - } |
|
1384 | + } |
|
1385 | 1385 | |
1386 | - return isset($formatters[$formatter_name]) ? $formatters[$formatter_name] : FALSE; |
|
1386 | + return isset($formatters[$formatter_name]) ? $formatters[$formatter_name] : FALSE; |
|
1387 | 1387 | } |
1388 | 1388 | |
1389 | 1389 | /** |
@@ -1393,10 +1393,10 @@ discard block |
||
1393 | 1393 | * If TRUE, clear the cache and fetch the information from the database again. |
1394 | 1394 | */ |
1395 | 1395 | function _content_type_info($reset = FALSE) { |
1396 | - global $language; |
|
1397 | - static $info; |
|
1396 | + global $language; |
|
1397 | + static $info; |
|
1398 | 1398 | |
1399 | - if ($reset || !isset($info)) { |
|
1399 | + if ($reset || !isset($info)) { |
|
1400 | 1400 | // Make sure this function doesn't run until the tables have been created, |
1401 | 1401 | // For instance: when first enabled and called from content_menu(), |
1402 | 1402 | // or when uninstalled and some subsequent field module uninstall |
@@ -1405,38 +1405,38 @@ discard block |
||
1405 | 1405 | // Don't try this before content module's update is run |
1406 | 1406 | // to add module and active columns to the table. |
1407 | 1407 | if (variable_get('content_schema_version', -1) < 6007) { |
1408 | - return array(); |
|
1408 | + return array(); |
|
1409 | 1409 | } |
1410 | 1410 | |
1411 | 1411 | if (!$reset && $cached = cache_get('content_type_info:'. $language->language, content_cache_tablename())) { |
1412 | - $info = $cached->data; |
|
1412 | + $info = $cached->data; |
|
1413 | 1413 | } |
1414 | 1414 | else { |
1415 | - $info = array( |
|
1415 | + $info = array( |
|
1416 | 1416 | 'field types' => array(), |
1417 | 1417 | 'widget types' => array(), |
1418 | 1418 | 'fields' => array(), |
1419 | 1419 | 'content types' => array(), |
1420 | - ); |
|
1420 | + ); |
|
1421 | 1421 | |
1422 | - // Populate field types. |
|
1423 | - foreach (module_list() as $module) { |
|
1422 | + // Populate field types. |
|
1423 | + foreach (module_list() as $module) { |
|
1424 | 1424 | $module_field_types = module_invoke($module, 'field_info'); |
1425 | 1425 | if ($module_field_types) { |
1426 | - foreach ($module_field_types as $name => $field_info) { |
|
1426 | + foreach ($module_field_types as $name => $field_info) { |
|
1427 | 1427 | // Truncate names to match the value that is stored in the database. |
1428 | 1428 | $db_name = substr($name, 0, 32); |
1429 | 1429 | $info['field types'][$db_name] = $field_info; |
1430 | 1430 | $info['field types'][$db_name]['module'] = $module; |
1431 | 1431 | $info['field types'][$db_name]['formatters'] = array(); |
1432 | - } |
|
1432 | + } |
|
1433 | + } |
|
1433 | 1434 | } |
1434 | - } |
|
1435 | 1435 | |
1436 | - // Populate widget types and formatters for known field types. |
|
1437 | - foreach (module_list() as $module) { |
|
1436 | + // Populate widget types and formatters for known field types. |
|
1437 | + foreach (module_list() as $module) { |
|
1438 | 1438 | if ($module_widgets = module_invoke($module, 'widget_info')) { |
1439 | - foreach ($module_widgets as $name => $widget_info) { |
|
1439 | + foreach ($module_widgets as $name => $widget_info) { |
|
1440 | 1440 | // Truncate names to match the value that is stored in the database. |
1441 | 1441 | $db_name = substr($name, 0, 32); |
1442 | 1442 | $info['widget types'][$db_name] = $widget_info; |
@@ -1444,44 +1444,44 @@ discard block |
||
1444 | 1444 | // Replace field types with db_compatible version of known field types. |
1445 | 1445 | $info['widget types'][$db_name]['field types'] = array(); |
1446 | 1446 | foreach ($widget_info['field types'] as $field_type) { |
1447 | - $field_type_db_name = substr($field_type, 0, 32); |
|
1448 | - if (isset($info['field types'][$field_type_db_name])) { |
|
1447 | + $field_type_db_name = substr($field_type, 0, 32); |
|
1448 | + if (isset($info['field types'][$field_type_db_name])) { |
|
1449 | 1449 | $info['widget types'][$db_name]['field types'][] = $field_type_db_name; |
1450 | - } |
|
1450 | + } |
|
1451 | + } |
|
1451 | 1452 | } |
1452 | - } |
|
1453 | 1453 | } |
1454 | 1454 | |
1455 | 1455 | if ($module_formatters = module_invoke($module, 'field_formatter_info')) { |
1456 | - foreach ($module_formatters as $name => $formatter_info) { |
|
1456 | + foreach ($module_formatters as $name => $formatter_info) { |
|
1457 | 1457 | foreach ($formatter_info['field types'] as $field_type) { |
1458 | - // Truncate names to match the value that is stored in the database. |
|
1459 | - $db_name = substr($field_type, 0, 32); |
|
1460 | - if (isset($info['field types'][$db_name])) { |
|
1458 | + // Truncate names to match the value that is stored in the database. |
|
1459 | + $db_name = substr($field_type, 0, 32); |
|
1460 | + if (isset($info['field types'][$db_name])) { |
|
1461 | 1461 | $info['field types'][$db_name]['formatters'][$name] = $formatter_info; |
1462 | 1462 | $info['field types'][$db_name]['formatters'][$name]['module'] = $module; |
1463 | - } |
|
1463 | + } |
|
1464 | 1464 | } |
1465 | - } |
|
1465 | + } |
|
1466 | + } |
|
1466 | 1467 | } |
1467 | - } |
|
1468 | 1468 | |
1469 | - // Populate actual field instances. |
|
1470 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
1471 | - foreach (node_get_types('types', NULL, TRUE) as $type_name => $data) { |
|
1469 | + // Populate actual field instances. |
|
1470 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
1471 | + foreach (node_get_types('types', NULL, TRUE) as $type_name => $data) { |
|
1472 | 1472 | $type = (array) $data; |
1473 | 1473 | $type['url_str'] = str_replace('_', '-', $type['type']); |
1474 | 1474 | $type['fields'] = array(); |
1475 | 1475 | $type['tables'] = array(); |
1476 | 1476 | if ($fields = content_field_instance_read(array('type_name' => $type_name))) { |
1477 | - foreach ($fields as $field) { |
|
1477 | + foreach ($fields as $field) { |
|
1478 | 1478 | $db_info = content_database_info($field); |
1479 | 1479 | $type['tables'][$db_info['table']] = $db_info['table']; |
1480 | 1480 | |
1481 | 1481 | // Allow external modules to translate field strings. |
1482 | 1482 | $field_strings = array( |
1483 | - 'widget_label' => $field['widget']['label'], |
|
1484 | - 'widget_description' => $field['widget']['description'], |
|
1483 | + 'widget_label' => $field['widget']['label'], |
|
1484 | + 'widget_description' => $field['widget']['description'], |
|
1485 | 1485 | ); |
1486 | 1486 | drupal_alter('content_field_strings', $field_strings, $field['type_name'], $field['field_name']); |
1487 | 1487 | $field['widget']['label'] = $field_strings['widget_label']; |
@@ -1491,11 +1491,11 @@ discard block |
||
1491 | 1491 | // This means that content_fields($field_name) (no type name) |
1492 | 1492 | // returns the last instance loaded. |
1493 | 1493 | $info['fields'][$field['field_name']] = $field; |
1494 | - } |
|
1495 | - // Make sure the per-type table is added, even if no field is actually |
|
1496 | - // stored in it. |
|
1497 | - $table = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE); |
|
1498 | - $type['tables'][$table] = $table; |
|
1494 | + } |
|
1495 | + // Make sure the per-type table is added, even if no field is actually |
|
1496 | + // stored in it. |
|
1497 | + $table = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE); |
|
1498 | + $type['tables'][$table] = $table; |
|
1499 | 1499 | } |
1500 | 1500 | |
1501 | 1501 | // Gather information about non-CCK 'fields'. |
@@ -1503,21 +1503,21 @@ discard block |
||
1503 | 1503 | drupal_alter('content_extra_fields', $extra, $type_name); |
1504 | 1504 | // Add saved weights. |
1505 | 1505 | foreach (variable_get('content_extra_weights_'. $type_name, array()) as $key => $value) { |
1506 | - // Some stored entries might not exist anymore, for instance if uploads |
|
1507 | - // have been disabled, or vocabularies removed... |
|
1508 | - if (isset($extra[$key])) { |
|
1506 | + // Some stored entries might not exist anymore, for instance if uploads |
|
1507 | + // have been disabled, or vocabularies removed... |
|
1508 | + if (isset($extra[$key])) { |
|
1509 | 1509 | $extra[$key]['weight'] = $value; |
1510 | - } |
|
1510 | + } |
|
1511 | 1511 | } |
1512 | 1512 | $type['extra'] = $extra; |
1513 | 1513 | |
1514 | 1514 | $info['content types'][$type_name] = $type; |
1515 | - } |
|
1515 | + } |
|
1516 | 1516 | |
1517 | - cache_set('content_type_info:'. $language->language, $info, content_cache_tablename()); |
|
1517 | + cache_set('content_type_info:'. $language->language, $info, content_cache_tablename()); |
|
1518 | + } |
|
1518 | 1519 | } |
1519 | - } |
|
1520 | - return $info; |
|
1520 | + return $info; |
|
1521 | 1521 | } |
1522 | 1522 | |
1523 | 1523 | /** |
@@ -1525,20 +1525,20 @@ discard block |
||
1525 | 1525 | * React to change in node types |
1526 | 1526 | */ |
1527 | 1527 | function content_node_type($op, $info) { |
1528 | - switch ($op) { |
|
1528 | + switch ($op) { |
|
1529 | 1529 | case 'insert': |
1530 | 1530 | module_load_include('inc', 'content', 'includes/content.crud'); |
1531 | - content_type_create($info); |
|
1532 | - break; |
|
1531 | + content_type_create($info); |
|
1532 | + break; |
|
1533 | 1533 | case 'update': |
1534 | 1534 | module_load_include('inc', 'content', 'includes/content.crud'); |
1535 | - content_type_update($info); |
|
1536 | - break; |
|
1535 | + content_type_update($info); |
|
1536 | + break; |
|
1537 | 1537 | case 'delete': |
1538 | 1538 | module_load_include('inc', 'content', 'includes/content.crud'); |
1539 | - content_type_delete($info); |
|
1540 | - break; |
|
1541 | - } |
|
1539 | + content_type_delete($info); |
|
1540 | + break; |
|
1541 | + } |
|
1542 | 1542 | } |
1543 | 1543 | |
1544 | 1544 | /** |
@@ -1546,19 +1546,19 @@ discard block |
||
1546 | 1546 | * information is changed. |
1547 | 1547 | */ |
1548 | 1548 | function content_clear_type_cache($rebuild_schema = FALSE) { |
1549 | - cache_clear_all('*', content_cache_tablename(), TRUE); |
|
1550 | - _content_type_info(TRUE); |
|
1549 | + cache_clear_all('*', content_cache_tablename(), TRUE); |
|
1550 | + _content_type_info(TRUE); |
|
1551 | 1551 | |
1552 | - // Refresh the schema to pick up new information. |
|
1553 | - if ($rebuild_schema) { |
|
1552 | + // Refresh the schema to pick up new information. |
|
1553 | + if ($rebuild_schema) { |
|
1554 | 1554 | $schema = drupal_get_schema(NULL, TRUE); |
1555 | - } |
|
1555 | + } |
|
1556 | 1556 | |
1557 | - if (module_exists('views')) { |
|
1557 | + if (module_exists('views')) { |
|
1558 | 1558 | // Needed because this can be called from .install files |
1559 | 1559 | module_load_include('module', 'views'); |
1560 | 1560 | views_invalidate_cache(); |
1561 | - } |
|
1561 | + } |
|
1562 | 1562 | } |
1563 | 1563 | |
1564 | 1564 | /** |
@@ -1577,38 +1577,38 @@ discard block |
||
1577 | 1577 | * database column that stores the data. |
1578 | 1578 | */ |
1579 | 1579 | function content_database_info($field) { |
1580 | - $db_info = array(); |
|
1581 | - if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
|
1580 | + $db_info = array(); |
|
1581 | + if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
|
1582 | 1582 | $db_info['table'] = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD); |
1583 | - } |
|
1584 | - else { |
|
1583 | + } |
|
1584 | + else { |
|
1585 | 1585 | $db_info['table'] = _content_tablename($field['type_name'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE); |
1586 | - } |
|
1586 | + } |
|
1587 | 1587 | |
1588 | - $db_info['columns'] = (array) $field['columns']; |
|
1589 | - // Generate column names for this field from generic column names. |
|
1590 | - foreach ($db_info['columns'] as $column_name => $attributes) { |
|
1588 | + $db_info['columns'] = (array) $field['columns']; |
|
1589 | + // Generate column names for this field from generic column names. |
|
1590 | + foreach ($db_info['columns'] as $column_name => $attributes) { |
|
1591 | 1591 | $db_info['columns'][$column_name]['column'] = $field['field_name'] .'_'. $column_name; |
1592 | - } |
|
1592 | + } |
|
1593 | 1593 | |
1594 | - return $db_info; |
|
1594 | + return $db_info; |
|
1595 | 1595 | } |
1596 | 1596 | |
1597 | 1597 | /** |
1598 | 1598 | * Helper function for identifying the storage type for a field. |
1599 | 1599 | */ |
1600 | 1600 | function content_storage_type($field) { |
1601 | - if ($field['multiple'] > 0) { |
|
1601 | + if ($field['multiple'] > 0) { |
|
1602 | 1602 | return CONTENT_DB_STORAGE_PER_FIELD; |
1603 | - } |
|
1604 | - else { |
|
1603 | + } |
|
1604 | + else { |
|
1605 | 1605 | module_load_include('inc', 'content', 'includes/content.crud'); |
1606 | 1606 | $instances = content_field_instance_read(array('field_name' => $field['field_name'])); |
1607 | 1607 | if (count($instances) > 1) { |
1608 | - return CONTENT_DB_STORAGE_PER_FIELD; |
|
1608 | + return CONTENT_DB_STORAGE_PER_FIELD; |
|
1609 | + } |
|
1609 | 1610 | } |
1610 | - } |
|
1611 | - return CONTENT_DB_STORAGE_PER_CONTENT_TYPE; |
|
1611 | + return CONTENT_DB_STORAGE_PER_CONTENT_TYPE; |
|
1612 | 1612 | } |
1613 | 1613 | |
1614 | 1614 | /** |
@@ -1625,20 +1625,20 @@ discard block |
||
1625 | 1625 | * The transposed array. |
1626 | 1626 | */ |
1627 | 1627 | function content_transpose_array_rows_cols($array) { |
1628 | - $result = array(); |
|
1629 | - if (is_array($array)) { |
|
1628 | + $result = array(); |
|
1629 | + if (is_array($array)) { |
|
1630 | 1630 | foreach ($array as $key1 => $value1) { |
1631 | - if (is_array($value1)) { |
|
1631 | + if (is_array($value1)) { |
|
1632 | 1632 | foreach ($value1 as $key2 => $value2) { |
1633 | - if (!isset($result[$key2])) { |
|
1633 | + if (!isset($result[$key2])) { |
|
1634 | 1634 | $result[$key2] = array(); |
1635 | - } |
|
1636 | - $result[$key2][$key1] = $value2; |
|
1635 | + } |
|
1636 | + $result[$key2][$key1] = $value2; |
|
1637 | 1637 | } |
1638 | - } |
|
1638 | + } |
|
1639 | + } |
|
1639 | 1640 | } |
1640 | - } |
|
1641 | - return $result; |
|
1641 | + return $result; |
|
1642 | 1642 | } |
1643 | 1643 | |
1644 | 1644 | /** |
@@ -1650,18 +1650,18 @@ discard block |
||
1650 | 1650 | * A flattened array. |
1651 | 1651 | */ |
1652 | 1652 | function content_array_flatten($array) { |
1653 | - $result = array(); |
|
1654 | - if (is_array($array)) { |
|
1653 | + $result = array(); |
|
1654 | + if (is_array($array)) { |
|
1655 | 1655 | foreach ($array as $key => $value) { |
1656 | - if (is_array($value)) { |
|
1656 | + if (is_array($value)) { |
|
1657 | 1657 | $result += content_array_flatten($value); |
1658 | - } |
|
1659 | - else { |
|
1658 | + } |
|
1659 | + else { |
|
1660 | 1660 | $result[$key] = $value; |
1661 | - } |
|
1661 | + } |
|
1662 | + } |
|
1662 | 1663 | } |
1663 | - } |
|
1664 | - return $result; |
|
1664 | + return $result; |
|
1665 | 1665 | } |
1666 | 1666 | |
1667 | 1667 | /** |
@@ -1680,46 +1680,46 @@ discard block |
||
1680 | 1680 | * when allowed values list is generated using PHP code. |
1681 | 1681 | */ |
1682 | 1682 | function content_allowed_values($field, $flatten = TRUE) { |
1683 | - static $allowed_values; |
|
1683 | + static $allowed_values; |
|
1684 | 1684 | |
1685 | - $cid = $field['field_name'] .':'. ($flatten ? '1' : '0'); |
|
1686 | - if (isset($allowed_values[$cid])) { |
|
1685 | + $cid = $field['field_name'] .':'. ($flatten ? '1' : '0'); |
|
1686 | + if (isset($allowed_values[$cid])) { |
|
1687 | 1687 | return $allowed_values[$cid]; |
1688 | - } |
|
1688 | + } |
|
1689 | 1689 | |
1690 | - $allowed_values[$cid] = array(); |
|
1690 | + $allowed_values[$cid] = array(); |
|
1691 | 1691 | |
1692 | - if (isset($field['allowed_values_php'])) { |
|
1692 | + if (isset($field['allowed_values_php'])) { |
|
1693 | 1693 | ob_start(); |
1694 | 1694 | $result = eval($field['allowed_values_php']); |
1695 | 1695 | if (is_array($result)) { |
1696 | - if ($flatten) { |
|
1696 | + if ($flatten) { |
|
1697 | 1697 | $result = content_array_flatten($result); |
1698 | - } |
|
1699 | - $allowed_values[$cid] = $result; |
|
1698 | + } |
|
1699 | + $allowed_values[$cid] = $result; |
|
1700 | 1700 | } |
1701 | 1701 | ob_end_clean(); |
1702 | - } |
|
1702 | + } |
|
1703 | 1703 | |
1704 | - if (empty($allowed_values[$cid]) && isset($field['allowed_values'])) { |
|
1704 | + if (empty($allowed_values[$cid]) && isset($field['allowed_values'])) { |
|
1705 | 1705 | $list = explode("\n", $field['allowed_values']); |
1706 | 1706 | $list = array_map('trim', $list); |
1707 | 1707 | $list = array_filter($list, 'strlen'); |
1708 | 1708 | foreach ($list as $opt) { |
1709 | - // Sanitize the user input with a permissive filter. |
|
1710 | - $opt = content_filter_xss($opt); |
|
1711 | - if (strpos($opt, '|') !== FALSE) { |
|
1709 | + // Sanitize the user input with a permissive filter. |
|
1710 | + $opt = content_filter_xss($opt); |
|
1711 | + if (strpos($opt, '|') !== FALSE) { |
|
1712 | 1712 | list($key, $value) = explode('|', $opt); |
1713 | 1713 | $allowed_values[$cid][$key] = (isset($value) && $value !=='') ? $value : $key; |
1714 | - } |
|
1715 | - else { |
|
1714 | + } |
|
1715 | + else { |
|
1716 | 1716 | $allowed_values[$cid][$opt] = $opt; |
1717 | - } |
|
1717 | + } |
|
1718 | 1718 | } |
1719 | 1719 | // Allow external modules to translate allowed values list. |
1720 | 1720 | drupal_alter('content_allowed_values', $allowed_values[$cid], $field); |
1721 | - } |
|
1722 | - return $allowed_values[$cid]; |
|
1721 | + } |
|
1722 | + return $allowed_values[$cid]; |
|
1723 | 1723 | } |
1724 | 1724 | |
1725 | 1725 | /** |
@@ -1730,14 +1730,14 @@ discard block |
||
1730 | 1730 | * @see content_handler_filter_many_to_one::allowed_values() |
1731 | 1731 | */ |
1732 | 1732 | function content_allowed_values_filter_html(&$options) { |
1733 | - foreach ($options as $key => $opt) { |
|
1733 | + foreach ($options as $key => $opt) { |
|
1734 | 1734 | if (is_array($opt)) { |
1735 | - content_allowed_values_filter_html($options[$key]); |
|
1735 | + content_allowed_values_filter_html($options[$key]); |
|
1736 | 1736 | } |
1737 | 1737 | else { |
1738 | - $options[$key] = html_entity_decode(strip_tags($opt), ENT_QUOTES); |
|
1738 | + $options[$key] = html_entity_decode(strip_tags($opt), ENT_QUOTES); |
|
1739 | + } |
|
1739 | 1740 | } |
1740 | - } |
|
1741 | 1741 | } |
1742 | 1742 | |
1743 | 1743 | /** |
@@ -1748,21 +1748,21 @@ discard block |
||
1748 | 1748 | * (so check_plain() is not acceptable). |
1749 | 1749 | */ |
1750 | 1750 | function content_filter_xss($string) { |
1751 | - return filter_xss($string, _content_filter_xss_allowed_tags()); |
|
1751 | + return filter_xss($string, _content_filter_xss_allowed_tags()); |
|
1752 | 1752 | } |
1753 | 1753 | |
1754 | 1754 | /** |
1755 | 1755 | * List of tags allowed by content_filter_xss(). |
1756 | 1756 | */ |
1757 | 1757 | function _content_filter_xss_allowed_tags() { |
1758 | - return array('a', 'b', 'big', 'code', 'del', 'em', 'i', 'ins', 'pre', 'q', 'small', 'span', 'strong', 'sub', 'sup', 'tt', 'ol', 'ul', 'li', 'p', 'br', 'img'); |
|
1758 | + return array('a', 'b', 'big', 'code', 'del', 'em', 'i', 'ins', 'pre', 'q', 'small', 'span', 'strong', 'sub', 'sup', 'tt', 'ol', 'ul', 'li', 'p', 'br', 'img'); |
|
1759 | 1759 | } |
1760 | 1760 | |
1761 | 1761 | /** |
1762 | 1762 | * Human-readable list of allowed tags, for display in help texts. |
1763 | 1763 | */ |
1764 | 1764 | function _content_filter_xss_display_allowed_tags() { |
1765 | - return '<'. implode('> <', _content_filter_xss_allowed_tags()) .'>'; |
|
1765 | + return '<'. implode('> <', _content_filter_xss_allowed_tags()) .'>'; |
|
1766 | 1766 | } |
1767 | 1767 | |
1768 | 1768 | /** |
@@ -1790,52 +1790,52 @@ discard block |
||
1790 | 1790 | * functions as necessary. |
1791 | 1791 | */ |
1792 | 1792 | function content_format($field, $item, $formatter_name = 'default', $node = NULL) { |
1793 | - if (!is_array($field)) { |
|
1793 | + if (!is_array($field)) { |
|
1794 | 1794 | $field = content_fields($field); |
1795 | - } |
|
1795 | + } |
|
1796 | 1796 | |
1797 | - if (content_access('view', $field, NULL, $node) && $formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
1797 | + if (content_access('view', $field, NULL, $node) && $formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
1798 | 1798 | $theme = $formatter['module'] .'_formatter_'. $formatter_name; |
1799 | 1799 | |
1800 | 1800 | $element = array( |
1801 | - '#theme' => $theme, |
|
1802 | - '#field_name' => $field['field_name'], |
|
1803 | - '#type_name' => isset($node->type) ? $node->type :'', |
|
1804 | - '#formatter' => $formatter_name, |
|
1805 | - '#node' => $node, |
|
1806 | - '#delta' => isset($item['#delta']) ? $item['#delta'] : NULL, |
|
1801 | + '#theme' => $theme, |
|
1802 | + '#field_name' => $field['field_name'], |
|
1803 | + '#type_name' => isset($node->type) ? $node->type :'', |
|
1804 | + '#formatter' => $formatter_name, |
|
1805 | + '#node' => $node, |
|
1806 | + '#delta' => isset($item['#delta']) ? $item['#delta'] : NULL, |
|
1807 | 1807 | ); |
1808 | 1808 | |
1809 | 1809 | if (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE) { |
1810 | - // Single value formatter. |
|
1810 | + // Single value formatter. |
|
1811 | 1811 | |
1812 | - // hook_field('sanitize') expects an array of items, so we build one. |
|
1813 | - $items = array($item); |
|
1814 | - $function = $field['module'] .'_field'; |
|
1815 | - if (function_exists($function)) { |
|
1812 | + // hook_field('sanitize') expects an array of items, so we build one. |
|
1813 | + $items = array($item); |
|
1814 | + $function = $field['module'] .'_field'; |
|
1815 | + if (function_exists($function)) { |
|
1816 | 1816 | $function('sanitize', $node, $field, $items, FALSE, FALSE); |
1817 | - } |
|
1817 | + } |
|
1818 | 1818 | |
1819 | - $element['#item'] = $items[0]; |
|
1819 | + $element['#item'] = $items[0]; |
|
1820 | 1820 | } |
1821 | 1821 | else { |
1822 | - // Multiple values formatter. |
|
1823 | - $items = $item; |
|
1824 | - $function = $field['module'] .'_field'; |
|
1825 | - if (function_exists($function)) { |
|
1822 | + // Multiple values formatter. |
|
1823 | + $items = $item; |
|
1824 | + $function = $field['module'] .'_field'; |
|
1825 | + if (function_exists($function)) { |
|
1826 | 1826 | $function('sanitize', $node, $field, $items, FALSE, FALSE); |
1827 | - } |
|
1827 | + } |
|
1828 | 1828 | |
1829 | - foreach ($items as $delta => $item) { |
|
1829 | + foreach ($items as $delta => $item) { |
|
1830 | 1830 | $element[$delta] = array( |
1831 | - '#item' => $item, |
|
1832 | - '#weight' => $delta, |
|
1831 | + '#item' => $item, |
|
1832 | + '#weight' => $delta, |
|
1833 | 1833 | ); |
1834 | - } |
|
1834 | + } |
|
1835 | 1835 | } |
1836 | 1836 | |
1837 | 1837 | return theme($theme, $element); |
1838 | - } |
|
1838 | + } |
|
1839 | 1839 | } |
1840 | 1840 | |
1841 | 1841 | /** |
@@ -1851,31 +1851,31 @@ discard block |
||
1851 | 1851 | * - a string tab id: the build modes in this tab. |
1852 | 1852 | */ |
1853 | 1853 | function content_build_modes($selector = NULL) { |
1854 | - static $info; |
|
1854 | + static $info; |
|
1855 | 1855 | |
1856 | - if (!isset($info)) { |
|
1856 | + if (!isset($info)) { |
|
1857 | 1857 | $data = array(); |
1858 | 1858 | foreach (module_implements('content_build_modes') as $module) { |
1859 | - $function = $module .'_content_build_modes'; |
|
1860 | - $data = array_merge($data, (array) $function()); |
|
1859 | + $function = $module .'_content_build_modes'; |
|
1860 | + $data = array_merge($data, (array) $function()); |
|
1861 | 1861 | } |
1862 | 1862 | $flat = array(); |
1863 | 1863 | foreach ($data as $tab) { |
1864 | - // Use the + operator to preserve numeric indexes (core build modes). |
|
1865 | - $flat += (array) $tab['build modes']; |
|
1864 | + // Use the + operator to preserve numeric indexes (core build modes). |
|
1865 | + $flat += (array) $tab['build modes']; |
|
1866 | 1866 | } |
1867 | 1867 | $info = array('tabs' => $data, 'build modes' => $flat); |
1868 | - } |
|
1868 | + } |
|
1869 | 1869 | |
1870 | - if ($selector === '_tabs') { |
|
1870 | + if ($selector === '_tabs') { |
|
1871 | 1871 | return $info['tabs']; |
1872 | - } |
|
1873 | - elseif (isset($selector) && isset($info['tabs'][$selector])) { |
|
1872 | + } |
|
1873 | + elseif (isset($selector) && isset($info['tabs'][$selector])) { |
|
1874 | 1874 | return isset($info['tabs'][$selector]) ? $info['tabs'][$selector]['build modes'] : array(); |
1875 | - } |
|
1876 | - else { |
|
1875 | + } |
|
1876 | + else { |
|
1877 | 1877 | return $info['build modes']; |
1878 | - } |
|
1878 | + } |
|
1879 | 1879 | } |
1880 | 1880 | |
1881 | 1881 | /** |
@@ -1914,60 +1914,60 @@ discard block |
||
1914 | 1914 | * ); |
1915 | 1915 | */ |
1916 | 1916 | function node_content_build_modes() { |
1917 | - return array( |
|
1917 | + return array( |
|
1918 | 1918 | 'basic' => array( |
1919 | - 'title' => t('Basic'), |
|
1920 | - 'build modes' => array( |
|
1919 | + 'title' => t('Basic'), |
|
1920 | + 'build modes' => array( |
|
1921 | 1921 | 'teaser' => array( |
1922 | - 'title' => t('Teaser'), |
|
1923 | - 'views style' => TRUE, |
|
1922 | + 'title' => t('Teaser'), |
|
1923 | + 'views style' => TRUE, |
|
1924 | 1924 | ), |
1925 | 1925 | 'full' => array( |
1926 | - 'title' => t('Full node'), |
|
1927 | - 'views style' => TRUE, |
|
1926 | + 'title' => t('Full node'), |
|
1927 | + 'views style' => TRUE, |
|
1928 | + ), |
|
1928 | 1929 | ), |
1929 | - ), |
|
1930 | 1930 | ), |
1931 | 1931 | 'rss' => array( |
1932 | - 'title' => t('RSS'), |
|
1933 | - 'build modes' => array( |
|
1932 | + 'title' => t('RSS'), |
|
1933 | + 'build modes' => array( |
|
1934 | 1934 | NODE_BUILD_RSS => array( |
1935 | - 'title' => t('RSS'), |
|
1936 | - 'views style' => FALSE, |
|
1935 | + 'title' => t('RSS'), |
|
1936 | + 'views style' => FALSE, |
|
1937 | + ), |
|
1937 | 1938 | ), |
1938 | - ), |
|
1939 | 1939 | ), |
1940 | - ); |
|
1940 | + ); |
|
1941 | 1941 | } |
1942 | 1942 | function search_content_build_modes() { |
1943 | - return array( |
|
1943 | + return array( |
|
1944 | 1944 | 'search' => array( |
1945 | - 'title' => t('Search'), |
|
1946 | - 'build modes' => array( |
|
1945 | + 'title' => t('Search'), |
|
1946 | + 'build modes' => array( |
|
1947 | 1947 | NODE_BUILD_SEARCH_INDEX => array( |
1948 | - 'title' => t('Search Index'), |
|
1949 | - 'views style' => FALSE, |
|
1948 | + 'title' => t('Search Index'), |
|
1949 | + 'views style' => FALSE, |
|
1950 | 1950 | ), |
1951 | 1951 | NODE_BUILD_SEARCH_RESULT => array( |
1952 | - 'title' => t('Search Result'), |
|
1953 | - 'views style' => FALSE, |
|
1952 | + 'title' => t('Search Result'), |
|
1953 | + 'views style' => FALSE, |
|
1954 | + ), |
|
1954 | 1955 | ), |
1955 | - ), |
|
1956 | 1956 | ), |
1957 | - ); |
|
1957 | + ); |
|
1958 | 1958 | } |
1959 | 1959 | function book_content_build_modes() { |
1960 | - return array( |
|
1960 | + return array( |
|
1961 | 1961 | 'print' => array( |
1962 | - 'title' => t('Print'), |
|
1963 | - 'build modes' => array( |
|
1962 | + 'title' => t('Print'), |
|
1963 | + 'build modes' => array( |
|
1964 | 1964 | NODE_BUILD_PRINT => array( |
1965 | - 'title' => t('Print'), |
|
1966 | - 'views style' => TRUE, |
|
1965 | + 'title' => t('Print'), |
|
1966 | + 'views style' => TRUE, |
|
1967 | + ), |
|
1967 | 1968 | ), |
1968 | - ), |
|
1969 | 1969 | ), |
1970 | - ); |
|
1970 | + ); |
|
1971 | 1971 | } |
1972 | 1972 | |
1973 | 1973 | /** |
@@ -1981,19 +1981,19 @@ discard block |
||
1981 | 1981 | * A string containing the generated name for the database table |
1982 | 1982 | */ |
1983 | 1983 | function _content_tablename($name, $storage, $version = NULL) { |
1984 | - if (is_null($version)) { |
|
1984 | + if (is_null($version)) { |
|
1985 | 1985 | $version = variable_get('content_schema_version', 0); |
1986 | - } |
|
1986 | + } |
|
1987 | 1987 | |
1988 | - if ($version < 1003) { |
|
1988 | + if ($version < 1003) { |
|
1989 | 1989 | $version = 0; |
1990 | - } |
|
1991 | - else { |
|
1990 | + } |
|
1991 | + else { |
|
1992 | 1992 | $version = 1003; |
1993 | - } |
|
1993 | + } |
|
1994 | 1994 | |
1995 | - $name = str_replace('-', '_', $name); |
|
1996 | - switch ("$version-$storage") { |
|
1995 | + $name = str_replace('-', '_', $name); |
|
1996 | + switch ("$version-$storage") { |
|
1997 | 1997 | case '0-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
1998 | 1998 | return "node_$name"; |
1999 | 1999 | case '0-'. CONTENT_DB_STORAGE_PER_FIELD : |
@@ -2002,7 +2002,7 @@ discard block |
||
2002 | 2002 | return "content_type_$name"; |
2003 | 2003 | case '1003-'. CONTENT_DB_STORAGE_PER_FIELD : |
2004 | 2004 | return "content_$name"; |
2005 | - } |
|
2005 | + } |
|
2006 | 2006 | } |
2007 | 2007 | |
2008 | 2008 | /** |
@@ -2014,10 +2014,10 @@ discard block |
||
2014 | 2014 | * with 'content_field'. |
2015 | 2015 | */ |
2016 | 2016 | function content_field_tablename($version = NULL) { |
2017 | - if (is_null($version)) { |
|
2017 | + if (is_null($version)) { |
|
2018 | 2018 | $version = variable_get('content_schema_version', 0); |
2019 | - } |
|
2020 | - return $version < 6001 ? 'node_field' : 'content_node_field'; |
|
2019 | + } |
|
2020 | + return $version < 6001 ? 'node_field' : 'content_node_field'; |
|
2021 | 2021 | } |
2022 | 2022 | |
2023 | 2023 | /** |
@@ -2026,10 +2026,10 @@ discard block |
||
2026 | 2026 | * Needed because the table name changes depending on version. |
2027 | 2027 | */ |
2028 | 2028 | function content_instance_tablename($version = NULL) { |
2029 | - if (is_null($version)) { |
|
2029 | + if (is_null($version)) { |
|
2030 | 2030 | $version = variable_get('content_schema_version', 0); |
2031 | - } |
|
2032 | - return $version < 6001 ? 'node_field_instance' : 'content_node_field_instance'; |
|
2031 | + } |
|
2032 | + return $version < 6001 ? 'node_field_instance' : 'content_node_field_instance'; |
|
2033 | 2033 | } |
2034 | 2034 | |
2035 | 2035 | /** |
@@ -2040,12 +2040,12 @@ discard block |
||
2040 | 2040 | * update 6000 runs, so the cache table will be used instead. |
2041 | 2041 | */ |
2042 | 2042 | function content_cache_tablename() { |
2043 | - if (variable_get('content_schema_version', -1) < 6000) { |
|
2043 | + if (variable_get('content_schema_version', -1) < 6000) { |
|
2044 | 2044 | return 'cache'; |
2045 | - } |
|
2046 | - else { |
|
2045 | + } |
|
2046 | + else { |
|
2047 | 2047 | return 'cache_content'; |
2048 | - } |
|
2048 | + } |
|
2049 | 2049 | } |
2050 | 2050 | |
2051 | 2051 | /** |
@@ -2056,45 +2056,45 @@ discard block |
||
2056 | 2056 | * otherwise the function will return the whole thing. |
2057 | 2057 | */ |
2058 | 2058 | function content_table_schema($field = NULL) { |
2059 | - $schema = array( |
|
2059 | + $schema = array( |
|
2060 | 2060 | 'fields' => array( |
2061 | - 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
|
2062 | - 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) |
|
2061 | + 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
|
2062 | + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) |
|
2063 | 2063 | ), |
2064 | 2064 | 'primary key' => array('vid'), |
2065 | 2065 | 'indexes' => array( |
2066 | - 'nid' => array('nid'), |
|
2066 | + 'nid' => array('nid'), |
|
2067 | 2067 | ), |
2068 | - ); |
|
2068 | + ); |
|
2069 | 2069 | |
2070 | - // Add delta column if needed. |
|
2071 | - if (!empty($field['multiple'])) { |
|
2070 | + // Add delta column if needed. |
|
2071 | + if (!empty($field['multiple'])) { |
|
2072 | 2072 | $schema['fields']['delta'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0); |
2073 | 2073 | $schema['primary key'][] = 'delta'; |
2074 | - } |
|
2075 | - $schema['content fields'] = array(); |
|
2074 | + } |
|
2075 | + $schema['content fields'] = array(); |
|
2076 | 2076 | |
2077 | - // Add field columns column if needed. |
|
2078 | - // This function is called from install files where it is not safe |
|
2079 | - // to use content_fields() or content_database_info(), so we |
|
2080 | - // just used the column values stored in the $field. |
|
2081 | - // We also need the schema to include fields from disabled modules |
|
2082 | - // or there will be no way to delete those fields. |
|
2077 | + // Add field columns column if needed. |
|
2078 | + // This function is called from install files where it is not safe |
|
2079 | + // to use content_fields() or content_database_info(), so we |
|
2080 | + // just used the column values stored in the $field. |
|
2081 | + // We also need the schema to include fields from disabled modules |
|
2082 | + // or there will be no way to delete those fields. |
|
2083 | 2083 | |
2084 | - if (!empty($field['columns'])) { |
|
2084 | + if (!empty($field['columns'])) { |
|
2085 | 2085 | foreach ($field['columns'] as $column => $attributes) { |
2086 | - $column_name = $field['field_name'] .'_'. $column; |
|
2087 | - if (isset($attributes['index']) && $attributes['index']) { |
|
2086 | + $column_name = $field['field_name'] .'_'. $column; |
|
2087 | + if (isset($attributes['index']) && $attributes['index']) { |
|
2088 | 2088 | $schema['indexes'][$column_name] = array($column_name); |
2089 | 2089 | unset($attributes['index']); |
2090 | - } |
|
2091 | - unset($attributes['column']); |
|
2092 | - unset($attributes['sortable']); |
|
2093 | - $schema['fields'][$column_name] = $attributes; |
|
2090 | + } |
|
2091 | + unset($attributes['column']); |
|
2092 | + unset($attributes['sortable']); |
|
2093 | + $schema['fields'][$column_name] = $attributes; |
|
2094 | 2094 | } |
2095 | 2095 | $schema['content fields'][] = $field['field_name']; |
2096 | - } |
|
2097 | - return $schema; |
|
2096 | + } |
|
2097 | + return $schema; |
|
2098 | 2098 | } |
2099 | 2099 | |
2100 | 2100 | /** |
@@ -2112,26 +2112,26 @@ discard block |
||
2112 | 2112 | * TRUE if the table exists. Otherwise FALSE. |
2113 | 2113 | */ |
2114 | 2114 | function content_db_index_exists($table, $name) { |
2115 | - global $db_type; |
|
2116 | - if ($db_type == 'mysql' || $db_type == 'mysqli') { |
|
2115 | + global $db_type; |
|
2116 | + if ($db_type == 'mysql' || $db_type == 'mysqli') { |
|
2117 | 2117 | if (version_compare(db_version(), '5.0.3') < 0) { |
2118 | - // Earlier versions of MySQL don't support a WHERE clause for SHOW. |
|
2119 | - $result = db_query('SHOW INDEX FROM {'. $table .'}'); |
|
2120 | - while ($row = db_fetch_array($result)) { |
|
2118 | + // Earlier versions of MySQL don't support a WHERE clause for SHOW. |
|
2119 | + $result = db_query('SHOW INDEX FROM {'. $table .'}'); |
|
2120 | + while ($row = db_fetch_array($result)) { |
|
2121 | 2121 | if ($row['Key_name'] == $name) { |
2122 | - return TRUE; |
|
2122 | + return TRUE; |
|
2123 | + } |
|
2123 | 2124 | } |
2124 | - } |
|
2125 | - return FALSE; |
|
2125 | + return FALSE; |
|
2126 | 2126 | } |
2127 | 2127 | return (bool)db_result(db_query("SHOW INDEX FROM {". $table ."} WHERE key_name = '$name'")); |
2128 | - } |
|
2129 | - elseif ($db_type == 'pgsql') { |
|
2128 | + } |
|
2129 | + elseif ($db_type == 'pgsql') { |
|
2130 | 2130 | // Note that the index names in Schema API for PostgreSQL are prefixed by |
2131 | 2131 | // the table name and suffixed by '_idx'. |
2132 | 2132 | return (bool)db_result(db_query("SELECT COUNT(indexname) FROM pg_indexes WHERE indexname = '{". $table ."}_{$name}_idx'")); |
2133 | - } |
|
2134 | - return FALSE; |
|
2133 | + } |
|
2134 | + return FALSE; |
|
2135 | 2135 | } |
2136 | 2136 | |
2137 | 2137 | /** |
@@ -2152,15 +2152,15 @@ discard block |
||
2152 | 2152 | * |
2153 | 2153 | */ |
2154 | 2154 | function content_callback($entity, $op, $field) { |
2155 | - switch ($entity) { |
|
2155 | + switch ($entity) { |
|
2156 | 2156 | case 'field': |
2157 | 2157 | $info = module_invoke($field['module'], "field_info"); |
2158 | - return isset($info[$field['type']]['callbacks'][$op]) ? $info[$field['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
2158 | + return isset($info[$field['type']]['callbacks'][$op]) ? $info[$field['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
2159 | 2159 | |
2160 | 2160 | case 'widget': |
2161 | 2161 | $info = module_invoke($field['widget']['module'], "widget_info"); |
2162 | - return isset($info[$field['widget']['type']]['callbacks'][$op]) ? $info[$field['widget']['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
2163 | - } |
|
2162 | + return isset($info[$field['widget']['type']]['callbacks'][$op]) ? $info[$field['widget']['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
2163 | + } |
|
2164 | 2164 | } |
2165 | 2165 | |
2166 | 2166 | /** |
@@ -2182,20 +2182,20 @@ discard block |
||
2182 | 2182 | * CONTENT_HANDLE_MODULE - the implementing module handles this operation. |
2183 | 2183 | */ |
2184 | 2184 | function content_handle($entity, $op, $object) { |
2185 | - switch ($entity) { |
|
2185 | + switch ($entity) { |
|
2186 | 2186 | case 'field': |
2187 | 2187 | $info = module_invoke($object['module'], "field_info"); |
2188 | - return isset($info[$object['type']][$op]) ? $info[$object['type']][$op] : CONTENT_HANDLE_CORE; |
|
2188 | + return isset($info[$object['type']][$op]) ? $info[$object['type']][$op] : CONTENT_HANDLE_CORE; |
|
2189 | 2189 | |
2190 | 2190 | case 'widget': |
2191 | 2191 | $info = module_invoke($object['widget']['module'], "widget_info"); |
2192 | - return isset($info[$object['widget']['type']][$op]) ? $info[$object['widget']['type']][$op] : CONTENT_HANDLE_CORE; |
|
2192 | + return isset($info[$object['widget']['type']][$op]) ? $info[$object['widget']['type']][$op] : CONTENT_HANDLE_CORE; |
|
2193 | 2193 | |
2194 | 2194 | case 'formatter': |
2195 | 2195 | // Much simpler, formatters arrays *are* the 'formatter_info' itself. |
2196 | 2196 | // We let content_handle deal with them only for code consistency. |
2197 | 2197 | return isset($object[$op]) ? $object[$op] : CONTENT_HANDLE_CORE; |
2198 | - } |
|
2198 | + } |
|
2199 | 2199 | } |
2200 | 2200 | |
2201 | 2201 | /** |
@@ -2211,22 +2211,22 @@ discard block |
||
2211 | 2211 | * The default value for that field. |
2212 | 2212 | */ |
2213 | 2213 | function content_default_value(&$form, &$form_state, $field, $delta) { |
2214 | - $widget_types = _content_widget_types(); |
|
2215 | - $module = $widget_types[$field['widget']['type']]['module']; |
|
2214 | + $widget_types = _content_widget_types(); |
|
2215 | + $module = $widget_types[$field['widget']['type']]['module']; |
|
2216 | 2216 | |
2217 | - $default_value = array(); |
|
2218 | - if (!empty($field['widget']['default_value_php'])) { |
|
2217 | + $default_value = array(); |
|
2218 | + if (!empty($field['widget']['default_value_php'])) { |
|
2219 | 2219 | ob_start(); |
2220 | 2220 | $result = eval($field['widget']['default_value_php']); |
2221 | 2221 | ob_end_clean(); |
2222 | 2222 | if (is_array($result)) { |
2223 | - $default_value = $result; |
|
2223 | + $default_value = $result; |
|
2224 | + } |
|
2224 | 2225 | } |
2225 | - } |
|
2226 | - elseif (!empty($field['widget']['default_value'])) { |
|
2226 | + elseif (!empty($field['widget']['default_value'])) { |
|
2227 | 2227 | $default_value = $field['widget']['default_value']; |
2228 | - } |
|
2229 | - return (array) $default_value; |
|
2228 | + } |
|
2229 | + return (array) $default_value; |
|
2230 | 2230 | } |
2231 | 2231 | |
2232 | 2232 | /** |
@@ -2247,33 +2247,33 @@ discard block |
||
2247 | 2247 | * FALSE if the operation is denied. |
2248 | 2248 | */ |
2249 | 2249 | function content_access($op, $field, $account = NULL, $node = NULL) { |
2250 | - global $user; |
|
2250 | + global $user; |
|
2251 | 2251 | |
2252 | - if (is_null($account)) { |
|
2252 | + if (is_null($account)) { |
|
2253 | 2253 | $account = $user; |
2254 | - } |
|
2255 | - // Check for valid field data. |
|
2256 | - if (!isset($field['field_name'])) { |
|
2254 | + } |
|
2255 | + // Check for valid field data. |
|
2256 | + if (!isset($field['field_name'])) { |
|
2257 | 2257 | return FALSE; |
2258 | - } |
|
2259 | - $access = module_invoke_all('field_access', $op, $field, $account, $node); |
|
2260 | - foreach ($access as $value) { |
|
2258 | + } |
|
2259 | + $access = module_invoke_all('field_access', $op, $field, $account, $node); |
|
2260 | + foreach ($access as $value) { |
|
2261 | 2261 | if ($value === FALSE) { |
2262 | - return FALSE; |
|
2262 | + return FALSE; |
|
2263 | + } |
|
2263 | 2264 | } |
2264 | - } |
|
2265 | - return TRUE; |
|
2265 | + return TRUE; |
|
2266 | 2266 | } |
2267 | 2267 | |
2268 | - /** |
|
2269 | - * Hide specified fields from the $content variable in node templates. |
|
2270 | - */ |
|
2268 | + /** |
|
2269 | + * Hide specified fields from the $content variable in node templates. |
|
2270 | + */ |
|
2271 | 2271 | function content_field_wrapper_post_render($content, $element) { |
2272 | - $field = content_fields($element['#field_name'], $element['#type_name']); |
|
2273 | - if (theme('content_exclude', $content, $field, $element['#context'])) { |
|
2272 | + $field = content_fields($element['#field_name'], $element['#type_name']); |
|
2273 | + if (theme('content_exclude', $content, $field, $element['#context'])) { |
|
2274 | 2274 | return ''; |
2275 | - } |
|
2276 | - return $content; |
|
2275 | + } |
|
2276 | + return $content; |
|
2277 | 2277 | } |
2278 | 2278 | |
2279 | 2279 | |
@@ -2329,17 +2329,17 @@ discard block |
||
2329 | 2329 | * as set on the Manage fields screen. |
2330 | 2330 | */ |
2331 | 2331 | function theme_content_exclude($content, $object, $context) { |
2332 | - // The field may be missing info for $contexts added by modules |
|
2333 | - // enabled after the field was last edited. |
|
2334 | - if (empty($object['display_settings']) |
|
2332 | + // The field may be missing info for $contexts added by modules |
|
2333 | + // enabled after the field was last edited. |
|
2334 | + if (empty($object['display_settings']) |
|
2335 | 2335 | || empty($object['display_settings'][$context]) |
2336 | 2336 | || !is_array($object['display_settings'][$context]) |
2337 | 2337 | || empty($object['display_settings'][$context]['exclude'])) { |
2338 | 2338 | return FALSE; |
2339 | - } |
|
2340 | - else { |
|
2339 | + } |
|
2340 | + else { |
|
2341 | 2341 | return TRUE; |
2342 | - } |
|
2342 | + } |
|
2343 | 2343 | } |
2344 | 2344 | |
2345 | 2345 | /** |
@@ -2358,48 +2358,48 @@ discard block |
||
2358 | 2358 | * doesn't get called when the theme overrides the template. Bug in theme layer ? |
2359 | 2359 | */ |
2360 | 2360 | function template_preprocess_content_field(&$variables) { |
2361 | - $element = $variables['element']; |
|
2362 | - $field = content_fields($element['#field_name'], $element['#node']->type); |
|
2361 | + $element = $variables['element']; |
|
2362 | + $field = content_fields($element['#field_name'], $element['#node']->type); |
|
2363 | 2363 | |
2364 | - $variables['node'] = $element['#node']; |
|
2365 | - $variables['field'] = $field; |
|
2366 | - $variables['items'] = array(); |
|
2364 | + $variables['node'] = $element['#node']; |
|
2365 | + $variables['field'] = $field; |
|
2366 | + $variables['items'] = array(); |
|
2367 | 2367 | |
2368 | - if ($element['#single']) { |
|
2368 | + if ($element['#single']) { |
|
2369 | 2369 | // Single value formatter. |
2370 | 2370 | foreach (element_children($element['items']) as $delta) { |
2371 | - $variables['items'][$delta] = $element['items'][$delta]['#item']; |
|
2372 | - // Use isset() to avoid undefined index message on #children when field values are empty. |
|
2373 | - $variables['items'][$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
2371 | + $variables['items'][$delta] = $element['items'][$delta]['#item']; |
|
2372 | + // Use isset() to avoid undefined index message on #children when field values are empty. |
|
2373 | + $variables['items'][$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
2374 | 2374 | } |
2375 | - } |
|
2376 | - else { |
|
2375 | + } |
|
2376 | + else { |
|
2377 | 2377 | // Multiple values formatter. |
2378 | 2378 | // We display the 'all items' output as $items[0], as if it was the |
2379 | 2379 | // output of a single valued field. |
2380 | 2380 | // Raw values are still exposed for all items. |
2381 | 2381 | foreach (element_children($element['items']) as $delta) { |
2382 | - $variables['items'][$delta] = $element['items'][$delta]['#item']; |
|
2382 | + $variables['items'][$delta] = $element['items'][$delta]['#item']; |
|
2383 | 2383 | } |
2384 | 2384 | $variables['items'][0]['view'] = $element['items']['#children']; |
2385 | - } |
|
2385 | + } |
|
2386 | 2386 | |
2387 | - $variables['teaser'] = $element['#teaser']; |
|
2388 | - $variables['page'] = $element['#page']; |
|
2387 | + $variables['teaser'] = $element['#teaser']; |
|
2388 | + $variables['page'] = $element['#page']; |
|
2389 | 2389 | |
2390 | - $field_empty = TRUE; |
|
2390 | + $field_empty = TRUE; |
|
2391 | 2391 | |
2392 | - foreach ($variables['items'] as $delta => $item) { |
|
2392 | + foreach ($variables['items'] as $delta => $item) { |
|
2393 | 2393 | if (!isset($item['view']) || (empty($item['view']) && (string)$item['view'] !== '0')) { |
2394 | - $variables['items'][$delta]['empty'] = TRUE; |
|
2394 | + $variables['items'][$delta]['empty'] = TRUE; |
|
2395 | 2395 | } |
2396 | 2396 | else { |
2397 | - $field_empty = FALSE; |
|
2398 | - $variables['items'][$delta]['empty'] = FALSE; |
|
2397 | + $field_empty = FALSE; |
|
2398 | + $variables['items'][$delta]['empty'] = FALSE; |
|
2399 | + } |
|
2399 | 2400 | } |
2400 | - } |
|
2401 | 2401 | |
2402 | - $additions = array( |
|
2402 | + $additions = array( |
|
2403 | 2403 | 'field_type' => $field['type'], |
2404 | 2404 | 'field_name' => $field['field_name'], |
2405 | 2405 | 'field_type_css' => strtr($field['type'], '_', '-'), |
@@ -2408,13 +2408,13 @@ discard block |
||
2408 | 2408 | 'label_display' => $element['#label_display'], |
2409 | 2409 | 'field_empty' => $field_empty, |
2410 | 2410 | 'template_files' => array( |
2411 | - 'content-field', |
|
2412 | - 'content-field-'. $element['#field_name'], |
|
2413 | - 'content-field-'. $element['#node']->type, |
|
2414 | - 'content-field-'. $element['#field_name'] .'-'. $element['#node']->type, |
|
2411 | + 'content-field', |
|
2412 | + 'content-field-'. $element['#field_name'], |
|
2413 | + 'content-field-'. $element['#node']->type, |
|
2414 | + 'content-field-'. $element['#field_name'] .'-'. $element['#node']->type, |
|
2415 | 2415 | ), |
2416 | - ); |
|
2417 | - $variables = array_merge($variables, $additions); |
|
2416 | + ); |
|
2417 | + $variables = array_merge($variables, $additions); |
|
2418 | 2418 | } |
2419 | 2419 | |
2420 | 2420 | /** |
@@ -2425,8 +2425,8 @@ discard block |
||
2425 | 2425 | * - Adds the formatted values in the 'view' key of the items. |
2426 | 2426 | */ |
2427 | 2427 | function content_preprocess_node(&$vars) { |
2428 | - $additions = _content_field_invoke_default('preprocess_node', $vars['node']); |
|
2429 | - $vars = array_merge($vars, $additions); |
|
2428 | + $additions = _content_field_invoke_default('preprocess_node', $vars['node']); |
|
2429 | + $vars = array_merge($vars, $additions); |
|
2430 | 2430 | } |
2431 | 2431 | |
2432 | 2432 | /** |
@@ -2438,10 +2438,10 @@ discard block |
||
2438 | 2438 | * @param $field |
2439 | 2439 | */ |
2440 | 2440 | function content_content_fieldapi($op, $field) { |
2441 | - if (module_exists('devel')) { |
|
2441 | + if (module_exists('devel')) { |
|
2442 | 2442 | //dsm($op); |
2443 | 2443 | //dsm($field); |
2444 | - } |
|
2444 | + } |
|
2445 | 2445 | } |
2446 | 2446 | |
2447 | 2447 | /** |
@@ -2450,115 +2450,115 @@ discard block |
||
2450 | 2450 | * Informations for non-CCK 'node fields' defined in core. |
2451 | 2451 | */ |
2452 | 2452 | function content_content_extra_fields($type_name) { |
2453 | - $type = node_get_types('type', $type_name); |
|
2454 | - $extra = array(); |
|
2453 | + $type = node_get_types('type', $type_name); |
|
2454 | + $extra = array(); |
|
2455 | 2455 | |
2456 | - if ($type->has_title) { |
|
2456 | + if ($type->has_title) { |
|
2457 | 2457 | $extra['title'] = array( |
2458 | - 'label' => $type->title_label, |
|
2459 | - 'description' => t('Node module form.'), |
|
2460 | - 'weight' => -5 |
|
2458 | + 'label' => $type->title_label, |
|
2459 | + 'description' => t('Node module form.'), |
|
2460 | + 'weight' => -5 |
|
2461 | 2461 | ); |
2462 | - } |
|
2463 | - if ($type->has_body) { |
|
2462 | + } |
|
2463 | + if ($type->has_body) { |
|
2464 | 2464 | $extra['body_field'] = array( |
2465 | - 'label' => $type->body_label, |
|
2466 | - 'description' => t('Node module form.'), |
|
2467 | - 'weight' => 0, |
|
2468 | - 'view' => 'body' |
|
2465 | + 'label' => $type->body_label, |
|
2466 | + 'description' => t('Node module form.'), |
|
2467 | + 'weight' => 0, |
|
2468 | + 'view' => 'body' |
|
2469 | 2469 | ); |
2470 | - } |
|
2471 | - $extra['revision_information'] = array( |
|
2470 | + } |
|
2471 | + $extra['revision_information'] = array( |
|
2472 | 2472 | 'label' => t('Revision information'), |
2473 | 2473 | 'description' => t('Node module form.'), |
2474 | 2474 | 'weight' => 20 |
2475 | - ); |
|
2476 | - $extra['author'] = array( |
|
2475 | + ); |
|
2476 | + $extra['author'] = array( |
|
2477 | 2477 | 'label' => t('Authoring information'), |
2478 | 2478 | 'description' => t('Node module form.'), |
2479 | 2479 | 'weight' => 20, |
2480 | - ); |
|
2481 | - $extra['options'] = array( |
|
2480 | + ); |
|
2481 | + $extra['options'] = array( |
|
2482 | 2482 | 'label' => t('Publishing options'), |
2483 | 2483 | 'description' => t('Node module form.'), |
2484 | 2484 | 'weight' => 25, |
2485 | - ); |
|
2486 | - if (module_exists('comment')) { |
|
2485 | + ); |
|
2486 | + if (module_exists('comment')) { |
|
2487 | 2487 | $extra['comment_settings'] = array( |
2488 | - 'label' => t('Comment settings'), |
|
2489 | - 'description' => t('Comment module form.'), |
|
2490 | - 'weight' => 30 |
|
2488 | + 'label' => t('Comment settings'), |
|
2489 | + 'description' => t('Comment module form.'), |
|
2490 | + 'weight' => 30 |
|
2491 | 2491 | ); |
2492 | - } |
|
2493 | - if (module_exists('locale') && variable_get("language_content_type_$type_name", 0)) { |
|
2492 | + } |
|
2493 | + if (module_exists('locale') && variable_get("language_content_type_$type_name", 0)) { |
|
2494 | 2494 | $extra['language'] = array( |
2495 | - 'label' => t('Language'), |
|
2496 | - 'description' => t('Locale module form.'), |
|
2497 | - 'weight' => 0 |
|
2495 | + 'label' => t('Language'), |
|
2496 | + 'description' => t('Locale module form.'), |
|
2497 | + 'weight' => 0 |
|
2498 | 2498 | ); |
2499 | - } |
|
2500 | - if (module_exists('translation') && translation_supported_type($type_name)) { |
|
2499 | + } |
|
2500 | + if (module_exists('translation') && translation_supported_type($type_name)) { |
|
2501 | 2501 | $extra['translation'] = array( |
2502 | - 'label' => t('Translation settings'), |
|
2503 | - 'description' => t('Translation module form.'), |
|
2504 | - 'weight' => 30 |
|
2502 | + 'label' => t('Translation settings'), |
|
2503 | + 'description' => t('Translation module form.'), |
|
2504 | + 'weight' => 30 |
|
2505 | 2505 | ); |
2506 | - } |
|
2507 | - if (module_exists('menu')) { |
|
2506 | + } |
|
2507 | + if (module_exists('menu')) { |
|
2508 | 2508 | $extra['menu'] = array( |
2509 | - 'label' => t('Menu settings'), |
|
2510 | - 'description' => t('Menu module form.'), |
|
2511 | - 'weight' => -2 |
|
2509 | + 'label' => t('Menu settings'), |
|
2510 | + 'description' => t('Menu module form.'), |
|
2511 | + 'weight' => -2 |
|
2512 | 2512 | ); |
2513 | - } |
|
2514 | - if (module_exists('taxonomy') && taxonomy_get_vocabularies($type_name)) { |
|
2513 | + } |
|
2514 | + if (module_exists('taxonomy') && taxonomy_get_vocabularies($type_name)) { |
|
2515 | 2515 | $extra['taxonomy'] = array( |
2516 | - 'label' => t('Taxonomy'), |
|
2517 | - 'description' => t('Taxonomy module form.'), |
|
2518 | - 'weight' => -3 |
|
2516 | + 'label' => t('Taxonomy'), |
|
2517 | + 'description' => t('Taxonomy module form.'), |
|
2518 | + 'weight' => -3 |
|
2519 | 2519 | ); |
2520 | - } |
|
2521 | - if (module_exists('book')) { |
|
2520 | + } |
|
2521 | + if (module_exists('book')) { |
|
2522 | 2522 | $extra['book'] = array( |
2523 | - 'label' => t('Book'), |
|
2524 | - 'description' => t('Book module form.'), |
|
2525 | - 'weight' => 10 |
|
2523 | + 'label' => t('Book'), |
|
2524 | + 'description' => t('Book module form.'), |
|
2525 | + 'weight' => 10 |
|
2526 | 2526 | ); |
2527 | - } |
|
2528 | - if (module_exists('path')) { |
|
2527 | + } |
|
2528 | + if (module_exists('path')) { |
|
2529 | 2529 | $extra['path'] = array( |
2530 | - 'label' => t('Path settings'), |
|
2531 | - 'description' => t('Path module form.'), |
|
2532 | - 'weight' => 30 |
|
2530 | + 'label' => t('Path settings'), |
|
2531 | + 'description' => t('Path module form.'), |
|
2532 | + 'weight' => 30 |
|
2533 | 2533 | ); |
2534 | - } |
|
2535 | - if ($type_name == 'poll' && module_exists('poll')) { |
|
2534 | + } |
|
2535 | + if ($type_name == 'poll' && module_exists('poll')) { |
|
2536 | 2536 | $extra['title'] = array( |
2537 | - 'label' => t('Poll title'), |
|
2538 | - 'description' => t('Poll module title.'), |
|
2539 | - 'weight' => -5 |
|
2537 | + 'label' => t('Poll title'), |
|
2538 | + 'description' => t('Poll module title.'), |
|
2539 | + 'weight' => -5 |
|
2540 | 2540 | ); |
2541 | 2541 | $extra['choice_wrapper'] = array( |
2542 | - 'label' => t('Poll choices'), |
|
2543 | - 'description' => t('Poll module choices.'), |
|
2544 | - 'weight' => -4 |
|
2542 | + 'label' => t('Poll choices'), |
|
2543 | + 'description' => t('Poll module choices.'), |
|
2544 | + 'weight' => -4 |
|
2545 | 2545 | ); |
2546 | 2546 | $extra['settings'] = array( |
2547 | - 'label' => t('Poll settings'), |
|
2548 | - 'description' => t('Poll module settings.'), |
|
2549 | - 'weight' => -3 |
|
2547 | + 'label' => t('Poll settings'), |
|
2548 | + 'description' => t('Poll module settings.'), |
|
2549 | + 'weight' => -3 |
|
2550 | 2550 | ); |
2551 | - } |
|
2552 | - if (module_exists('upload') && variable_get("upload_$type_name", TRUE)) { |
|
2551 | + } |
|
2552 | + if (module_exists('upload') && variable_get("upload_$type_name", TRUE)) { |
|
2553 | 2553 | $extra['attachments'] = array( |
2554 | - 'label' => t('File attachments'), |
|
2555 | - 'description' => t('Upload module form.'), |
|
2556 | - 'weight' => 30, |
|
2557 | - 'view' => 'files' |
|
2554 | + 'label' => t('File attachments'), |
|
2555 | + 'description' => t('Upload module form.'), |
|
2556 | + 'weight' => 30, |
|
2557 | + 'view' => 'files' |
|
2558 | 2558 | ); |
2559 | - } |
|
2559 | + } |
|
2560 | 2560 | |
2561 | - return $extra; |
|
2561 | + return $extra; |
|
2562 | 2562 | } |
2563 | 2563 | |
2564 | 2564 | /** |
@@ -2579,18 +2579,18 @@ discard block |
||
2579 | 2579 | * by content.module. |
2580 | 2580 | */ |
2581 | 2581 | function content_extra_field_weight($type_name, $pseudo_field_name) { |
2582 | - $type = content_types($type_name); |
|
2582 | + $type = content_types($type_name); |
|
2583 | 2583 | |
2584 | - // If we don't have the requested item, this may be because the cached |
|
2585 | - // information for 'extra' fields hasn't been refreshed yet. |
|
2586 | - if (!isset($type['extra'][$pseudo_field_name])) { |
|
2584 | + // If we don't have the requested item, this may be because the cached |
|
2585 | + // information for 'extra' fields hasn't been refreshed yet. |
|
2586 | + if (!isset($type['extra'][$pseudo_field_name])) { |
|
2587 | 2587 | content_clear_type_cache(); |
2588 | 2588 | $type = content_types($type_name); |
2589 | - } |
|
2589 | + } |
|
2590 | 2590 | |
2591 | - if (isset($type['extra'][$pseudo_field_name])) { |
|
2591 | + if (isset($type['extra'][$pseudo_field_name])) { |
|
2592 | 2592 | return $type['extra'][$pseudo_field_name]['weight']; |
2593 | - } |
|
2593 | + } |
|
2594 | 2594 | } |
2595 | 2595 | |
2596 | 2596 | /** |
@@ -2617,68 +2617,68 @@ discard block |
||
2617 | 2617 | * Do we want to eliminate them from the results? |
2618 | 2618 | */ |
2619 | 2619 | function content_max_delta($field_name, $type_name = NULL) { |
2620 | - $fields = content_fields(); |
|
2621 | - $field = $fields[$field_name]; |
|
2620 | + $fields = content_fields(); |
|
2621 | + $field = $fields[$field_name]; |
|
2622 | 2622 | |
2623 | - // Non-multiple value fields don't use the delta column, |
|
2624 | - // but could exist in multiple databases. If any value |
|
2625 | - // exists in any examined table, the max delta will be zero. |
|
2626 | - if (empty($field['multiple'])) { |
|
2623 | + // Non-multiple value fields don't use the delta column, |
|
2624 | + // but could exist in multiple databases. If any value |
|
2625 | + // exists in any examined table, the max delta will be zero. |
|
2626 | + if (empty($field['multiple'])) { |
|
2627 | 2627 | $content_types = content_types(); |
2628 | 2628 | foreach ($content_types as $content_type) { |
2629 | - if (empty($type_name) || $content_type['type'] == $type_name) { |
|
2629 | + if (empty($type_name) || $content_type['type'] == $type_name) { |
|
2630 | 2630 | foreach ($content_type['fields'] as $field) { |
2631 | - $db_info = content_database_info($field); |
|
2632 | - if (db_result(db_query("SELECT COUNT(*) FROM {". $db_info['table'] ."}")) >= 1) { |
|
2631 | + $db_info = content_database_info($field); |
|
2632 | + if (db_result(db_query("SELECT COUNT(*) FROM {". $db_info['table'] ."}")) >= 1) { |
|
2633 | 2633 | return 0; |
2634 | - } |
|
2634 | + } |
|
2635 | + } |
|
2635 | 2636 | } |
2636 | - } |
|
2637 | 2637 | } |
2638 | - } |
|
2639 | - // Multiple value fields always share the same table and use the delta. |
|
2640 | - // If we want to find delta values for a particular type, we join |
|
2641 | - // in the node table to limit the type. |
|
2642 | - else { |
|
2638 | + } |
|
2639 | + // Multiple value fields always share the same table and use the delta. |
|
2640 | + // If we want to find delta values for a particular type, we join |
|
2641 | + // in the node table to limit the type. |
|
2642 | + else { |
|
2643 | 2643 | $db_info = content_database_info($field); |
2644 | 2644 | if (!empty($type_name)) { |
2645 | - $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."} f LEFT JOIN {node} n ON f.vid = n.vid WHERE n.type = '%s'", $type_name)); |
|
2645 | + $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."} f LEFT JOIN {node} n ON f.vid = n.vid WHERE n.type = '%s'", $type_name)); |
|
2646 | 2646 | } |
2647 | 2647 | else { |
2648 | - $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."}")); |
|
2648 | + $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."}")); |
|
2649 | 2649 | } |
2650 | 2650 | if ($delta >= 0) { |
2651 | - return $delta; |
|
2651 | + return $delta; |
|
2652 | 2652 | } |
2653 | - } |
|
2654 | - // If we got this far, there is no data for this field. |
|
2655 | - return NULL; |
|
2653 | + } |
|
2654 | + // If we got this far, there is no data for this field. |
|
2655 | + return NULL; |
|
2656 | 2656 | } |
2657 | 2657 | |
2658 | 2658 | /** |
2659 | 2659 | * Helper function to identify inactive fields. |
2660 | 2660 | */ |
2661 | 2661 | function content_inactive_fields($type_name = NULL) { |
2662 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
2663 | - if (!empty($type_name)) { |
|
2662 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
2663 | + if (!empty($type_name)) { |
|
2664 | 2664 | $param = array('type_name' => $type_name); |
2665 | 2665 | $inactive = array($type_name => array()); |
2666 | - } |
|
2667 | - else { |
|
2666 | + } |
|
2667 | + else { |
|
2668 | 2668 | $param = array(); |
2669 | 2669 | $inactive = array(); |
2670 | - } |
|
2671 | - $all = content_field_instance_read($param, TRUE); |
|
2672 | - $active = array_keys(content_fields()); |
|
2673 | - foreach ($all as $field) { |
|
2670 | + } |
|
2671 | + $all = content_field_instance_read($param, TRUE); |
|
2672 | + $active = array_keys(content_fields()); |
|
2673 | + foreach ($all as $field) { |
|
2674 | 2674 | if (!in_array($field['field_name'], $active)) { |
2675 | - $inactive[$field['type_name']][$field['field_name']] = content_field_instance_expand($field); |
|
2675 | + $inactive[$field['type_name']][$field['field_name']] = content_field_instance_expand($field); |
|
2676 | + } |
|
2676 | 2677 | } |
2677 | - } |
|
2678 | - if (!empty($type_name)) { |
|
2678 | + if (!empty($type_name)) { |
|
2679 | 2679 | return $inactive[$type_name]; |
2680 | - } |
|
2681 | - return $inactive; |
|
2680 | + } |
|
2681 | + return $inactive; |
|
2682 | 2682 | } |
2683 | 2683 | |
2684 | 2684 | |
@@ -2689,21 +2689,21 @@ discard block |
||
2689 | 2689 | * if the fields have other (shared) instances that are still active. |
2690 | 2690 | */ |
2691 | 2691 | function content_inactive_instances($type_name = NULL) { |
2692 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
2693 | - if (!empty($type_name)) { |
|
2692 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
2693 | + if (!empty($type_name)) { |
|
2694 | 2694 | $param = array('type_name' => $type_name); |
2695 | 2695 | $inactive = array($type_name => array()); |
2696 | - } |
|
2697 | - else { |
|
2696 | + } |
|
2697 | + else { |
|
2698 | 2698 | $param = array(); |
2699 | 2699 | $inactive = array(); |
2700 | - } |
|
2701 | - $all = content_field_instance_read($param, TRUE); |
|
2702 | - foreach ($all as $field) { |
|
2700 | + } |
|
2701 | + $all = content_field_instance_read($param, TRUE); |
|
2702 | + foreach ($all as $field) { |
|
2703 | 2703 | $inactive[$field['type_name']][$field['field_name']] = content_field_instance_expand($field); |
2704 | - } |
|
2705 | - if (!empty($type_name)) { |
|
2704 | + } |
|
2705 | + if (!empty($type_name)) { |
|
2706 | 2706 | return $inactive[$type_name]; |
2707 | - } |
|
2708 | - return $inactive; |
|
2707 | + } |
|
2708 | + return $inactive; |
|
2709 | 2709 | } |