@@ -11,68 +11,68 @@ discard block |
||
11 | 11 | * Menu callback; replacement for node_overview_types(). |
12 | 12 | */ |
13 | 13 | function content_types_overview() { |
14 | - $types = node_get_types(); |
|
15 | - $names = node_get_types('names'); |
|
16 | - $header = array(t('Name'), t('Type'), t('Description'), array('data' => t('Operations'), 'colspan' => '4'),); |
|
17 | - $rows = array(); |
|
14 | + $types = node_get_types(); |
|
15 | + $names = node_get_types('names'); |
|
16 | + $header = array(t('Name'), t('Type'), t('Description'), array('data' => t('Operations'), 'colspan' => '4'),); |
|
17 | + $rows = array(); |
|
18 | 18 | |
19 | - foreach ($names as $key => $name) { |
|
19 | + foreach ($names as $key => $name) { |
|
20 | 20 | $type = $types[$key]; |
21 | 21 | if (node_hook($type, 'form')) { |
22 | - $type_url_str = str_replace('_', '-', $type->type); |
|
23 | - $row = array( |
|
22 | + $type_url_str = str_replace('_', '-', $type->type); |
|
23 | + $row = array( |
|
24 | 24 | check_plain($name), |
25 | 25 | check_plain($type->type), |
26 | - ); |
|
27 | - // Make the description smaller |
|
28 | - $row[] = array('data' => filter_xss_admin($type->description), 'class' => 'description'); |
|
29 | - // Set the edit column. |
|
30 | - $row[] = array('data' => l(t('edit'), 'admin/content/node-type/'. $type_url_str)); |
|
31 | - // Set links for managing fields. |
|
32 | - // TODO: a hook to allow other content modules to add more stuff? |
|
33 | - $row[] = array('data' => l(t('manage fields'), 'admin/content/node-type/'. $type_url_str .'/fields')); |
|
34 | - // Set the delete column. |
|
35 | - if ($type->custom) { |
|
26 | + ); |
|
27 | + // Make the description smaller |
|
28 | + $row[] = array('data' => filter_xss_admin($type->description), 'class' => 'description'); |
|
29 | + // Set the edit column. |
|
30 | + $row[] = array('data' => l(t('edit'), 'admin/content/node-type/'. $type_url_str)); |
|
31 | + // Set links for managing fields. |
|
32 | + // TODO: a hook to allow other content modules to add more stuff? |
|
33 | + $row[] = array('data' => l(t('manage fields'), 'admin/content/node-type/'. $type_url_str .'/fields')); |
|
34 | + // Set the delete column. |
|
35 | + if ($type->custom) { |
|
36 | 36 | $row[] = array('data' => l(t('delete'), 'admin/content/node-type/'. $type_url_str .'/delete')); |
37 | - } |
|
38 | - else { |
|
37 | + } |
|
38 | + else { |
|
39 | 39 | $row[] = array('data' => ''); |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - $rows[] = $row; |
|
42 | + $rows[] = $row; |
|
43 | + } |
|
43 | 44 | } |
44 | - } |
|
45 | 45 | |
46 | - // Allow external modules alter the table headers and rows. |
|
47 | - foreach (module_implements('content_types_overview_alter') as $module) { |
|
46 | + // Allow external modules alter the table headers and rows. |
|
47 | + foreach (module_implements('content_types_overview_alter') as $module) { |
|
48 | 48 | $function = $module .'_content_types_overview_alter'; |
49 | 49 | $function($header, $rows); |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - if (empty($rows)) { |
|
52 | + if (empty($rows)) { |
|
53 | 53 | $rows[] = array(array('data' => t('No content types available.'), 'colspan' => '7', 'class' => 'message')); |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - return theme('table', $header, $rows) .theme('content_overview_links'); |
|
56 | + return theme('table', $header, $rows) .theme('content_overview_links'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function theme_content_overview_links() { |
60 | - return '<div class="content-overview-links">'. l(t('» Add a new content type'), 'admin/content/types/add') .'</div>'; |
|
60 | + return '<div class="content-overview-links">'. l(t('» Add a new content type'), 'admin/content/types/add') .'</div>'; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Menu callback; lists all defined fields for quick reference. |
65 | 65 | */ |
66 | 66 | function content_fields_list() { |
67 | - $fields = content_fields(); |
|
68 | - $field_types = _content_field_types(); |
|
67 | + $fields = content_fields(); |
|
68 | + $field_types = _content_field_types(); |
|
69 | 69 | |
70 | - // Sort fields by field name. |
|
71 | - ksort($fields); |
|
70 | + // Sort fields by field name. |
|
71 | + ksort($fields); |
|
72 | 72 | |
73 | - $header = array(t('Field name'), t('Field type'), t('Used in')); |
|
74 | - $rows = array(); |
|
75 | - foreach ($fields as $field) { |
|
73 | + $header = array(t('Field name'), t('Field type'), t('Used in')); |
|
74 | + $rows = array(); |
|
75 | + foreach ($fields as $field) { |
|
76 | 76 | $row = array(); |
77 | 77 | $row[] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field['field_name'])) : $field['field_name']; |
78 | 78 | $row[] = t($field_types[$field['type']]['label']); |
@@ -85,40 +85,40 @@ discard block |
||
85 | 85 | "AND nfi.widget_active = 1 ". |
86 | 86 | "ORDER BY nt.name ASC", $field['field_name']); |
87 | 87 | while ($type = db_fetch_array($result)) { |
88 | - $content_type = content_types($type['type']); |
|
89 | - $types[] = l($type['name'], 'admin/content/node-type/'. $content_type['url_str'] .'/fields'); |
|
88 | + $content_type = content_types($type['type']); |
|
89 | + $types[] = l($type['name'], 'admin/content/node-type/'. $content_type['url_str'] .'/fields'); |
|
90 | 90 | } |
91 | 91 | $row[] = implode(', ', $types); |
92 | 92 | |
93 | 93 | $rows[] = array('data' => $row, 'class' => $field['locked'] ? 'menu-disabled' : ''); |
94 | - } |
|
95 | - if (empty($rows)) { |
|
94 | + } |
|
95 | + if (empty($rows)) { |
|
96 | 96 | $output = t('No fields have been defined for any content type yet.'); |
97 | - } |
|
98 | - else { |
|
97 | + } |
|
98 | + else { |
|
99 | 99 | $output = theme('table', $header, $rows); |
100 | - } |
|
101 | - return $output; |
|
100 | + } |
|
101 | + return $output; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * Helper function to display a message about inactive fields. |
106 | 106 | */ |
107 | 107 | function content_inactive_message($type_name) { |
108 | - $inactive_fields = content_inactive_fields($type_name); |
|
109 | - if (!empty($inactive_fields)) { |
|
108 | + $inactive_fields = content_inactive_fields($type_name); |
|
109 | + if (!empty($inactive_fields)) { |
|
110 | 110 | $field_types = _content_field_types(); |
111 | 111 | $widget_types = _content_widget_types($type_name); |
112 | 112 | drupal_set_message(t('This content type has inactive fields. Inactive fields are not included in lists of available fields until their modules are enabled.'), 'error'); |
113 | 113 | foreach ($inactive_fields as $field_name => $field) { |
114 | - drupal_set_message(t('!field (!field_name) is an inactive !field_type field that uses a !widget_type widget.', array( |
|
115 | - '!field' => $field['widget']['label'], |
|
116 | - '!field_name' => $field['field_name'], |
|
117 | - '!field_type' => array_key_exists($field['type'], $field_types) ? $field_types[$field['type']]['label'] : $field['type'], |
|
118 | - '!widget_type' => array_key_exists($field['widget']['type'], $widget_types) ? $widget_types[$field['widget']['type']]['label'] : $field['widget']['type'], |
|
119 | - ))); |
|
120 | - } |
|
121 | - } |
|
114 | + drupal_set_message(t('!field (!field_name) is an inactive !field_type field that uses a !widget_type widget.', array( |
|
115 | + '!field' => $field['widget']['label'], |
|
116 | + '!field_name' => $field['field_name'], |
|
117 | + '!field_type' => array_key_exists($field['type'], $field_types) ? $field_types[$field['type']]['label'] : $field['type'], |
|
118 | + '!widget_type' => array_key_exists($field['widget']['type'], $widget_types) ? $widget_types[$field['widget']['type']]['label'] : $field['widget']['type'], |
|
119 | + ))); |
|
120 | + } |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -129,34 +129,34 @@ discard block |
||
129 | 129 | */ |
130 | 130 | function content_field_overview_form(&$form_state, $type_name) { |
131 | 131 | |
132 | - content_inactive_message($type_name); |
|
132 | + content_inactive_message($type_name); |
|
133 | 133 | |
134 | - // When displaying the form, make sure the list of fields |
|
135 | - // is up-to-date. |
|
136 | - if (empty($form_state['post'])) { |
|
134 | + // When displaying the form, make sure the list of fields |
|
135 | + // is up-to-date. |
|
136 | + if (empty($form_state['post'])) { |
|
137 | 137 | content_clear_type_cache(); |
138 | - } |
|
138 | + } |
|
139 | 139 | |
140 | - // Gather type information. |
|
141 | - $type = content_types($type_name); |
|
142 | - $fields = $type['fields']; |
|
143 | - $field_types = _content_field_types(); |
|
140 | + // Gather type information. |
|
141 | + $type = content_types($type_name); |
|
142 | + $fields = $type['fields']; |
|
143 | + $field_types = _content_field_types(); |
|
144 | 144 | |
145 | - $extra = $type['extra']; |
|
146 | - $groups = $group_options = $group_types = array(); |
|
147 | - if (module_exists('fieldgroup')) { |
|
145 | + $extra = $type['extra']; |
|
146 | + $groups = $group_options = $group_types = array(); |
|
147 | + if (module_exists('fieldgroup')) { |
|
148 | 148 | $groups = fieldgroup_groups($type['type']); |
149 | 149 | $group_types = fieldgroup_types(); |
150 | 150 | $group_options = _fieldgroup_groups_label($type['type']); |
151 | 151 | // Add the ability to group under the newly created row. |
152 | 152 | $group_options['_add_new_group'] = '_add_new_group'; |
153 | - } |
|
153 | + } |
|
154 | 154 | |
155 | - // Store the default weights as we meet them, to be able to put the |
|
156 | - //'add new' rows after them. |
|
157 | - $weights = array(); |
|
155 | + // Store the default weights as we meet them, to be able to put the |
|
156 | + //'add new' rows after them. |
|
157 | + $weights = array(); |
|
158 | 158 | |
159 | - $form = array( |
|
159 | + $form = array( |
|
160 | 160 | '#tree' => TRUE, |
161 | 161 | '#type_name' => $type['type'], |
162 | 162 | '#fields' => array_keys($fields), |
@@ -164,94 +164,94 @@ discard block |
||
164 | 164 | '#extra' => array_keys($extra), |
165 | 165 | '#field_rows' => array(), |
166 | 166 | '#group_rows' => array(), |
167 | - ); |
|
167 | + ); |
|
168 | 168 | |
169 | - // Fields. |
|
170 | - foreach ($fields as $name => $field) { |
|
169 | + // Fields. |
|
170 | + foreach ($fields as $name => $field) { |
|
171 | 171 | $weight = $field['widget']['weight']; |
172 | 172 | $form[$name] = array( |
173 | - 'label' => array('#value' => check_plain($field['widget']['label'])), |
|
174 | - 'field_name' => array('#value' => $field['field_name']), |
|
175 | - 'type' => array('#value' => t($field_types[$field['type']]['label'])), |
|
176 | - 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'])), |
|
177 | - 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/remove')), |
|
178 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
179 | - 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
180 | - 'prev_parent' => array('#type' => 'hidden', '#value' => ''), |
|
181 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $field['field_name']), |
|
182 | - '#leaf' => TRUE, |
|
183 | - '#row_type' => 'field', |
|
184 | - 'field' => array('#type' => 'value', '#value' => $field), |
|
173 | + 'label' => array('#value' => check_plain($field['widget']['label'])), |
|
174 | + 'field_name' => array('#value' => $field['field_name']), |
|
175 | + 'type' => array('#value' => t($field_types[$field['type']]['label'])), |
|
176 | + 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'])), |
|
177 | + 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/remove')), |
|
178 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
179 | + 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
180 | + 'prev_parent' => array('#type' => 'hidden', '#value' => ''), |
|
181 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $field['field_name']), |
|
182 | + '#leaf' => TRUE, |
|
183 | + '#row_type' => 'field', |
|
184 | + 'field' => array('#type' => 'value', '#value' => $field), |
|
185 | 185 | ); |
186 | 186 | if ($field['locked']) { |
187 | - $form[$name]['configure'] = array('#value' => t('Locked')); |
|
188 | - $form[$name]['remove'] = array(); |
|
189 | - $form[$name]['#disabled_row'] = TRUE; |
|
187 | + $form[$name]['configure'] = array('#value' => t('Locked')); |
|
188 | + $form[$name]['remove'] = array(); |
|
189 | + $form[$name]['#disabled_row'] = TRUE; |
|
190 | 190 | } |
191 | 191 | $form['#field_rows'][] = $name; |
192 | 192 | $weights[] = $weight; |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - // Groups. |
|
196 | - foreach ($groups as $name => $group) { |
|
195 | + // Groups. |
|
196 | + foreach ($groups as $name => $group) { |
|
197 | 197 | $weight = $group['weight']; |
198 | 198 | $form[$name] = array( |
199 | - 'label' => array('#value' => check_plain($group['label'])), |
|
200 | - 'group_name' => array('#value' => $group['group_name']), |
|
201 | - 'group_type' => array('#value' => t($group_types[$group['group_type']])), |
|
202 | - 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'])), |
|
203 | - 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'] .'/remove')), |
|
204 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
205 | - 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
206 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $group['group_name']), |
|
207 | - '#root' => TRUE, |
|
208 | - '#row_type' => 'group', |
|
209 | - 'group' => array('#type' => 'value', '#value' => $group), |
|
199 | + 'label' => array('#value' => check_plain($group['label'])), |
|
200 | + 'group_name' => array('#value' => $group['group_name']), |
|
201 | + 'group_type' => array('#value' => t($group_types[$group['group_type']])), |
|
202 | + 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'])), |
|
203 | + 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'] .'/remove')), |
|
204 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
205 | + 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
206 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $group['group_name']), |
|
207 | + '#root' => TRUE, |
|
208 | + '#row_type' => 'group', |
|
209 | + 'group' => array('#type' => 'value', '#value' => $group), |
|
210 | 210 | ); |
211 | 211 | // Adjust child fields rows. |
212 | 212 | foreach ($group['fields'] as $field_name => $field) { |
213 | - $form[$field_name]['parent']['#default_value'] = $name; |
|
214 | - $form[$field_name]['prev_parent']['#value'] = $name; |
|
213 | + $form[$field_name]['parent']['#default_value'] = $name; |
|
214 | + $form[$field_name]['prev_parent']['#value'] = $name; |
|
215 | 215 | } |
216 | 216 | $form['#group_rows'][] = $name; |
217 | 217 | $weights[] = $weight; |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - // Non-CCK 'fields'. |
|
221 | - foreach ($extra as $name => $label) { |
|
220 | + // Non-CCK 'fields'. |
|
221 | + foreach ($extra as $name => $label) { |
|
222 | 222 | $weight = $extra[$name]['weight']; |
223 | 223 | $form[$name] = array( |
224 | - 'label' => array('#value' => check_plain(t($extra[$name]['label']))), |
|
225 | - 'description' => array('#value' => isset($extra[$name]['description']) ? $extra[$name]['description'] : ''), |
|
226 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
227 | - 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
228 | - 'configure' => array('#value' => isset($extra[$name]['configure']) ? $extra[$name]['configure'] : ''), |
|
229 | - 'remove' => array('#value' => isset($extra[$name]['remove']) ? $extra[$name]['remove'] : ''), |
|
230 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
231 | - '#leaf' => TRUE, |
|
232 | - '#root' => TRUE, |
|
233 | - '#disabled_row' => TRUE, |
|
234 | - '#row_type' => 'extra', |
|
224 | + 'label' => array('#value' => check_plain(t($extra[$name]['label']))), |
|
225 | + 'description' => array('#value' => isset($extra[$name]['description']) ? $extra[$name]['description'] : ''), |
|
226 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
227 | + 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
228 | + 'configure' => array('#value' => isset($extra[$name]['configure']) ? $extra[$name]['configure'] : ''), |
|
229 | + 'remove' => array('#value' => isset($extra[$name]['remove']) ? $extra[$name]['remove'] : ''), |
|
230 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
231 | + '#leaf' => TRUE, |
|
232 | + '#root' => TRUE, |
|
233 | + '#disabled_row' => TRUE, |
|
234 | + '#row_type' => 'extra', |
|
235 | 235 | ); |
236 | 236 | $form['#field_rows'][] = $name; |
237 | 237 | $weights[] = $weight; |
238 | - } |
|
238 | + } |
|
239 | 239 | |
240 | - // Additional row : add new field. |
|
241 | - $weight = max($weights) + 1; |
|
242 | - $field_type_options = content_field_type_options(); |
|
243 | - $widget_type_options = content_widget_type_options(NULL, TRUE); |
|
244 | - if ($field_type_options && $widget_type_options) { |
|
240 | + // Additional row : add new field. |
|
241 | + $weight = max($weights) + 1; |
|
242 | + $field_type_options = content_field_type_options(); |
|
243 | + $widget_type_options = content_widget_type_options(NULL, TRUE); |
|
244 | + if ($field_type_options && $widget_type_options) { |
|
245 | 245 | array_unshift($field_type_options, t('- Select a field type -')); |
246 | 246 | array_unshift($widget_type_options, t('- Select a widget -')); |
247 | 247 | $name = '_add_new_field'; |
248 | 248 | $form[$name] = array( |
249 | - 'label' => array( |
|
249 | + 'label' => array( |
|
250 | 250 | '#type' => 'textfield', |
251 | 251 | '#size' => 15, |
252 | 252 | '#description' => t('Label'), |
253 | - ), |
|
254 | - 'field_name' => array( |
|
253 | + ), |
|
254 | + 'field_name' => array( |
|
255 | 255 | '#type' => 'textfield', |
256 | 256 | // This field should stay LTR even for RTL languages. |
257 | 257 | '#field_prefix' => '<span dir="ltr">field_', |
@@ -262,70 +262,70 @@ discard block |
||
262 | 262 | // prefix which is 6 characters long. |
263 | 263 | '#maxlength' => 26, |
264 | 264 | '#description' => t('Field name (a-z, 0-9, _)'), |
265 | - ), |
|
266 | - 'type' => array( |
|
265 | + ), |
|
266 | + 'type' => array( |
|
267 | 267 | '#type' => 'select', |
268 | 268 | '#options' => $field_type_options, |
269 | 269 | '#description' => theme('advanced_help_topic', 'content', 'fields') . t('Type of data to store.'), |
270 | - ), |
|
271 | - 'widget_type' => array( |
|
270 | + ), |
|
271 | + 'widget_type' => array( |
|
272 | 272 | '#type' => 'select', |
273 | 273 | '#options' => $widget_type_options, |
274 | 274 | '#description' => t('Form element to edit the data.'), |
275 | - ), |
|
276 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
277 | - 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
278 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
279 | - '#leaf' => TRUE, |
|
280 | - '#add_new' => TRUE, |
|
281 | - '#row_type' => 'add_new_field', |
|
275 | + ), |
|
276 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
277 | + 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
278 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
279 | + '#leaf' => TRUE, |
|
280 | + '#add_new' => TRUE, |
|
281 | + '#row_type' => 'add_new_field', |
|
282 | 282 | ); |
283 | 283 | $form['#field_rows'][] = $name; |
284 | - } |
|
284 | + } |
|
285 | 285 | |
286 | - // Additional row : add existing field. |
|
287 | - $existing_field_options = content_existing_field_options($type_name); |
|
288 | - if ($existing_field_options && $widget_type_options) { |
|
286 | + // Additional row : add existing field. |
|
287 | + $existing_field_options = content_existing_field_options($type_name); |
|
288 | + if ($existing_field_options && $widget_type_options) { |
|
289 | 289 | $weight++; |
290 | 290 | array_unshift($existing_field_options, t('- Select an existing field -')); |
291 | 291 | $name = '_add_existing_field'; |
292 | 292 | $form[$name] = array( |
293 | - 'label' => array( |
|
293 | + 'label' => array( |
|
294 | 294 | '#type' => 'textfield', |
295 | 295 | '#size' => 15, |
296 | 296 | '#description' => t('Label'), |
297 | - ), |
|
298 | - 'field_name' => array( |
|
297 | + ), |
|
298 | + 'field_name' => array( |
|
299 | 299 | '#type' => 'select', |
300 | 300 | '#options' => $existing_field_options, |
301 | 301 | '#description' => t('Field to share'), |
302 | - ), |
|
303 | - 'widget_type' => array( |
|
302 | + ), |
|
303 | + 'widget_type' => array( |
|
304 | 304 | '#type' => 'select', |
305 | 305 | '#options' => $widget_type_options, |
306 | 306 | '#description' => t('Form element to edit the data.'), |
307 | - ), |
|
308 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
309 | - 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
310 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
311 | - '#leaf' => TRUE, |
|
312 | - '#add_new' => TRUE, |
|
313 | - '#row_type' => 'add_existing_field', |
|
307 | + ), |
|
308 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
309 | + 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
310 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
311 | + '#leaf' => TRUE, |
|
312 | + '#add_new' => TRUE, |
|
313 | + '#row_type' => 'add_existing_field', |
|
314 | 314 | ); |
315 | 315 | $form['#field_rows'][] = $name; |
316 | - } |
|
316 | + } |
|
317 | 317 | |
318 | - // Additional row : add new group. |
|
319 | - if (!empty($group_types)) { |
|
318 | + // Additional row : add new group. |
|
319 | + if (!empty($group_types)) { |
|
320 | 320 | $weight++; |
321 | 321 | $name = '_add_new_group'; |
322 | 322 | $form[$name] = array( |
323 | - 'label' => array( |
|
323 | + 'label' => array( |
|
324 | 324 | '#type' => 'textfield', |
325 | 325 | '#size' => 15, |
326 | 326 | '#description' => t('Label'), |
327 | - ), |
|
328 | - 'group_name' => array( |
|
327 | + ), |
|
328 | + 'group_name' => array( |
|
329 | 329 | '#type' => 'textfield', |
330 | 330 | // This field should stay LTR even for RTL languages. |
331 | 331 | '#field_prefix' => '<span dir="ltr">group_', |
@@ -336,40 +336,40 @@ discard block |
||
336 | 336 | // prefix which is 6 characters long. |
337 | 337 | '#maxlength' => 26, |
338 | 338 | '#description' => t('Group name (a-z, 0-9, _)'), |
339 | - ), |
|
340 | - 'group_option' => array( |
|
339 | + ), |
|
340 | + 'group_option' => array( |
|
341 | 341 | '#type' => 'hidden', |
342 | 342 | '#value' => '', |
343 | - ), |
|
344 | - 'group_type' => array( |
|
343 | + ), |
|
344 | + 'group_type' => array( |
|
345 | 345 | '#type' => 'hidden', |
346 | 346 | '#value' => 'standard', |
347 | - ), |
|
348 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
349 | - 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
350 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
351 | - '#root' => TRUE, |
|
352 | - '#add_new' => TRUE, |
|
353 | - '#row_type' => 'add_new_group', |
|
347 | + ), |
|
348 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
349 | + 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
350 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
351 | + '#root' => TRUE, |
|
352 | + '#add_new' => TRUE, |
|
353 | + '#row_type' => 'add_new_group', |
|
354 | 354 | ); |
355 | 355 | if (count($group_types) > 1) { |
356 | - $form[$name]['group_type'] = array( |
|
356 | + $form[$name]['group_type'] = array( |
|
357 | 357 | '#type' => 'select', |
358 | 358 | '#description' => t('Type of group.'), |
359 | 359 | '#options' => $group_types, |
360 | 360 | '#default_value' => 'standard', |
361 | - ); |
|
361 | + ); |
|
362 | 362 | } |
363 | 363 | $form['#group_rows'][] = $name; |
364 | - } |
|
364 | + } |
|
365 | 365 | |
366 | - $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); |
|
367 | - return $form; |
|
366 | + $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); |
|
367 | + return $form; |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | function content_field_overview_form_validate($form, &$form_state) { |
371 | - _content_field_overview_form_validate_add_new($form, $form_state); |
|
372 | - _content_field_overview_form_validate_add_existing($form, $form_state); |
|
371 | + _content_field_overview_form_validate_add_new($form, $form_state); |
|
372 | + _content_field_overview_form_validate_add_existing($form, $form_state); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -378,71 +378,71 @@ discard block |
||
378 | 378 | * Validate the 'add new field' row. |
379 | 379 | */ |
380 | 380 | function _content_field_overview_form_validate_add_new($form, &$form_state) { |
381 | - $field = $form_state['values']['_add_new_field']; |
|
381 | + $field = $form_state['values']['_add_new_field']; |
|
382 | 382 | |
383 | - // Validate if any information was provided in the 'add new field' row. |
|
384 | - if (array_filter(array($field['label'], $field['field_name'], $field['type'], $field['widget_type']))) { |
|
383 | + // Validate if any information was provided in the 'add new field' row. |
|
384 | + if (array_filter(array($field['label'], $field['field_name'], $field['type'], $field['widget_type']))) { |
|
385 | 385 | // No label. |
386 | 386 | if (!$field['label']) { |
387 | - form_set_error('_add_new_field][label', t('Add new field: you need to provide a label.')); |
|
387 | + form_set_error('_add_new_field][label', t('Add new field: you need to provide a label.')); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | // No field name. |
391 | 391 | if (!$field['field_name']) { |
392 | - form_set_error('_add_new_field][field_name', t('Add new field: you need to provide a field name.')); |
|
392 | + form_set_error('_add_new_field][field_name', t('Add new field: you need to provide a field name.')); |
|
393 | 393 | } |
394 | 394 | // Field name validation. |
395 | 395 | else { |
396 | - $field_name = $field['field_name']; |
|
396 | + $field_name = $field['field_name']; |
|
397 | 397 | |
398 | - // Add the 'field_' prefix. |
|
399 | - if (substr($field_name, 0, 6) != 'field_') { |
|
398 | + // Add the 'field_' prefix. |
|
399 | + if (substr($field_name, 0, 6) != 'field_') { |
|
400 | 400 | $field_name = 'field_'. $field_name; |
401 | 401 | form_set_value($form['_add_new_field']['field_name'], $field_name, $form_state); |
402 | - } |
|
402 | + } |
|
403 | 403 | |
404 | - // Invalid field name. |
|
405 | - if (!preg_match('!^field_[a-z0-9_]+$!', $field_name)) { |
|
404 | + // Invalid field name. |
|
405 | + if (!preg_match('!^field_[a-z0-9_]+$!', $field_name)) { |
|
406 | 406 | form_set_error('_add_new_field][field_name', t('Add new field: the field name %field_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%field_name' => $field_name))); |
407 | - } |
|
408 | - if (strlen($field_name) > 32) { |
|
407 | + } |
|
408 | + if (strlen($field_name) > 32) { |
|
409 | 409 | form_set_error('_add_new_field][field_name', t('Add new field: the field name %field_name is too long. The name is limited to 32 characters, including the \'field_\' prefix.', array('%field_name' => $field_name))); |
410 | - } |
|
411 | - // A field named 'field_instance' would cause a tablename clash with {content_field_instance} |
|
412 | - if ($field_name == 'field_instance') { |
|
410 | + } |
|
411 | + // A field named 'field_instance' would cause a tablename clash with {content_field_instance} |
|
412 | + if ($field_name == 'field_instance') { |
|
413 | 413 | form_set_error('_add_new_field][field_name', t("Add new field: the name 'field_instance' is a reserved name.")); |
414 | - } |
|
415 | - |
|
416 | - // Field name already exists. |
|
417 | - // We need to check inactive fields as well, so we can't use content_fields(). |
|
418 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
419 | - $fields = content_field_instance_read(array(), TRUE); |
|
420 | - $used = FALSE; |
|
421 | - foreach ($fields as $existing_field) { |
|
414 | + } |
|
415 | + |
|
416 | + // Field name already exists. |
|
417 | + // We need to check inactive fields as well, so we can't use content_fields(). |
|
418 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
419 | + $fields = content_field_instance_read(array(), TRUE); |
|
420 | + $used = FALSE; |
|
421 | + foreach ($fields as $existing_field) { |
|
422 | 422 | $used |= ($existing_field['field_name'] == $field_name); |
423 | - } |
|
424 | - if ($used) { |
|
423 | + } |
|
424 | + if ($used) { |
|
425 | 425 | form_set_error('_add_new_field][field_name', t('Add new field: the field name %field_name already exists.', array('%field_name' => $field_name))); |
426 | - } |
|
426 | + } |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | // No field type. |
430 | 430 | if (!$field['type']) { |
431 | - form_set_error('_add_new_field][type', t('Add new field: you need to select a field type.')); |
|
431 | + form_set_error('_add_new_field][type', t('Add new field: you need to select a field type.')); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | // No widget type. |
435 | 435 | if (!$field['widget_type']) { |
436 | - form_set_error('_add_new_field][widget_type', t('Add new field: you need to select a widget.')); |
|
436 | + form_set_error('_add_new_field][widget_type', t('Add new field: you need to select a widget.')); |
|
437 | 437 | } |
438 | 438 | // Wrong widget type. |
439 | 439 | elseif ($field['type']) { |
440 | - $widget_types = content_widget_type_options($field['type']); |
|
441 | - if (!isset($widget_types[$field['widget_type']])) { |
|
440 | + $widget_types = content_widget_type_options($field['type']); |
|
441 | + if (!isset($widget_types[$field['widget_type']])) { |
|
442 | 442 | form_set_error('_add_new_field][widget_type', t('Add new field: invalid widget.')); |
443 | - } |
|
443 | + } |
|
444 | + } |
|
444 | 445 | } |
445 | - } |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | /** |
@@ -451,112 +451,112 @@ discard block |
||
451 | 451 | * Validate the 'add existing field' row. |
452 | 452 | */ |
453 | 453 | function _content_field_overview_form_validate_add_existing($form, &$form_state) { |
454 | - // The form element might be absent if no existing fields can be added to |
|
455 | - // this content type |
|
456 | - if (isset($form_state['values']['_add_existing_field'])) { |
|
454 | + // The form element might be absent if no existing fields can be added to |
|
455 | + // this content type |
|
456 | + if (isset($form_state['values']['_add_existing_field'])) { |
|
457 | 457 | $field = $form_state['values']['_add_existing_field']; |
458 | 458 | |
459 | 459 | // Validate if any information was provided in the 'add existing field' row. |
460 | 460 | if (array_filter(array($field['label'], $field['field_name'], $field['widget_type']))) { |
461 | - // No label. |
|
462 | - if (!$field['label']) { |
|
461 | + // No label. |
|
462 | + if (!$field['label']) { |
|
463 | 463 | form_set_error('_add_existing_field][label', t('Add existing field: you need to provide a label.')); |
464 | - } |
|
464 | + } |
|
465 | 465 | |
466 | - // No existing field. |
|
467 | - if (!$field['field_name']) { |
|
466 | + // No existing field. |
|
467 | + if (!$field['field_name']) { |
|
468 | 468 | form_set_error('_add_existing_field][field_name', t('Add existing field: you need to select a field.')); |
469 | - } |
|
469 | + } |
|
470 | 470 | |
471 | - // No widget type. |
|
472 | - if (!$field['widget_type']) { |
|
471 | + // No widget type. |
|
472 | + if (!$field['widget_type']) { |
|
473 | 473 | form_set_error('_add_existing_field][widget_type', t('Add existing field: you need to select a widget.')); |
474 | - } |
|
475 | - // Wrong widget type. |
|
476 | - elseif ($field['field_name'] && ($existing_field = content_fields($field['field_name']))) { |
|
474 | + } |
|
475 | + // Wrong widget type. |
|
476 | + elseif ($field['field_name'] && ($existing_field = content_fields($field['field_name']))) { |
|
477 | 477 | $widget_types = content_widget_type_options($existing_field['type']); |
478 | 478 | if (!isset($widget_types[$field['widget_type']])) { |
479 | - form_set_error('_add_existing_field][widget_type', t('Add existing field: invalid widget.')); |
|
479 | + form_set_error('_add_existing_field][widget_type', t('Add existing field: invalid widget.')); |
|
480 | + } |
|
480 | 481 | } |
481 | - } |
|
482 | 482 | } |
483 | - } |
|
483 | + } |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | function content_field_overview_form_submit($form, &$form_state) { |
487 | - $form_values = $form_state['values']; |
|
487 | + $form_values = $form_state['values']; |
|
488 | 488 | |
489 | - $type_name = $form['#type_name']; |
|
490 | - $type = content_types($type_name); |
|
489 | + $type_name = $form['#type_name']; |
|
490 | + $type = content_types($type_name); |
|
491 | 491 | |
492 | - // Update field weights. |
|
493 | - $extra = array(); |
|
494 | - foreach ($form_values as $key => $values) { |
|
492 | + // Update field weights. |
|
493 | + $extra = array(); |
|
494 | + foreach ($form_values as $key => $values) { |
|
495 | 495 | // Groups are handled in fieldgroup_content_overview_form_submit(). |
496 | 496 | if (in_array($key, $form['#fields'])) { |
497 | - db_query("UPDATE {". content_instance_tablename() ."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", |
|
497 | + db_query("UPDATE {". content_instance_tablename() ."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", |
|
498 | 498 | $values['weight'], $type_name, $key); |
499 | 499 | } |
500 | 500 | elseif (in_array($key, $form['#extra'])) { |
501 | - $extra[$key] = $values['weight']; |
|
501 | + $extra[$key] = $values['weight']; |
|
502 | + } |
|
502 | 503 | } |
503 | - } |
|
504 | 504 | |
505 | - if ($extra) { |
|
505 | + if ($extra) { |
|
506 | 506 | variable_set('content_extra_weights_'. $type_name, $extra); |
507 | - } |
|
508 | - else { |
|
507 | + } |
|
508 | + else { |
|
509 | 509 | variable_del('content_extra_weights_'. $type_name); |
510 | - } |
|
510 | + } |
|
511 | 511 | |
512 | - content_clear_type_cache(); |
|
512 | + content_clear_type_cache(); |
|
513 | 513 | |
514 | - $destinations = array(); |
|
514 | + $destinations = array(); |
|
515 | 515 | |
516 | - // Create new field. |
|
517 | - if (!empty($form_values['_add_new_field']['field_name'])) { |
|
516 | + // Create new field. |
|
517 | + if (!empty($form_values['_add_new_field']['field_name'])) { |
|
518 | 518 | $field = $form_values['_add_new_field']; |
519 | 519 | $field['type_name'] = $type_name; |
520 | 520 | |
521 | 521 | module_load_include('inc', 'content', 'includes/content.crud'); |
522 | 522 | if (content_field_instance_create($field)) { |
523 | - // Store new field information for fieldgroup submit handler. |
|
524 | - $form_state['fields_added']['_add_new_field'] = $field['field_name']; |
|
525 | - $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
|
523 | + // Store new field information for fieldgroup submit handler. |
|
524 | + $form_state['fields_added']['_add_new_field'] = $field['field_name']; |
|
525 | + $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
|
526 | 526 | } |
527 | 527 | else { |
528 | - drupal_set_message(t('There was a problem creating field %label.', array( |
|
528 | + drupal_set_message(t('There was a problem creating field %label.', array( |
|
529 | 529 | '%label' => $field['label']))); |
530 | 530 | } |
531 | - } |
|
531 | + } |
|
532 | 532 | |
533 | - // Add existing field. |
|
534 | - if (!empty($form_values['_add_existing_field']['field_name'])) { |
|
533 | + // Add existing field. |
|
534 | + if (!empty($form_values['_add_existing_field']['field_name'])) { |
|
535 | 535 | $field = $form_values['_add_existing_field']; |
536 | 536 | $field['type_name'] = $type_name; |
537 | 537 | $existing_field = content_fields($field['field_name']); |
538 | 538 | |
539 | 539 | if ($existing_field['locked']) { |
540 | - drupal_set_message(t('The field %label cannot be added to a content type because it is locked.', array('%label' => $field['field_name']))); |
|
540 | + drupal_set_message(t('The field %label cannot be added to a content type because it is locked.', array('%label' => $field['field_name']))); |
|
541 | 541 | } |
542 | 542 | else { |
543 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
544 | - if (content_field_instance_create($field)) { |
|
543 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
544 | + if (content_field_instance_create($field)) { |
|
545 | 545 | // Store new field information for fieldgroup submit handler. |
546 | 546 | $form_state['fields_added']['_add_existing_field'] = $field['field_name']; |
547 | 547 | $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
548 | - } |
|
549 | - else { |
|
548 | + } |
|
549 | + else { |
|
550 | 550 | drupal_set_message(t('There was a problem adding field %label.', array('%label' => $field['field_name']))); |
551 | - } |
|
551 | + } |
|
552 | + } |
|
552 | 553 | } |
553 | - } |
|
554 | 554 | |
555 | - if ($destinations) { |
|
555 | + if ($destinations) { |
|
556 | 556 | $destinations[] = urldecode(substr(drupal_get_destination(), 12)); |
557 | 557 | unset($_REQUEST['destination']); |
558 | 558 | $form_state['redirect'] = content_get_destinations($destinations); |
559 | - } |
|
559 | + } |
|
560 | 560 | |
561 | 561 | } |
562 | 562 | |
@@ -567,173 +567,173 @@ discard block |
||
567 | 567 | * and how the field labels should be rendered. |
568 | 568 | */ |
569 | 569 | function content_display_overview_form(&$form_state, $type_name, $contexts_selector = 'basic') { |
570 | - content_inactive_message($type_name); |
|
570 | + content_inactive_message($type_name); |
|
571 | 571 | |
572 | - // Gather type information. |
|
573 | - $type = content_types($type_name); |
|
574 | - $field_types = _content_field_types(); |
|
575 | - $fields = $type['fields']; |
|
572 | + // Gather type information. |
|
573 | + $type = content_types($type_name); |
|
574 | + $field_types = _content_field_types(); |
|
575 | + $fields = $type['fields']; |
|
576 | 576 | |
577 | - $groups = array(); |
|
578 | - if (module_exists('fieldgroup')) { |
|
577 | + $groups = array(); |
|
578 | + if (module_exists('fieldgroup')) { |
|
579 | 579 | $groups = fieldgroup_groups($type['type']); |
580 | - } |
|
581 | - $contexts = content_build_modes($contexts_selector); |
|
580 | + } |
|
581 | + $contexts = content_build_modes($contexts_selector); |
|
582 | 582 | |
583 | - $form = array( |
|
583 | + $form = array( |
|
584 | 584 | '#tree' => TRUE, |
585 | 585 | '#type_name' => $type['type'], |
586 | 586 | '#fields' => array_keys($fields), |
587 | 587 | '#groups' => array_keys($groups), |
588 | 588 | '#contexts' => $contexts_selector, |
589 | - ); |
|
589 | + ); |
|
590 | 590 | |
591 | - if (empty($fields)) { |
|
591 | + if (empty($fields)) { |
|
592 | 592 | drupal_set_message(t('There are no fields configured for this content type. You can add new fields on the <a href="@link">Manage fields</a> page.', array( |
593 | - '@link' => url('admin/content/node-type/'. $type['url_str'] .'/fields'))), 'warning'); |
|
593 | + '@link' => url('admin/content/node-type/'. $type['url_str'] .'/fields'))), 'warning'); |
|
594 | 594 | return $form; |
595 | - } |
|
595 | + } |
|
596 | 596 | |
597 | - // Fields. |
|
598 | - $label_options = array( |
|
597 | + // Fields. |
|
598 | + $label_options = array( |
|
599 | 599 | 'above' => t('Above'), |
600 | 600 | 'inline' => t('Inline'), |
601 | 601 | 'hidden' => t('<Hidden>'), |
602 | - ); |
|
603 | - foreach ($fields as $name => $field) { |
|
602 | + ); |
|
603 | + foreach ($fields as $name => $field) { |
|
604 | 604 | $field_type = $field_types[$field['type']]; |
605 | 605 | $defaults = $field['display_settings']; |
606 | 606 | $weight = $field['widget']['weight']; |
607 | 607 | |
608 | 608 | $form[$name] = array( |
609 | - 'human_name' => array('#value' => check_plain($field['widget']['label'])), |
|
610 | - 'weight' => array('#type' => 'value', '#value' => $weight), |
|
611 | - 'parent' => array('#type' => 'value', '#value' => ''), |
|
609 | + 'human_name' => array('#value' => check_plain($field['widget']['label'])), |
|
610 | + 'weight' => array('#type' => 'value', '#value' => $weight), |
|
611 | + 'parent' => array('#type' => 'value', '#value' => ''), |
|
612 | 612 | ); |
613 | 613 | |
614 | 614 | // Label |
615 | 615 | if ($contexts_selector == 'basic') { |
616 | - $form[$name]['label']['format'] = array( |
|
616 | + $form[$name]['label']['format'] = array( |
|
617 | 617 | '#type' => 'select', |
618 | 618 | '#options' => $label_options, |
619 | 619 | '#default_value' => isset($defaults['label']['format']) ? $defaults['label']['format'] : 'above', |
620 | - ); |
|
620 | + ); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | // Formatters. |
624 | 624 | $options = array(); |
625 | 625 | foreach ($field_type['formatters'] as $formatter_name => $formatter_info) { |
626 | - $options[$formatter_name] = $formatter_info['label']; |
|
626 | + $options[$formatter_name] = $formatter_info['label']; |
|
627 | 627 | } |
628 | 628 | $options['hidden'] = t('<Hidden>'); |
629 | 629 | |
630 | 630 | foreach ($contexts as $key => $value) { |
631 | - $form[$name][$key]['format'] = array( |
|
631 | + $form[$name][$key]['format'] = array( |
|
632 | 632 | '#type' => 'select', |
633 | 633 | '#options' => $options, |
634 | 634 | '#default_value' => isset($defaults[$key]['format']) ? $defaults[$key]['format'] : 'default', |
635 | - ); |
|
636 | - // exclude from $content |
|
637 | - $form[$name][$key]['exclude'] = array( |
|
635 | + ); |
|
636 | + // exclude from $content |
|
637 | + $form[$name][$key]['exclude'] = array( |
|
638 | 638 | '#type' => 'checkbox', |
639 | 639 | '#options' => array(0 => t('Include'), 1 => t('Exclude')), |
640 | 640 | '#default_value' => isset($defaults[$key]['exclude']) ? $defaults[$key]['exclude'] : 0, |
641 | - ); |
|
641 | + ); |
|
642 | + } |
|
642 | 643 | } |
643 | - } |
|
644 | 644 | |
645 | - // Groups. |
|
646 | - $label_options = array( |
|
645 | + // Groups. |
|
646 | + $label_options = array( |
|
647 | 647 | 'above' => t('Above'), |
648 | 648 | 'hidden' => t('<Hidden>'), |
649 | - ); |
|
650 | - $options = array( |
|
649 | + ); |
|
650 | + $options = array( |
|
651 | 651 | 'no_style' => t('no styling'), |
652 | 652 | 'simple' => t('simple'), |
653 | 653 | 'fieldset' => t('fieldset'), |
654 | 654 | 'fieldset_collapsible' => t('fieldset - collapsible'), |
655 | 655 | 'fieldset_collapsed' => t('fieldset - collapsed'), |
656 | 656 | 'hidden' => t('<Hidden>'), |
657 | - ); |
|
658 | - foreach ($groups as $name => $group) { |
|
657 | + ); |
|
658 | + foreach ($groups as $name => $group) { |
|
659 | 659 | $defaults = $group['settings']['display']; |
660 | 660 | $weight = $group['weight']; |
661 | 661 | |
662 | 662 | $form[$name] = array( |
663 | - 'human_name' => array('#value' => check_plain($group['label'])), |
|
664 | - 'weight' => array('#type' => 'value', '#value' => $weight), |
|
663 | + 'human_name' => array('#value' => check_plain($group['label'])), |
|
664 | + 'weight' => array('#type' => 'value', '#value' => $weight), |
|
665 | 665 | ); |
666 | 666 | if ($contexts_selector == 'basic') { |
667 | - $form[$name]['label'] = array( |
|
667 | + $form[$name]['label'] = array( |
|
668 | 668 | '#type' => 'select', |
669 | 669 | '#options' => $label_options, |
670 | 670 | '#default_value' => isset($defaults['label']) ? $defaults['label'] : 'above', |
671 | - ); |
|
671 | + ); |
|
672 | 672 | } |
673 | 673 | foreach ($contexts as $key => $title) { |
674 | - $form[$name][$key]['format'] = array( |
|
674 | + $form[$name][$key]['format'] = array( |
|
675 | 675 | '#type' => 'select', |
676 | 676 | '#options' => $options, |
677 | 677 | '#default_value' => isset($defaults[$key]['format']) ? $defaults[$key]['format'] : 'fieldset', |
678 | - ); |
|
679 | - // exclude in $content |
|
680 | - $form[$name][$key]['exclude'] = array( |
|
678 | + ); |
|
679 | + // exclude in $content |
|
680 | + $form[$name][$key]['exclude'] = array( |
|
681 | 681 | '#type' => 'checkbox', |
682 | 682 | '#options' => array(0 => t('Include'), 1 => t('Exclude')), |
683 | 683 | '#default_value' => isset($defaults[$key]['exclude']) ? $defaults[$key]['exclude'] : 0, |
684 | - ); |
|
684 | + ); |
|
685 | 685 | } |
686 | 686 | foreach ($group['fields'] as $field_name => $field) { |
687 | - $form[$field_name]['parent']['#value'] = $name; |
|
687 | + $form[$field_name]['parent']['#value'] = $name; |
|
688 | + } |
|
688 | 689 | } |
689 | - } |
|
690 | 690 | |
691 | - $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); |
|
692 | - return $form; |
|
691 | + $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); |
|
692 | + return $form; |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | /** |
696 | 696 | * Submit handler for the display overview form. |
697 | 697 | */ |
698 | 698 | function content_display_overview_form_submit($form, &$form_state) { |
699 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
700 | - $form_values = $form_state['values']; |
|
701 | - foreach ($form_values as $key => $values) { |
|
699 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
700 | + $form_values = $form_state['values']; |
|
701 | + foreach ($form_values as $key => $values) { |
|
702 | 702 | // Groups are handled in fieldgroup_display_overview_form_submit(). |
703 | 703 | if (in_array($key, $form['#fields'])) { |
704 | - $field = content_fields($key, $form['#type_name']); |
|
705 | - // We have some numeric keys here, so we can't use array_merge. |
|
706 | - $field['display_settings'] = $values + $field['display_settings']; |
|
707 | - content_field_instance_update($field, FALSE); |
|
704 | + $field = content_fields($key, $form['#type_name']); |
|
705 | + // We have some numeric keys here, so we can't use array_merge. |
|
706 | + $field['display_settings'] = $values + $field['display_settings']; |
|
707 | + content_field_instance_update($field, FALSE); |
|
708 | + } |
|
708 | 709 | } |
709 | - } |
|
710 | 710 | |
711 | - // Clear caches and rebuild menu. |
|
712 | - content_clear_type_cache(TRUE); |
|
713 | - menu_rebuild(); |
|
711 | + // Clear caches and rebuild menu. |
|
712 | + content_clear_type_cache(TRUE); |
|
713 | + menu_rebuild(); |
|
714 | 714 | |
715 | - drupal_set_message(t('Your settings have been saved.')); |
|
715 | + drupal_set_message(t('Your settings have been saved.')); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
719 | 719 | * Return an array of field_type options. |
720 | 720 | */ |
721 | 721 | function content_field_type_options() { |
722 | - static $options; |
|
722 | + static $options; |
|
723 | 723 | |
724 | - if (!isset($options)) { |
|
724 | + if (!isset($options)) { |
|
725 | 725 | $options = array(); |
726 | 726 | $field_types = _content_field_types(); |
727 | 727 | $field_type_options = array(); |
728 | 728 | foreach ($field_types as $field_type_name => $field_type) { |
729 | - // skip field types which have no widget types. |
|
730 | - if (content_widget_type_options($field_type_name)) { |
|
729 | + // skip field types which have no widget types. |
|
730 | + if (content_widget_type_options($field_type_name)) { |
|
731 | 731 | $options[$field_type_name] = t($field_type['label']); |
732 | - } |
|
732 | + } |
|
733 | 733 | } |
734 | 734 | asort($options); |
735 | - } |
|
736 | - return $options; |
|
735 | + } |
|
736 | + return $options; |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
@@ -743,320 +743,320 @@ discard block |
||
743 | 743 | * all widget types, keyed by field type human name |
744 | 744 | */ |
745 | 745 | function content_widget_type_options($field_type = NULL, $by_label = FALSE) { |
746 | - static $options; |
|
746 | + static $options; |
|
747 | 747 | |
748 | - if (!isset($options)) { |
|
748 | + if (!isset($options)) { |
|
749 | 749 | $options = array(); |
750 | 750 | foreach (_content_widget_types() as $widget_type_name => $widget_type) { |
751 | - foreach ($widget_type['field types'] as $widget_field_type) { |
|
751 | + foreach ($widget_type['field types'] as $widget_field_type) { |
|
752 | 752 | $options[$widget_field_type][$widget_type_name] = t($widget_type['label']); |
753 | - } |
|
753 | + } |
|
754 | + } |
|
754 | 755 | } |
755 | - } |
|
756 | 756 | |
757 | - if ($field_type) { |
|
757 | + if ($field_type) { |
|
758 | 758 | return !empty($options[$field_type]) ? $options[$field_type] : array(); |
759 | - } |
|
760 | - elseif ($by_label) { |
|
759 | + } |
|
760 | + elseif ($by_label) { |
|
761 | 761 | $field_types = _content_field_types(); |
762 | 762 | $options_by_label = array(); |
763 | 763 | foreach ($options as $field_type => $widgets) { |
764 | - $options_by_label[t($field_types[$field_type]['label'])] = $widgets; |
|
764 | + $options_by_label[t($field_types[$field_type]['label'])] = $widgets; |
|
765 | 765 | } |
766 | 766 | return $options_by_label; |
767 | - } |
|
768 | - else { |
|
767 | + } |
|
768 | + else { |
|
769 | 769 | return $options; |
770 | - } |
|
770 | + } |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
774 | 774 | * Return an array of existing field to be added to a node type. |
775 | 775 | */ |
776 | 776 | function content_existing_field_options($type_name) { |
777 | - $type = content_types($type_name); |
|
778 | - $fields = content_fields(); |
|
779 | - $field_types = _content_field_types(); |
|
777 | + $type = content_types($type_name); |
|
778 | + $fields = content_fields(); |
|
779 | + $field_types = _content_field_types(); |
|
780 | 780 | |
781 | - $options = array(); |
|
782 | - foreach ($fields as $field) { |
|
781 | + $options = array(); |
|
782 | + foreach ($fields as $field) { |
|
783 | 783 | if (!isset($type['fields'][$field['field_name']]) && !$field['locked']) { |
784 | - $field_type = $field_types[$field['type']]; |
|
785 | - $text = t('@type: @field (@label)', array('@type' => t($field_type['label']), '@label' => t($field['widget']['label']), '@field' => $field['field_name'])); |
|
786 | - $options[$field['field_name']] = (drupal_strlen($text) > 80) ? truncate_utf8($text, 77) . '...' : $text; |
|
784 | + $field_type = $field_types[$field['type']]; |
|
785 | + $text = t('@type: @field (@label)', array('@type' => t($field_type['label']), '@label' => t($field['widget']['label']), '@field' => $field['field_name'])); |
|
786 | + $options[$field['field_name']] = (drupal_strlen($text) > 80) ? truncate_utf8($text, 77) . '...' : $text; |
|
787 | 787 | } |
788 | - } |
|
789 | - // Sort the list by type, then by field name, then by label. |
|
790 | - asort($options); |
|
788 | + } |
|
789 | + // Sort the list by type, then by field name, then by label. |
|
790 | + asort($options); |
|
791 | 791 | |
792 | - return $options; |
|
792 | + return $options; |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
796 | 796 | * A form element for selecting field, widget, and label. |
797 | 797 | */ |
798 | 798 | function content_field_basic_form(&$form_state, $form_values) { |
799 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
799 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
800 | 800 | |
801 | - $type_name = $form_values['type_name']; |
|
802 | - $type = content_types($form_values['type_name']); |
|
803 | - $field_name = $form_values['field_name']; |
|
804 | - $field_type = $form_values['type']; |
|
805 | - $label = $form_values['label']; |
|
801 | + $type_name = $form_values['type_name']; |
|
802 | + $type = content_types($form_values['type_name']); |
|
803 | + $field_name = $form_values['field_name']; |
|
804 | + $field_type = $form_values['type']; |
|
805 | + $label = $form_values['label']; |
|
806 | 806 | |
807 | - $form = array(); |
|
807 | + $form = array(); |
|
808 | 808 | |
809 | - $form['basic'] = array( |
|
809 | + $form['basic'] = array( |
|
810 | 810 | '#type' => 'fieldset', |
811 | 811 | '#title' => t('Edit basic information'), |
812 | - ); |
|
813 | - $form['basic']['field_name'] = array( |
|
812 | + ); |
|
813 | + $form['basic']['field_name'] = array( |
|
814 | 814 | '#title' => t('Field name'), |
815 | 815 | '#type' => 'textfield', |
816 | 816 | '#value' => $field_name, |
817 | 817 | '#description' => t("The machine-readable name of the field. This name cannot be changed."), |
818 | 818 | '#disabled' => TRUE, |
819 | - ); |
|
820 | - $form['basic']['label'] = array( |
|
819 | + ); |
|
820 | + $form['basic']['label'] = array( |
|
821 | 821 | '#type' => 'textfield', |
822 | 822 | '#title' => t('Label'), |
823 | 823 | '#default_value' => $label, |
824 | 824 | '#required' => TRUE, |
825 | 825 | '#description' => t('A human-readable name to be used as the label for this field in the %type content type.', array('%type' => $type['name'])), |
826 | - ); |
|
827 | - $form['basic']['type'] = array( |
|
826 | + ); |
|
827 | + $form['basic']['type'] = array( |
|
828 | 828 | '#type' => 'select', |
829 | 829 | '#title' => t('Field type'), |
830 | 830 | '#options' => content_field_type_options(), |
831 | 831 | '#default_value' => $field_type, |
832 | 832 | '#description' => t('The type of data you would like to store in the database with this field. This option cannot be changed.'), |
833 | 833 | '#disabled' => TRUE, |
834 | - ); |
|
835 | - $form['basic']['widget_type'] = array( |
|
834 | + ); |
|
835 | + $form['basic']['widget_type'] = array( |
|
836 | 836 | '#type' => 'select', |
837 | 837 | '#title' => t('Widget type'), |
838 | 838 | '#required' => TRUE, |
839 | 839 | '#options' => content_widget_type_options($field_type), |
840 | 840 | '#default_value' => $form_values['widget_type'], |
841 | 841 | '#description' => t('The type of form element you would like to present to the user when creating this field in the %type content type.', array('%type' => $type['name'])), |
842 | - ); |
|
842 | + ); |
|
843 | 843 | |
844 | - $form['type_name'] = array( |
|
844 | + $form['type_name'] = array( |
|
845 | 845 | '#type' => 'value', |
846 | 846 | '#value' => $type_name, |
847 | - ); |
|
847 | + ); |
|
848 | 848 | |
849 | - $form['submit'] = array( |
|
849 | + $form['submit'] = array( |
|
850 | 850 | '#type' => 'submit', |
851 | 851 | '#value' => t('Continue'), |
852 | - ); |
|
852 | + ); |
|
853 | 853 | |
854 | - $form['#validate'] = array(); |
|
855 | - $form['#submit'] = array('content_field_basic_form_submit'); |
|
854 | + $form['#validate'] = array(); |
|
855 | + $form['#submit'] = array('content_field_basic_form_submit'); |
|
856 | 856 | |
857 | - return $form; |
|
857 | + return $form; |
|
858 | 858 | } |
859 | 859 | |
860 | 860 | /** |
861 | 861 | * Create a new field for a content type. |
862 | 862 | */ |
863 | 863 | function content_field_basic_form_submit($form, &$form_state) { |
864 | - $form_values = $form_state['values']; |
|
864 | + $form_values = $form_state['values']; |
|
865 | 865 | |
866 | - $label = $form_values['label']; |
|
866 | + $label = $form_values['label']; |
|
867 | 867 | |
868 | - // Set the right module information |
|
869 | - $field_types = _content_field_types(); |
|
870 | - $widget_types = _content_widget_types(); |
|
871 | - $form_values['module'] = $field_types[$form_values['type']]['module']; |
|
872 | - $form_values['widget_module'] = $widget_types[$form_values['widget_type']]['module']; |
|
868 | + // Set the right module information |
|
869 | + $field_types = _content_field_types(); |
|
870 | + $widget_types = _content_widget_types(); |
|
871 | + $form_values['module'] = $field_types[$form_values['type']]['module']; |
|
872 | + $form_values['widget_module'] = $widget_types[$form_values['widget_type']]['module']; |
|
873 | 873 | |
874 | - // Make sure we retain previous values and only over-write changed values. |
|
875 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
876 | - $instances = content_field_instance_read(array('field_name' => $form_values['field_name'], 'type_name' => $form_values['type_name'])); |
|
877 | - $field = array_merge(content_field_instance_collapse($instances[0]), $form_values); |
|
878 | - if (content_field_instance_update($field)) { |
|
874 | + // Make sure we retain previous values and only over-write changed values. |
|
875 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
876 | + $instances = content_field_instance_read(array('field_name' => $form_values['field_name'], 'type_name' => $form_values['type_name'])); |
|
877 | + $field = array_merge(content_field_instance_collapse($instances[0]), $form_values); |
|
878 | + if (content_field_instance_update($field)) { |
|
879 | 879 | drupal_set_message(t('Updated basic settings for field %label.', array( |
880 | - '%label' => $label))); |
|
881 | - } |
|
882 | - else { |
|
880 | + '%label' => $label))); |
|
881 | + } |
|
882 | + else { |
|
883 | 883 | drupal_set_message(t('There was a problem updating the basic settings for field %label.', array( |
884 | - '%label' => $label))); |
|
885 | - } |
|
884 | + '%label' => $label))); |
|
885 | + } |
|
886 | 886 | |
887 | - $type = content_types($form_values['type_name']); |
|
888 | - $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $form_values['field_name']; |
|
889 | - $form_state['rebuild'] = FALSE; |
|
887 | + $type = content_types($form_values['type_name']); |
|
888 | + $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $form_values['field_name']; |
|
889 | + $form_state['rebuild'] = FALSE; |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
893 | 893 | * Menu callback; present a form for removing a field from a content type. |
894 | 894 | */ |
895 | 895 | function content_field_remove_form(&$form_state, $type_name, $field_name) { |
896 | - $type = content_types($type_name); |
|
897 | - $field = $type['fields'][$field_name]; |
|
896 | + $type = content_types($type_name); |
|
897 | + $field = $type['fields'][$field_name]; |
|
898 | 898 | |
899 | - $form = array(); |
|
900 | - $form['type_name'] = array( |
|
899 | + $form = array(); |
|
900 | + $form['type_name'] = array( |
|
901 | 901 | '#type' => 'value', |
902 | 902 | '#value' => $type_name, |
903 | - ); |
|
904 | - $form['field_name'] = array( |
|
903 | + ); |
|
904 | + $form['field_name'] = array( |
|
905 | 905 | '#type' => 'value', |
906 | 906 | '#value' => $field_name, |
907 | - ); |
|
907 | + ); |
|
908 | 908 | |
909 | - $output = confirm_form($form, |
|
909 | + $output = confirm_form($form, |
|
910 | 910 | t('Are you sure you want to remove the field %field?', array('%field' => $field['widget']['label'])), |
911 | 911 | 'admin/content/node-type/'. $type['url_str'] .'/fields', |
912 | 912 | t('If you have any content left in this field, it will be lost. This action cannot be undone.'), |
913 | 913 | t('Remove'), t('Cancel'), |
914 | 914 | 'confirm' |
915 | - ); |
|
915 | + ); |
|
916 | 916 | |
917 | - if ($field['locked']) { |
|
917 | + if ($field['locked']) { |
|
918 | 918 | unset($output['actions']['submit']); |
919 | 919 | $output['description']['#value'] = t('This field is <strong>locked</strong> and cannot be removed.'); |
920 | - } |
|
920 | + } |
|
921 | 921 | |
922 | - return $output; |
|
922 | + return $output; |
|
923 | 923 | } |
924 | 924 | |
925 | 925 | /** |
926 | 926 | * Remove a field from a content type. |
927 | 927 | */ |
928 | 928 | function content_field_remove_form_submit($form, &$form_state) { |
929 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
930 | - $form_values = $form_state['values']; |
|
929 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
930 | + $form_values = $form_state['values']; |
|
931 | 931 | |
932 | - $type = content_types($form_values['type_name']); |
|
933 | - $field = $type['fields'][$form_values['field_name']]; |
|
934 | - if ($field['locked']) { |
|
932 | + $type = content_types($form_values['type_name']); |
|
933 | + $field = $type['fields'][$form_values['field_name']]; |
|
934 | + if ($field['locked']) { |
|
935 | 935 | return; |
936 | - } |
|
936 | + } |
|
937 | 937 | |
938 | - if ($type && $field && $form_values['confirm']) { |
|
938 | + if ($type && $field && $form_values['confirm']) { |
|
939 | 939 | if (content_field_instance_delete($form_values['field_name'], $form_values['type_name'])) { |
940 | - drupal_set_message(t('Removed field %field from %type.', array( |
|
940 | + drupal_set_message(t('Removed field %field from %type.', array( |
|
941 | 941 | '%field' => $field['widget']['label'], |
942 | 942 | '%type' => $type['name']))); |
943 | 943 | } |
944 | 944 | else { |
945 | - drupal_set_message(t('There was a problem deleting %field from %type.', array( |
|
945 | + drupal_set_message(t('There was a problem deleting %field from %type.', array( |
|
946 | 946 | '%field' => $field['widget']['label'], |
947 | 947 | '%type' => $type['name']))); |
948 | 948 | } |
949 | 949 | $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; |
950 | - } |
|
950 | + } |
|
951 | 951 | } |
952 | 952 | |
953 | 953 | /** |
954 | 954 | * Menu callback; presents the field editing page. |
955 | 955 | */ |
956 | 956 | function content_field_edit_form(&$form_state, $type_name, $field_name) { |
957 | - $output = ''; |
|
958 | - $type = content_types($type_name); |
|
959 | - $field = $type['fields'][$field_name]; |
|
957 | + $output = ''; |
|
958 | + $type = content_types($type_name); |
|
959 | + $field = $type['fields'][$field_name]; |
|
960 | 960 | |
961 | - if ($field['locked']) { |
|
961 | + if ($field['locked']) { |
|
962 | 962 | $output = array(); |
963 | 963 | $output['locked'] = array( |
964 | - '#value' => t('The field %field is locked and cannot be edited.', array('%field' => $field['widget']['label'])), |
|
964 | + '#value' => t('The field %field is locked and cannot be edited.', array('%field' => $field['widget']['label'])), |
|
965 | 965 | ); |
966 | 966 | return $output; |
967 | - } |
|
967 | + } |
|
968 | 968 | |
969 | - $field_types = _content_field_types(); |
|
970 | - $field_type = $field_types[$field['type']]; |
|
971 | - $widget_types = _content_widget_types(); |
|
972 | - $widget_type = $widget_types[$field['widget']['type']]; |
|
969 | + $field_types = _content_field_types(); |
|
970 | + $field_type = $field_types[$field['type']]; |
|
971 | + $widget_types = _content_widget_types(); |
|
972 | + $widget_type = $widget_types[$field['widget']['type']]; |
|
973 | 973 | |
974 | - $title = isset($field['widget']['label']) ? $field['widget']['label'] : $field['field_name']; |
|
975 | - drupal_set_title(check_plain($title)); |
|
974 | + $title = isset($field['widget']['label']) ? $field['widget']['label'] : $field['field_name']; |
|
975 | + drupal_set_title(check_plain($title)); |
|
976 | 976 | |
977 | - // See if we need to change the widget type or label. |
|
978 | - if (isset($form_state['change_basic'])) { |
|
977 | + // See if we need to change the widget type or label. |
|
978 | + if (isset($form_state['change_basic'])) { |
|
979 | 979 | module_load_include('inc', 'content', 'includes/content.crud'); |
980 | 980 | $field_values = content_field_instance_collapse($field); |
981 | 981 | return content_field_basic_form($form_state, $field_values); |
982 | - } |
|
982 | + } |
|
983 | 983 | |
984 | - $add_new_sequence = isset($_REQUEST['destinations']); |
|
984 | + $add_new_sequence = isset($_REQUEST['destinations']); |
|
985 | 985 | |
986 | - // Remove menu tabs when we are in an 'add new' sequence. |
|
987 | - if ($add_new_sequence) { |
|
986 | + // Remove menu tabs when we are in an 'add new' sequence. |
|
987 | + if ($add_new_sequence) { |
|
988 | 988 | menu_set_item(NULL, menu_get_item('node')); |
989 | - } |
|
989 | + } |
|
990 | 990 | |
991 | - $form = array(); |
|
992 | - $form['#field'] = $field; |
|
993 | - $form['#type'] = $type; |
|
991 | + $form = array(); |
|
992 | + $form['#field'] = $field; |
|
993 | + $form['#type'] = $type; |
|
994 | 994 | |
995 | - // Basic iformation : hide when we are in an 'add new' sequence. |
|
996 | - $form['basic'] = array( |
|
995 | + // Basic iformation : hide when we are in an 'add new' sequence. |
|
996 | + $form['basic'] = array( |
|
997 | 997 | '#type' => 'fieldset', |
998 | 998 | '#title' => t('%type basic information', array('%type' => $type['name'])), |
999 | 999 | '#access' => !$add_new_sequence, |
1000 | - ); |
|
1001 | - $form['basic']['label'] = array( |
|
1000 | + ); |
|
1001 | + $form['basic']['label'] = array( |
|
1002 | 1002 | '#type' => 'textfield', |
1003 | 1003 | '#title' => t('Label'), |
1004 | 1004 | '#value' => $field['widget']['label'], |
1005 | 1005 | '#disabled' => TRUE, |
1006 | - ); |
|
1007 | - $form['basic']['field_name'] = array( |
|
1006 | + ); |
|
1007 | + $form['basic']['field_name'] = array( |
|
1008 | 1008 | '#type' => 'hidden', |
1009 | 1009 | '#title' => t('Field name'), |
1010 | 1010 | '#value' => $field['field_name'], |
1011 | 1011 | '#disabled' => TRUE, |
1012 | - ); |
|
1013 | - $form['basic']['type'] = array( |
|
1012 | + ); |
|
1013 | + $form['basic']['type'] = array( |
|
1014 | 1014 | '#type' => 'hidden', |
1015 | 1015 | '#title' => t('Field type'), |
1016 | 1016 | '#value' => $field['type'], |
1017 | 1017 | '#disabled' => TRUE, |
1018 | - ); |
|
1019 | - $widget_options = content_widget_type_options($field['type']); |
|
1020 | - $form['basic']['widget_type'] = array( |
|
1018 | + ); |
|
1019 | + $widget_options = content_widget_type_options($field['type']); |
|
1020 | + $form['basic']['widget_type'] = array( |
|
1021 | 1021 | '#type' => 'select', |
1022 | 1022 | '#title' => t('Widget type'), |
1023 | 1023 | '#options' => $widget_options, |
1024 | 1024 | '#default_value' => $field['widget']['type'] ? $field['widget']['type'] : key($widget_options), |
1025 | 1025 | '#disabled' => TRUE, |
1026 | - ); |
|
1027 | - $form['basic']['change'] = array( |
|
1026 | + ); |
|
1027 | + $form['basic']['change'] = array( |
|
1028 | 1028 | '#type' => 'submit', |
1029 | 1029 | '#value' => t('Change basic information'), |
1030 | 1030 | '#submit' => array('content_field_edit_form_submit_update_basic'), |
1031 | - ); |
|
1031 | + ); |
|
1032 | 1032 | |
1033 | - $form['widget'] = array( |
|
1033 | + $form['widget'] = array( |
|
1034 | 1034 | '#type' => 'fieldset', |
1035 | 1035 | '#title' => t('%type settings', array('%type' => $type['name'])), |
1036 | 1036 | '#description' => t('These settings apply only to the %field field as it appears in the %type content type.', array( |
1037 | - '%field' => $field['widget']['label'], |
|
1038 | - '%type' => $type['name'])), |
|
1039 | - ); |
|
1040 | - $form['widget']['weight'] = array( |
|
1037 | + '%field' => $field['widget']['label'], |
|
1038 | + '%type' => $type['name'])), |
|
1039 | + ); |
|
1040 | + $form['widget']['weight'] = array( |
|
1041 | 1041 | '#type' => 'hidden', |
1042 | 1042 | '#default_value' => $field['widget']['weight'], |
1043 | - ); |
|
1043 | + ); |
|
1044 | 1044 | |
1045 | - $additions = (array) module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget']); |
|
1046 | - drupal_alter('widget_settings', $additions, 'form', $field['widget']); |
|
1047 | - $form['widget'] = array_merge($form['widget'], $additions); |
|
1045 | + $additions = (array) module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget']); |
|
1046 | + drupal_alter('widget_settings', $additions, 'form', $field['widget']); |
|
1047 | + $form['widget'] = array_merge($form['widget'], $additions); |
|
1048 | 1048 | |
1049 | - $form['widget']['description'] = array( |
|
1049 | + $form['widget']['description'] = array( |
|
1050 | 1050 | '#type' => 'textarea', |
1051 | 1051 | '#title' => t('Help text'), |
1052 | 1052 | '#default_value' => $field['widget']['description'], |
1053 | 1053 | '#rows' => 5, |
1054 | 1054 | '#description' => t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => _content_filter_xss_display_allowed_tags())), |
1055 | 1055 | '#required' => FALSE, |
1056 | - ); |
|
1056 | + ); |
|
1057 | 1057 | |
1058 | - // Add handling for default value if not provided by field. |
|
1059 | - if (content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) { |
|
1058 | + // Add handling for default value if not provided by field. |
|
1059 | + if (content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) { |
|
1060 | 1060 | |
1061 | 1061 | // Store the original default value for use in programmed forms. |
1062 | 1062 | // Set '#default_value' instead of '#value' so programmed values |
@@ -1064,22 +1064,22 @@ discard block |
||
1064 | 1064 | $default_value = isset($field['widget']['default_value']) ? $field['widget']['default_value'] : array(); |
1065 | 1065 | $default_value_php = isset($field['widget']['default_value_php']) ? $field['widget']['default_value_php'] : ''; |
1066 | 1066 | $form['widget']['default_value'] = array( |
1067 | - '#type' => 'value', |
|
1068 | - '#default_value' => $default_value, |
|
1067 | + '#type' => 'value', |
|
1068 | + '#default_value' => $default_value, |
|
1069 | 1069 | ); |
1070 | 1070 | $form['widget']['default_value_php'] = array( |
1071 | - '#type' => 'value', |
|
1072 | - '#default_value' => $default_value_php, |
|
1071 | + '#type' => 'value', |
|
1072 | + '#default_value' => $default_value_php, |
|
1073 | 1073 | ); |
1074 | 1074 | |
1075 | 1075 | // We can't tell at the time we build the form if this is a programmed |
1076 | 1076 | // form or not, so we always end up adding the default value widget |
1077 | 1077 | // even if we won't use it. |
1078 | 1078 | $form['widget']['default_value_fieldset'] = array( |
1079 | - '#type' => 'fieldset', |
|
1080 | - '#title' => t('Default value'), |
|
1081 | - '#collapsible' => TRUE, |
|
1082 | - '#collapsed' => TRUE, |
|
1079 | + '#type' => 'fieldset', |
|
1080 | + '#title' => t('Default value'), |
|
1081 | + '#collapsible' => TRUE, |
|
1082 | + '#collapsed' => TRUE, |
|
1083 | 1083 | ); |
1084 | 1084 | |
1085 | 1085 | // Default value widget. |
@@ -1097,264 +1097,264 @@ discard block |
||
1097 | 1097 | |
1098 | 1098 | // Advanced: PHP code. |
1099 | 1099 | $form['widget']['default_value_fieldset']['advanced_options'] = array( |
1100 | - '#type' => 'fieldset', |
|
1101 | - '#title' => t('PHP code'), |
|
1102 | - '#collapsible' => TRUE, |
|
1103 | - '#collapsed' => empty($field['widget']['default_value_php']), |
|
1100 | + '#type' => 'fieldset', |
|
1101 | + '#title' => t('PHP code'), |
|
1102 | + '#collapsible' => TRUE, |
|
1103 | + '#collapsed' => empty($field['widget']['default_value_php']), |
|
1104 | 1104 | ); |
1105 | 1105 | |
1106 | 1106 | if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
1107 | - $db_info = content_database_info($field); |
|
1108 | - $columns = array_keys($db_info['columns']); |
|
1109 | - foreach ($columns as $key => $column) { |
|
1107 | + $db_info = content_database_info($field); |
|
1108 | + $columns = array_keys($db_info['columns']); |
|
1109 | + foreach ($columns as $key => $column) { |
|
1110 | 1110 | $columns[$key] = t("'@column' => value for @column", array('@column' => $column)); |
1111 | - } |
|
1112 | - $sample = t("return array(\n 0 => array(@columns),\n // You'll usually want to stop here. Provide more values\n // if you want your 'default value' to be multi-valued:\n 1 => array(@columns),\n 2 => ...\n);", array('@columns' => implode(', ', $columns))); |
|
1111 | + } |
|
1112 | + $sample = t("return array(\n 0 => array(@columns),\n // You'll usually want to stop here. Provide more values\n // if you want your 'default value' to be multi-valued:\n 1 => array(@columns),\n 2 => ...\n);", array('@columns' => implode(', ', $columns))); |
|
1113 | 1113 | |
1114 | - $form['widget']['default_value_fieldset']['advanced_options']['default_value_php'] = array( |
|
1114 | + $form['widget']['default_value_fieldset']['advanced_options']['default_value_php'] = array( |
|
1115 | 1115 | '#type' => 'textarea', |
1116 | 1116 | '#title' => t('Code'), |
1117 | 1117 | '#default_value' => isset($field['widget']['default_value_php']) ? $field['widget']['default_value_php'] : '', |
1118 | 1118 | '#rows' => 6, |
1119 | 1119 | '#tree' => TRUE, |
1120 | 1120 | '#description' => t('Advanced usage only: PHP code that returns a default value. Should not include <?php ?> delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format: <pre>!sample</pre>To figure out the expected format, you can use the <em>devel load</em> tab provided by <a href="@link_devel">devel module</a> on a %type content page.', array( |
1121 | - '!sample' => $sample, |
|
1122 | - '@link_devel' => 'http://www.drupal.org/project/devel', |
|
1123 | - '%type' => $type_name)), |
|
1124 | - ); |
|
1121 | + '!sample' => $sample, |
|
1122 | + '@link_devel' => 'http://www.drupal.org/project/devel', |
|
1123 | + '%type' => $type_name)), |
|
1124 | + ); |
|
1125 | 1125 | } |
1126 | 1126 | else { |
1127 | - $form['widget']['default_value_fieldset']['advanced_options']['markup_default_value_php'] = array( |
|
1127 | + $form['widget']['default_value_fieldset']['advanced_options']['markup_default_value_php'] = array( |
|
1128 | 1128 | '#type' => 'item', |
1129 | 1129 | '#title' => t('Code'), |
1130 | 1130 | '#value' => !empty($field['widget']['default_value_php']) ? '<code>'. check_plain($field['widget']['default_value_php']) .'</code>' : t('<none>'), |
1131 | 1131 | '#description' => empty($field['widget']['default_value_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override any value specified above.'), |
1132 | - ); |
|
1132 | + ); |
|
1133 | + } |
|
1133 | 1134 | } |
1134 | - } |
|
1135 | 1135 | |
1136 | - $form['field'] = array( |
|
1136 | + $form['field'] = array( |
|
1137 | 1137 | '#type' => 'fieldset', |
1138 | 1138 | '#title' => t('Global settings'), |
1139 | 1139 | '#description' => t('These settings apply to the %field field in every content type in which it appears.', array('%field' => $field['widget']['label'])), |
1140 | - ); |
|
1141 | - $form['field']['required'] = array( |
|
1140 | + ); |
|
1141 | + $form['field']['required'] = array( |
|
1142 | 1142 | '#type' => 'checkbox', |
1143 | 1143 | '#title' => t('Required'), |
1144 | 1144 | '#default_value' => $field['required'], |
1145 | - ); |
|
1146 | - $description = t('Maximum number of values users can enter for this field.'); |
|
1147 | - if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
1145 | + ); |
|
1146 | + $description = t('Maximum number of values users can enter for this field.'); |
|
1147 | + if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
1148 | 1148 | $description .= '<br/>'. t("'Unlimited' will provide an 'Add more' button so the users can add as many values as they like."); |
1149 | - } |
|
1150 | - $description .= '<br/><strong>'. t('Warning! Changing this setting after data has been created could result in the loss of data!') .'</strong>'; |
|
1151 | - $form['field']['multiple'] = array( |
|
1149 | + } |
|
1150 | + $description .= '<br/><strong>'. t('Warning! Changing this setting after data has been created could result in the loss of data!') .'</strong>'; |
|
1151 | + $form['field']['multiple'] = array( |
|
1152 | 1152 | '#type' => 'select', |
1153 | 1153 | '#title' => t('Number of values'), |
1154 | 1154 | '#options' => array(1 => t('Unlimited'), 0 => 1) + drupal_map_assoc(range(2, 10)), |
1155 | 1155 | '#default_value' => $field['multiple'], |
1156 | 1156 | '#description' => $description, |
1157 | - ); |
|
1157 | + ); |
|
1158 | 1158 | |
1159 | - $form['field']['previous_field'] = array( |
|
1159 | + $form['field']['previous_field'] = array( |
|
1160 | 1160 | '#type' => 'hidden', |
1161 | 1161 | '#value' => serialize($field), |
1162 | - ); |
|
1162 | + ); |
|
1163 | 1163 | |
1164 | - $additions = (array) module_invoke($field_type['module'], 'field_settings', 'form', $field); |
|
1165 | - drupal_alter('field_settings', $additions, 'form', $field); |
|
1166 | - $form['field'] = array_merge($form['field'], $additions); |
|
1164 | + $additions = (array) module_invoke($field_type['module'], 'field_settings', 'form', $field); |
|
1165 | + drupal_alter('field_settings', $additions, 'form', $field); |
|
1166 | + $form['field'] = array_merge($form['field'], $additions); |
|
1167 | 1167 | |
1168 | - $form['submit'] = array( |
|
1168 | + $form['submit'] = array( |
|
1169 | 1169 | '#type' => 'submit', |
1170 | 1170 | '#value' => t('Save field settings'), |
1171 | - ); |
|
1172 | - $form['type_name'] = array( |
|
1171 | + ); |
|
1172 | + $form['type_name'] = array( |
|
1173 | 1173 | '#type' => 'value', |
1174 | 1174 | '#value' => $type_name, |
1175 | - ); |
|
1176 | - $form['field_name'] = array( |
|
1175 | + ); |
|
1176 | + $form['field_name'] = array( |
|
1177 | 1177 | '#type' => 'value', |
1178 | 1178 | '#value' => $field_name, |
1179 | - ); |
|
1180 | - $form['type'] = array( |
|
1179 | + ); |
|
1180 | + $form['type'] = array( |
|
1181 | 1181 | '#type' => 'value', |
1182 | 1182 | '#value' => $field['type'], |
1183 | - ); |
|
1184 | - $form['module'] = array( |
|
1183 | + ); |
|
1184 | + $form['module'] = array( |
|
1185 | 1185 | '#type' => 'value', |
1186 | 1186 | '#value' => $field['module'], |
1187 | - ); |
|
1188 | - $form['widget']['label'] = array( |
|
1187 | + ); |
|
1188 | + $form['widget']['label'] = array( |
|
1189 | 1189 | '#type' => 'value', |
1190 | 1190 | '#value' => $field['widget']['label'], |
1191 | - ); |
|
1192 | - $form['widget_module'] = array( |
|
1191 | + ); |
|
1192 | + $form['widget_module'] = array( |
|
1193 | 1193 | '#type' => 'value', |
1194 | 1194 | '#value' => $field['widget']['module'], |
1195 | - ); |
|
1196 | - $form['columns'] = array( |
|
1195 | + ); |
|
1196 | + $form['columns'] = array( |
|
1197 | 1197 | '#type' => 'value', |
1198 | 1198 | '#value' => $field['columns'], |
1199 | - ); |
|
1200 | - return $form; |
|
1199 | + ); |
|
1200 | + return $form; |
|
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | /** |
1204 | 1204 | * Validate a field's settings. |
1205 | 1205 | */ |
1206 | 1206 | function content_field_edit_form_validate($form, &$form_state) { |
1207 | - $form_values = $form_state['values']; |
|
1208 | - if (isset($form_state['change_basic']) || $form_values['op'] == t('Change basic information')) { |
|
1207 | + $form_values = $form_state['values']; |
|
1208 | + if (isset($form_state['change_basic']) || $form_values['op'] == t('Change basic information')) { |
|
1209 | 1209 | return; |
1210 | - } |
|
1210 | + } |
|
1211 | 1211 | |
1212 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
1213 | - $previous_field = unserialize($form_values['previous_field']); |
|
1214 | - $field = content_field_instance_expand($form_values); |
|
1215 | - $field['db_storage'] = content_storage_type($field); |
|
1212 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
1213 | + $previous_field = unserialize($form_values['previous_field']); |
|
1214 | + $field = content_field_instance_expand($form_values); |
|
1215 | + $field['db_storage'] = content_storage_type($field); |
|
1216 | 1216 | |
1217 | - $field_types = _content_field_types(); |
|
1218 | - $field_type = $field_types[$field['type']]; |
|
1219 | - $widget_types = _content_widget_types(); |
|
1220 | - $widget_type = $widget_types[$field['widget']['type']]; |
|
1217 | + $field_types = _content_field_types(); |
|
1218 | + $field_type = $field_types[$field['type']]; |
|
1219 | + $widget_types = _content_widget_types(); |
|
1220 | + $widget_type = $widget_types[$field['widget']['type']]; |
|
1221 | 1221 | |
1222 | - if ($dropped_data = content_alter_db_analyze($previous_field, $field)) { |
|
1222 | + if ($dropped_data = content_alter_db_analyze($previous_field, $field)) { |
|
1223 | 1223 | // @TODO |
1224 | 1224 | // This is a change that might result in loss of data. |
1225 | 1225 | // Add a confirmation form here. |
1226 | 1226 | // dsm($dropped_data); |
1227 | - } |
|
1227 | + } |
|
1228 | 1228 | |
1229 | - module_invoke($widget_type['module'], 'widget_settings', 'validate', array_merge($field, $form_values)); |
|
1230 | - module_invoke($field_type['module'], 'field_settings', 'validate', array_merge($field, $form_values)); |
|
1229 | + module_invoke($widget_type['module'], 'widget_settings', 'validate', array_merge($field, $form_values)); |
|
1230 | + module_invoke($field_type['module'], 'field_settings', 'validate', array_merge($field, $form_values)); |
|
1231 | 1231 | |
1232 | - // If content.module is handling the default value, |
|
1233 | - // validate the result using the field validation. |
|
1234 | - if (content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) { |
|
1232 | + // If content.module is handling the default value, |
|
1233 | + // validate the result using the field validation. |
|
1234 | + if (content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) { |
|
1235 | 1235 | |
1236 | 1236 | // If this is a programmed form, get rid of the default value widget, |
1237 | 1237 | // we have the default values already. |
1238 | 1238 | if ($form['#programmed']) { |
1239 | - form_set_value(array('#parents' => array('default_value_widget')), NULL, $form_state); |
|
1240 | - return; |
|
1239 | + form_set_value(array('#parents' => array('default_value_widget')), NULL, $form_state); |
|
1240 | + return; |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | if (isset($form_values['default_value_php']) && |
1244 | 1244 | ($php = trim($form_values['default_value_php']))) { |
1245 | - $error = FALSE; |
|
1246 | - ob_start(); |
|
1247 | - $return = eval($php); |
|
1248 | - ob_end_clean(); |
|
1249 | - if (!is_array($return)) { |
|
1245 | + $error = FALSE; |
|
1246 | + ob_start(); |
|
1247 | + $return = eval($php); |
|
1248 | + ob_end_clean(); |
|
1249 | + if (!is_array($return)) { |
|
1250 | 1250 | $error = TRUE; |
1251 | - } |
|
1252 | - else { |
|
1251 | + } |
|
1252 | + else { |
|
1253 | 1253 | foreach ($return as $item) { |
1254 | - if (!is_array($item)) { |
|
1254 | + if (!is_array($item)) { |
|
1255 | 1255 | $error = TRUE; |
1256 | 1256 | break; |
1257 | - } |
|
1257 | + } |
|
1258 | 1258 | } |
1259 | - } |
|
1260 | - if ($error) { |
|
1259 | + } |
|
1260 | + if ($error) { |
|
1261 | 1261 | $db_info = content_database_info($field); |
1262 | 1262 | $columns = array_keys($db_info['columns']); |
1263 | 1263 | foreach ($columns as $key => $column) { |
1264 | - $columns[$key] = t("'@column' => value for @column", array('@column' => $column)); |
|
1264 | + $columns[$key] = t("'@column' => value for @column", array('@column' => $column)); |
|
1265 | 1265 | } |
1266 | 1266 | $sample = t("return array(\n 0 => array(@columns),\n // You'll usually want to stop here. Provide more values\n // if you want your 'default value' to be multi-valued:\n 1 => array(@columns),\n 2 => ...\n);", array('@columns' => implode(', ', $columns))); |
1267 | 1267 | |
1268 | 1268 | form_set_error('default_value_php', t('The default value PHP code returned an incorrect value.<br/>Expected format: <pre>!sample</pre> Returned value: @value', array( |
1269 | - '!sample' => $sample, |
|
1270 | - '@value' => print_r($return, TRUE)))); |
|
1269 | + '!sample' => $sample, |
|
1270 | + '@value' => print_r($return, TRUE)))); |
|
1271 | 1271 | return; |
1272 | - } |
|
1273 | - else { |
|
1272 | + } |
|
1273 | + else { |
|
1274 | 1274 | $default_value = $return; |
1275 | 1275 | $is_code = TRUE; |
1276 | 1276 | form_set_value(array('#parents' => array('default_value_php')), $php, $form_state); |
1277 | 1277 | form_set_value(array('#parents' => array('default_value')), array(), $form_state); |
1278 | - } |
|
1278 | + } |
|
1279 | 1279 | } |
1280 | 1280 | elseif (!empty($form_values['default_value_widget'])) { |
1281 | - // Fields that handle their own multiple values may use an expected |
|
1282 | - // value as the top-level key, so just pop off the top element. |
|
1283 | - $key = array_shift(array_keys($form_values['default_value_widget'])); |
|
1284 | - $default_value = $form_values['default_value_widget'][$key]; |
|
1285 | - $is_code = FALSE; |
|
1286 | - form_set_value(array('#parents' => array('default_value_php')), '', $form_state); |
|
1287 | - form_set_value(array('#parents' => array('default_value')), $default_value, $form_state); |
|
1281 | + // Fields that handle their own multiple values may use an expected |
|
1282 | + // value as the top-level key, so just pop off the top element. |
|
1283 | + $key = array_shift(array_keys($form_values['default_value_widget'])); |
|
1284 | + $default_value = $form_values['default_value_widget'][$key]; |
|
1285 | + $is_code = FALSE; |
|
1286 | + form_set_value(array('#parents' => array('default_value_php')), '', $form_state); |
|
1287 | + form_set_value(array('#parents' => array('default_value')), $default_value, $form_state); |
|
1288 | 1288 | } |
1289 | 1289 | if (isset($default_value)) { |
1290 | - $node = array(); |
|
1291 | - $node[$form_values['field_name']] = $default_value; |
|
1292 | - $field['required'] = FALSE; |
|
1293 | - $field_function = $field_type['module'] .'_field'; |
|
1290 | + $node = array(); |
|
1291 | + $node[$form_values['field_name']] = $default_value; |
|
1292 | + $field['required'] = FALSE; |
|
1293 | + $field_function = $field_type['module'] .'_field'; |
|
1294 | 1294 | |
1295 | - $errors_before = form_get_errors(); |
|
1295 | + $errors_before = form_get_errors(); |
|
1296 | 1296 | |
1297 | - // Widget now does its own validation, should be no need |
|
1298 | - // to add anything for widget validation here. |
|
1299 | - if (function_exists($field_function)) { |
|
1297 | + // Widget now does its own validation, should be no need |
|
1298 | + // to add anything for widget validation here. |
|
1299 | + if (function_exists($field_function)) { |
|
1300 | 1300 | $field_function('validate', $node, $field, $default_value, $form, NULL); |
1301 | - } |
|
1302 | - // The field validation routine won't set an error on the right field, |
|
1303 | - // so set it here. |
|
1304 | - $errors_after = form_get_errors(); |
|
1305 | - if (count($errors_after) > count($errors_before)) { |
|
1301 | + } |
|
1302 | + // The field validation routine won't set an error on the right field, |
|
1303 | + // so set it here. |
|
1304 | + $errors_after = form_get_errors(); |
|
1305 | + if (count($errors_after) > count($errors_before)) { |
|
1306 | 1306 | if (trim($form_values['default_value_php'])) { |
1307 | - form_set_error('default_value_php', t("The PHP code for 'default value' returned @value, which is invalid.", array( |
|
1307 | + form_set_error('default_value_php', t("The PHP code for 'default value' returned @value, which is invalid.", array( |
|
1308 | 1308 | '@value' => print_r($default_value, TRUE)))); |
1309 | 1309 | } |
1310 | 1310 | else { |
1311 | - form_set_error('default_value', t('The default value is invalid.')); |
|
1311 | + form_set_error('default_value', t('The default value is invalid.')); |
|
1312 | 1312 | } |
1313 | - } |
|
1313 | + } |
|
1314 | + } |
|
1314 | 1315 | } |
1315 | - } |
|
1316 | 1316 | } |
1317 | 1317 | |
1318 | 1318 | /** |
1319 | 1319 | * Button submit handler. |
1320 | 1320 | */ |
1321 | 1321 | function content_field_edit_form_submit_update_basic($form, &$form_state) { |
1322 | - $form_state['change_basic'] = TRUE; |
|
1323 | - $form_state['rebuild'] = TRUE; |
|
1322 | + $form_state['change_basic'] = TRUE; |
|
1323 | + $form_state['rebuild'] = TRUE; |
|
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | /** |
1327 | 1327 | * Save a field's settings after editing. |
1328 | 1328 | */ |
1329 | 1329 | function content_field_edit_form_submit($form, &$form_state) { |
1330 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
1331 | - $form_values = $form_state['values']; |
|
1332 | - content_field_instance_update($form_values); |
|
1333 | - |
|
1334 | - $destinations = !empty($_REQUEST['destinations']) ? $_REQUEST['destinations'] : array(); |
|
1335 | - // Remove any external URLs. |
|
1336 | - $destinations = array_diff($destinations, array_filter($destinations, 'menu_path_is_external')); |
|
1337 | - if ($destinations) { |
|
1330 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
1331 | + $form_values = $form_state['values']; |
|
1332 | + content_field_instance_update($form_values); |
|
1333 | + |
|
1334 | + $destinations = !empty($_REQUEST['destinations']) ? $_REQUEST['destinations'] : array(); |
|
1335 | + // Remove any external URLs. |
|
1336 | + $destinations = array_diff($destinations, array_filter($destinations, 'menu_path_is_external')); |
|
1337 | + if ($destinations) { |
|
1338 | 1338 | drupal_set_message(t('Added field %label.', array('%label' => $form_values['label']))); |
1339 | 1339 | $form_state['redirect'] = content_get_destinations($destinations); |
1340 | - } |
|
1341 | - else { |
|
1340 | + } |
|
1341 | + else { |
|
1342 | 1342 | drupal_set_message(t('Saved field %label.', array('%label' => $form_values['label']))); |
1343 | 1343 | $type = content_types($form_values['type_name']); |
1344 | 1344 | $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; |
1345 | - } |
|
1345 | + } |
|
1346 | 1346 | } |
1347 | 1347 | |
1348 | 1348 | /** |
1349 | 1349 | * Helper function to handle multipage redirects. |
1350 | 1350 | */ |
1351 | 1351 | function content_get_destinations($destinations) { |
1352 | - $query = array(); |
|
1353 | - $path = array_shift($destinations); |
|
1354 | - if ($destinations) { |
|
1352 | + $query = array(); |
|
1353 | + $path = array_shift($destinations); |
|
1354 | + if ($destinations) { |
|
1355 | 1355 | $query['destinations'] = $destinations; |
1356 | - } |
|
1357 | - return array($path, $query); |
|
1356 | + } |
|
1357 | + return array($path, $query); |
|
1358 | 1358 | } |
1359 | 1359 | |
1360 | 1360 | /** |
@@ -1367,7 +1367,7 @@ discard block |
||
1367 | 1367 | * |
1368 | 1368 | */ |
1369 | 1369 | function content_alter_schema($previous_field, $new_field) { |
1370 | - content_alter_db($previous_field, $new_field); |
|
1370 | + content_alter_db($previous_field, $new_field); |
|
1371 | 1371 | } |
1372 | 1372 | |
1373 | 1373 | /** |
@@ -1378,37 +1378,37 @@ discard block |
||
1378 | 1378 | * we actually alter the schema. |
1379 | 1379 | */ |
1380 | 1380 | function content_alter_db_analyze($previous_field, $new_field) { |
1381 | - $dropped = array(); |
|
1382 | - // There is no loss of data if there was no previous data. |
|
1383 | - if (empty($previous_field)) { |
|
1381 | + $dropped = array(); |
|
1382 | + // There is no loss of data if there was no previous data. |
|
1383 | + if (empty($previous_field)) { |
|
1384 | 1384 | return $dropped; |
1385 | - } |
|
1385 | + } |
|
1386 | 1386 | |
1387 | - // Analyze possible data loss from changes in storage type. |
|
1388 | - if (!empty($previous_field) && !empty($new_field)) { |
|
1387 | + // Analyze possible data loss from changes in storage type. |
|
1388 | + if (!empty($previous_field) && !empty($new_field)) { |
|
1389 | 1389 | // Changing from multiple to not multiple data, will cause loss of all |
1390 | 1390 | // values greater than zero. |
1391 | 1391 | if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD && |
1392 | 1392 | $new_field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE) { |
1393 | - $dropped['delta'] = 0; |
|
1393 | + $dropped['delta'] = 0; |
|
1394 | 1394 | } |
1395 | 1395 | // Changing from one multiple value to another will cause loss of all |
1396 | 1396 | // values for deltas greater than or equal to the new multiple value. |
1397 | 1397 | elseif (isset($previous_field['multiple']) && isset($new_field['multiple'])) { |
1398 | - if ($previous_field['multiple'] > $new_field['multiple'] && |
|
1398 | + if ($previous_field['multiple'] > $new_field['multiple'] && |
|
1399 | 1399 | $new_field['multiple'] > 1) { |
1400 | 1400 | $dropped['delta'] = $new_field['multiple']; |
1401 | - } |
|
1401 | + } |
|
1402 | + } |
|
1402 | 1403 | } |
1403 | - } |
|
1404 | 1404 | |
1405 | - // Analyze possible data loss from changes in field columns. |
|
1406 | - $previous_schema = !empty($previous_field) ? content_table_schema($previous_field) : array('fields' => array()); |
|
1407 | - $new_schema = !empty($new_field) ? content_table_schema($new_field) : array('fields' => array()); |
|
1408 | - $dropped_columns = array_diff(array_keys($previous_schema['fields']), array_keys($new_schema['fields'])); |
|
1409 | - if ($dropped_columns) { |
|
1405 | + // Analyze possible data loss from changes in field columns. |
|
1406 | + $previous_schema = !empty($previous_field) ? content_table_schema($previous_field) : array('fields' => array()); |
|
1407 | + $new_schema = !empty($new_field) ? content_table_schema($new_field) : array('fields' => array()); |
|
1408 | + $dropped_columns = array_diff(array_keys($previous_schema['fields']), array_keys($new_schema['fields'])); |
|
1409 | + if ($dropped_columns) { |
|
1410 | 1410 | $dropped['columns'] = $dropped_columns; |
1411 | - } |
|
1411 | + } |
|
1412 | 1412 | // if (empty($new_schema['fields'])) { |
1413 | 1413 | // // No new columns, will lose all columns for a field. |
1414 | 1414 | // foreach ($previous_schema['fields'] as $column => $attributes) { |
@@ -1424,7 +1424,7 @@ discard block |
||
1424 | 1424 | // } |
1425 | 1425 | // } |
1426 | 1426 | |
1427 | - return $dropped; |
|
1427 | + return $dropped; |
|
1428 | 1428 | } |
1429 | 1429 | |
1430 | 1430 | /** |
@@ -1432,214 +1432,214 @@ discard block |
||
1432 | 1432 | * new field definitions. |
1433 | 1433 | */ |
1434 | 1434 | function content_alter_db($previous_field, $new_field) { |
1435 | - $ret = array(); |
|
1435 | + $ret = array(); |
|
1436 | 1436 | |
1437 | - // One or the other of these must be valid. |
|
1438 | - if (empty($previous_field) && empty($new_field)) { |
|
1437 | + // One or the other of these must be valid. |
|
1438 | + if (empty($previous_field) && empty($new_field)) { |
|
1439 | 1439 | return $ret; |
1440 | - } |
|
1440 | + } |
|
1441 | 1441 | |
1442 | - // Gather relevant information : schema, table name... |
|
1443 | - $previous_schema = !empty($previous_field) ? content_table_schema($previous_field) : array(); |
|
1444 | - $new_schema = !empty($new_field) ? content_table_schema($new_field) : array(); |
|
1445 | - if (!empty($previous_field)) { |
|
1442 | + // Gather relevant information : schema, table name... |
|
1443 | + $previous_schema = !empty($previous_field) ? content_table_schema($previous_field) : array(); |
|
1444 | + $new_schema = !empty($new_field) ? content_table_schema($new_field) : array(); |
|
1445 | + if (!empty($previous_field)) { |
|
1446 | 1446 | $previous_db_info = content_database_info($previous_field); |
1447 | 1447 | $previous_table = $previous_db_info['table']; |
1448 | - } |
|
1449 | - if (!empty($new_field)) { |
|
1448 | + } |
|
1449 | + if (!empty($new_field)) { |
|
1450 | 1450 | $new_db_info = content_database_info($new_field); |
1451 | 1451 | $new_table = $new_db_info['table']; |
1452 | - } |
|
1452 | + } |
|
1453 | 1453 | |
1454 | - // Deletion of a field instance: drop relevant columns and tables and return. |
|
1455 | - if (empty($new_field)) { |
|
1454 | + // Deletion of a field instance: drop relevant columns and tables and return. |
|
1455 | + if (empty($new_field)) { |
|
1456 | 1456 | if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
1457 | - db_drop_table($ret, $previous_table); |
|
1457 | + db_drop_table($ret, $previous_table); |
|
1458 | 1458 | } |
1459 | 1459 | else { |
1460 | - foreach ($previous_schema['fields'] as $column => $attributes) { |
|
1460 | + foreach ($previous_schema['fields'] as $column => $attributes) { |
|
1461 | 1461 | if (!in_array($column, array('nid', 'vid', 'delta'))) { |
1462 | - db_drop_field($ret, $previous_table, $column); |
|
1462 | + db_drop_field($ret, $previous_table, $column); |
|
1463 | + } |
|
1463 | 1464 | } |
1464 | - } |
|
1465 | 1465 | } |
1466 | 1466 | content_alter_db_cleanup(); |
1467 | 1467 | return $ret; |
1468 | - } |
|
1468 | + } |
|
1469 | 1469 | |
1470 | - // Check that content types that have fields do have a per-type table. |
|
1471 | - if (!empty($new_field)) { |
|
1470 | + // Check that content types that have fields do have a per-type table. |
|
1471 | + if (!empty($new_field)) { |
|
1472 | 1472 | $base_tablename = _content_tablename($new_field['type_name'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE); |
1473 | 1473 | if (!db_table_exists($base_tablename)) { |
1474 | - db_create_table($ret, $base_tablename, content_table_schema()); |
|
1474 | + db_create_table($ret, $base_tablename, content_table_schema()); |
|
1475 | + } |
|
1475 | 1476 | } |
1476 | - } |
|
1477 | 1477 | |
1478 | - // Create new table and columns, if not already created. |
|
1479 | - if (!db_table_exists($new_table)) { |
|
1478 | + // Create new table and columns, if not already created. |
|
1479 | + if (!db_table_exists($new_table)) { |
|
1480 | 1480 | db_create_table($ret, $new_table, $new_schema); |
1481 | - } |
|
1482 | - else { |
|
1481 | + } |
|
1482 | + else { |
|
1483 | 1483 | // Or add fields and/or indexes to an existing table. |
1484 | 1484 | foreach ($new_schema['fields'] as $column => $attributes) { |
1485 | - if (!in_array($column, array('nid', 'vid', 'delta'))) { |
|
1485 | + if (!in_array($column, array('nid', 'vid', 'delta'))) { |
|
1486 | 1486 | // Create the column if it does not exist. |
1487 | 1487 | if (!db_column_exists($new_table, $column)) { |
1488 | - db_add_field($ret, $new_table, $column, $attributes); |
|
1488 | + db_add_field($ret, $new_table, $column, $attributes); |
|
1489 | 1489 | } |
1490 | 1490 | // Create the index if requested to, and it does not exist. |
1491 | 1491 | if (isset($new_schema['indexes'][$column]) && !content_db_index_exists($new_table, $column)) { |
1492 | - db_add_index($ret, $new_table, $column, $new_schema['indexes'][$column]); |
|
1492 | + db_add_index($ret, $new_table, $column, $new_schema['indexes'][$column]); |
|
1493 | + } |
|
1493 | 1494 | } |
1494 | - } |
|
1495 | 1495 | } |
1496 | - } |
|
1496 | + } |
|
1497 | 1497 | |
1498 | - // If this is a new field, we're done. |
|
1499 | - if (empty($previous_field)) { |
|
1498 | + // If this is a new field, we're done. |
|
1499 | + if (empty($previous_field)) { |
|
1500 | 1500 | content_alter_db_cleanup(); |
1501 | 1501 | return $ret; |
1502 | - } |
|
1502 | + } |
|
1503 | 1503 | |
1504 | - // If the previous table doesn't exist, we're done. |
|
1505 | - // Could happen if someone tries to run a schema update from an |
|
1506 | - // content.install update function more than once. |
|
1507 | - if (!db_table_exists($previous_table)) { |
|
1504 | + // If the previous table doesn't exist, we're done. |
|
1505 | + // Could happen if someone tries to run a schema update from an |
|
1506 | + // content.install update function more than once. |
|
1507 | + if (!db_table_exists($previous_table)) { |
|
1508 | 1508 | content_alter_db_cleanup(); |
1509 | 1509 | return $ret; |
1510 | - } |
|
1510 | + } |
|
1511 | 1511 | |
1512 | - // If changing data from one schema to another, see if changes require that |
|
1513 | - // we drop multiple values or migrate data from one storage type to another. |
|
1514 | - $migrate_columns = array_intersect_assoc($new_schema['fields'], $previous_schema['fields']); |
|
1515 | - unset($migrate_columns['nid'], $migrate_columns['vid'], $migrate_columns['delta']); |
|
1512 | + // If changing data from one schema to another, see if changes require that |
|
1513 | + // we drop multiple values or migrate data from one storage type to another. |
|
1514 | + $migrate_columns = array_intersect_assoc($new_schema['fields'], $previous_schema['fields']); |
|
1515 | + unset($migrate_columns['nid'], $migrate_columns['vid'], $migrate_columns['delta']); |
|
1516 | 1516 | |
1517 | - // If we're going from one multiple value a smaller one or to single, |
|
1518 | - // drop all delta values higher than the new maximum delta value. |
|
1519 | - // Not needed if the new multiple is unlimited or if the new table is the content table. |
|
1520 | - if ($new_table != $base_tablename && $new_field['multiple'] < $previous_field['multiple'] && $new_field['multiple'] != 1) { |
|
1517 | + // If we're going from one multiple value a smaller one or to single, |
|
1518 | + // drop all delta values higher than the new maximum delta value. |
|
1519 | + // Not needed if the new multiple is unlimited or if the new table is the content table. |
|
1520 | + if ($new_table != $base_tablename && $new_field['multiple'] < $previous_field['multiple'] && $new_field['multiple'] != 1) { |
|
1521 | 1521 | db_query("DELETE FROM {". $new_table ."} WHERE delta >= ". max(1, $new_field['multiple'])); |
1522 | - } |
|
1522 | + } |
|
1523 | 1523 | |
1524 | - // If going from multiple to non-multiple, make sure the field tables have |
|
1525 | - // the right database structure to accept migrated data. |
|
1526 | - if ($new_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
|
1524 | + // If going from multiple to non-multiple, make sure the field tables have |
|
1525 | + // the right database structure to accept migrated data. |
|
1526 | + if ($new_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
|
1527 | 1527 | if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD && count($previous_schema['fields'])) { |
1528 | - // Already using per-field storage; change multiplicity if needed. |
|
1529 | - if ($previous_field['multiple'] > 0 && $new_field['multiple'] == 0) { |
|
1528 | + // Already using per-field storage; change multiplicity if needed. |
|
1529 | + if ($previous_field['multiple'] > 0 && $new_field['multiple'] == 0) { |
|
1530 | 1530 | db_drop_field($ret, $new_table, 'delta'); |
1531 | 1531 | db_drop_primary_key($ret, $new_table); |
1532 | 1532 | db_add_primary_key($ret, $new_table, array('vid')); |
1533 | - } |
|
1534 | - else if ($previous_field['multiple'] == 0 && $new_field['multiple'] > 0) { |
|
1533 | + } |
|
1534 | + else if ($previous_field['multiple'] == 0 && $new_field['multiple'] > 0) { |
|
1535 | 1535 | db_add_field($ret, $new_table, 'delta', array( |
1536 | - 'type' => 'int', |
|
1537 | - 'unsigned' => TRUE, |
|
1538 | - 'not null' => TRUE, |
|
1539 | - 'default' => 0)); |
|
1536 | + 'type' => 'int', |
|
1537 | + 'unsigned' => TRUE, |
|
1538 | + 'not null' => TRUE, |
|
1539 | + 'default' => 0)); |
|
1540 | 1540 | db_drop_primary_key($ret, $new_table); |
1541 | 1541 | db_add_primary_key($ret, $new_table, array('vid', 'delta')); |
1542 | - } |
|
1542 | + } |
|
1543 | + } |
|
1543 | 1544 | } |
1544 | - } |
|
1545 | 1545 | |
1546 | - // Migrate data from per-content-type storage. |
|
1547 | - if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE && |
|
1546 | + // Migrate data from per-content-type storage. |
|
1547 | + if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE && |
|
1548 | 1548 | $new_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
1549 | 1549 | $columns = array_keys($migrate_columns); |
1550 | 1550 | if ($new_field['multiple']) { |
1551 | - db_query('INSERT INTO {'. $new_table .'} (vid, nid, delta, '. implode(', ', $columns) .') '. |
|
1551 | + db_query('INSERT INTO {'. $new_table .'} (vid, nid, delta, '. implode(', ', $columns) .') '. |
|
1552 | 1552 | ' SELECT vid, nid, 0, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
1553 | 1553 | } |
1554 | 1554 | else { |
1555 | - db_query('INSERT INTO {'. $new_table .'} (vid, nid, '. implode(', ', $columns) .') '. |
|
1555 | + db_query('INSERT INTO {'. $new_table .'} (vid, nid, '. implode(', ', $columns) .') '. |
|
1556 | 1556 | ' SELECT vid, nid, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
1557 | 1557 | } |
1558 | 1558 | foreach ($columns as $column_name) { |
1559 | - db_drop_field($ret, $previous_table, $column_name); |
|
1559 | + db_drop_field($ret, $previous_table, $column_name); |
|
1560 | + } |
|
1560 | 1561 | } |
1561 | - } |
|
1562 | 1562 | |
1563 | - // Migrate data from per-field storage, and drop per-field table. |
|
1564 | - if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD && |
|
1563 | + // Migrate data from per-field storage, and drop per-field table. |
|
1564 | + if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD && |
|
1565 | 1565 | $new_field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE) { |
1566 | 1566 | // In order to be able to use drupal_write_record, we need to |
1567 | 1567 | // rebuild the schema now. |
1568 | 1568 | content_alter_db_cleanup(); |
1569 | 1569 | if ($previous_field['multiple']) { |
1570 | - $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE delta = 0 AND n.type = '%s'", $new_field['type_name']); |
|
1570 | + $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE delta = 0 AND n.type = '%s'", $new_field['type_name']); |
|
1571 | 1571 | } |
1572 | 1572 | else { |
1573 | - $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s'", $new_field['type_name']); |
|
1573 | + $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s'", $new_field['type_name']); |
|
1574 | 1574 | } |
1575 | 1575 | $record = array(); |
1576 | 1576 | while ($data = db_fetch_array($result)) { |
1577 | - $record['nid'] = $data['nid']; |
|
1578 | - $record['vid'] = $data['vid']; |
|
1579 | - if ($previous_field['multiple']) { |
|
1577 | + $record['nid'] = $data['nid']; |
|
1578 | + $record['vid'] = $data['vid']; |
|
1579 | + if ($previous_field['multiple']) { |
|
1580 | 1580 | $record['delta'] = $data['delta']; |
1581 | - } |
|
1582 | - foreach ($migrate_columns as $column => $attributes) { |
|
1581 | + } |
|
1582 | + foreach ($migrate_columns as $column => $attributes) { |
|
1583 | 1583 | if (is_null($data[$column])) { |
1584 | - $record[$column] = NULL; |
|
1584 | + $record[$column] = NULL; |
|
1585 | 1585 | } |
1586 | 1586 | else { |
1587 | - $record[$column] = $data[$column]; |
|
1588 | - // Prevent double serializtion in drupal_write_record. |
|
1589 | - if (isset($attributes['serialize']) && $attributes['serialize']) { |
|
1587 | + $record[$column] = $data[$column]; |
|
1588 | + // Prevent double serializtion in drupal_write_record. |
|
1589 | + if (isset($attributes['serialize']) && $attributes['serialize']) { |
|
1590 | 1590 | $record[$column] = unserialize($record[$column]); |
1591 | - } |
|
1591 | + } |
|
1592 | 1592 | } |
1593 | - } |
|
1594 | - if (db_result(db_query('SELECT COUNT(*) FROM {'. $new_table . |
|
1595 | - '} WHERE vid = %d AND nid = %d', $data['vid'], $data['nid']))) { |
|
1593 | + } |
|
1594 | + if (db_result(db_query('SELECT COUNT(*) FROM {'. $new_table . |
|
1595 | + '} WHERE vid = %d AND nid = %d', $data['vid'], $data['nid']))) { |
|
1596 | 1596 | $keys = $new_field['multiple'] ? array('vid', 'delta') : array('vid'); |
1597 | 1597 | drupal_write_record($new_table, $record, $keys); |
1598 | - } |
|
1599 | - else { |
|
1598 | + } |
|
1599 | + else { |
|
1600 | 1600 | drupal_write_record($new_table, $record); |
1601 | - } |
|
1601 | + } |
|
1602 | 1602 | } |
1603 | 1603 | db_drop_table($ret, $previous_table); |
1604 | - } |
|
1604 | + } |
|
1605 | 1605 | |
1606 | - // Change modified columns that don't involve storage changes. |
|
1607 | - foreach ($new_schema['fields'] as $column => $attributes) { |
|
1606 | + // Change modified columns that don't involve storage changes. |
|
1607 | + foreach ($new_schema['fields'] as $column => $attributes) { |
|
1608 | 1608 | if (isset($previous_schema['fields'][$column]) && |
1609 | 1609 | $previous_field['db_storage'] == $new_field['db_storage']) { |
1610 | - if ($attributes != $previous_schema['fields'][$column]) { |
|
1610 | + if ($attributes != $previous_schema['fields'][$column]) { |
|
1611 | 1611 | if (!in_array($column, array('nid', 'vid', 'delta'))) { |
1612 | - db_change_field($ret, $new_table, $column, $column, $attributes); |
|
1612 | + db_change_field($ret, $new_table, $column, $column, $attributes); |
|
1613 | + } |
|
1613 | 1614 | } |
1614 | - } |
|
1615 | 1615 | } |
1616 | - } |
|
1616 | + } |
|
1617 | 1617 | |
1618 | - // Remove obsolete columns. |
|
1619 | - foreach ($previous_schema['fields'] as $column => $attributes) { |
|
1618 | + // Remove obsolete columns. |
|
1619 | + foreach ($previous_schema['fields'] as $column => $attributes) { |
|
1620 | 1620 | if (!isset($new_schema['fields'][$column])) { |
1621 | - if (!in_array($column, array('nid', 'vid', 'delta'))) { |
|
1621 | + if (!in_array($column, array('nid', 'vid', 'delta'))) { |
|
1622 | 1622 | db_drop_field($ret, $previous_table, $column); |
1623 | - } |
|
1623 | + } |
|
1624 | + } |
|
1624 | 1625 | } |
1625 | - } |
|
1626 | 1626 | |
1627 | - // TODO: debugging stuff - should be removed |
|
1628 | - if (module_exists('devel')) { |
|
1627 | + // TODO: debugging stuff - should be removed |
|
1628 | + if (module_exists('devel')) { |
|
1629 | 1629 | //dsm($ret); |
1630 | - } |
|
1631 | - return $ret; |
|
1630 | + } |
|
1631 | + return $ret; |
|
1632 | 1632 | } |
1633 | 1633 | |
1634 | 1634 | /** |
1635 | 1635 | * Helper function for handling cleanup operations when schema changes are made. |
1636 | 1636 | */ |
1637 | 1637 | function content_alter_db_cleanup() { |
1638 | - // Rebuild the whole database schema. |
|
1639 | - // TODO: this could be optimized. We don't need to rebuild in *every case*... |
|
1640 | - // Or do we? This affects the schema and menu and may have unfortunate |
|
1641 | - // delayed effects if we don't clear everything out at this point. |
|
1642 | - content_clear_type_cache(TRUE); |
|
1638 | + // Rebuild the whole database schema. |
|
1639 | + // TODO: this could be optimized. We don't need to rebuild in *every case*... |
|
1640 | + // Or do we? This affects the schema and menu and may have unfortunate |
|
1641 | + // delayed effects if we don't clear everything out at this point. |
|
1642 | + content_clear_type_cache(TRUE); |
|
1643 | 1643 | } |
1644 | 1644 | |
1645 | 1645 | /** |
@@ -1650,27 +1650,27 @@ discard block |
||
1650 | 1650 | * relationships are sorted out. |
1651 | 1651 | */ |
1652 | 1652 | function _content_overview_order(&$form, $field_rows, $group_rows) { |
1653 | - // Put weight and parenting values into a $dummy render structure |
|
1654 | - // and let drupal_render figure out the corresponding row order. |
|
1655 | - $dummy = array(); |
|
1656 | - // Group rows: account for weight. |
|
1657 | - if (module_exists('fieldgroup')) { |
|
1653 | + // Put weight and parenting values into a $dummy render structure |
|
1654 | + // and let drupal_render figure out the corresponding row order. |
|
1655 | + $dummy = array(); |
|
1656 | + // Group rows: account for weight. |
|
1657 | + if (module_exists('fieldgroup')) { |
|
1658 | 1658 | foreach ($group_rows as $name) { |
1659 | - $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name .' '); |
|
1659 | + $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name .' '); |
|
1660 | 1660 | } |
1661 | - } |
|
1662 | - // Field rows : account for weight and parenting. |
|
1663 | - foreach ($field_rows as $name) { |
|
1661 | + } |
|
1662 | + // Field rows : account for weight and parenting. |
|
1663 | + foreach ($field_rows as $name) { |
|
1664 | 1664 | $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name .' '); |
1665 | 1665 | if (module_exists('fieldgroup')) { |
1666 | - if ($parent = $form[$name]['parent']['#value']) { |
|
1666 | + if ($parent = $form[$name]['parent']['#value']) { |
|
1667 | 1667 | $form[$name]['#depth'] = 1; |
1668 | 1668 | $dummy[$parent][$name] = $dummy[$name]; |
1669 | 1669 | unset($dummy[$name]); |
1670 | - } |
|
1670 | + } |
|
1671 | 1671 | } |
1672 | - } |
|
1673 | - return $dummy ? explode(' ', trim(drupal_render($dummy))) : array(); |
|
1672 | + } |
|
1673 | + return $dummy ? explode(' ', trim(drupal_render($dummy))) : array(); |
|
1674 | 1674 | } |
1675 | 1675 | |
1676 | 1676 | /** |
@@ -1683,50 +1683,50 @@ discard block |
||
1683 | 1683 | * this and get it working properly when the fields are altered via the API. |
1684 | 1684 | */ |
1685 | 1685 | function content_alter_fields($previous_field, $new_field) { |
1686 | - // See what values need to be updated in the field data. |
|
1687 | - $mask = content_alter_db_mask($previous_field, $new_field); |
|
1688 | - |
|
1689 | - // We use batch processing to prevent timeout when updating a large number |
|
1690 | - // of nodes. If there is no previous data to adjust, we can just go straight |
|
1691 | - // to altering the schema, otherwise use batch processing to update |
|
1692 | - // the database one node at a time, then update the schema. |
|
1693 | - if (empty($mask)) { |
|
1686 | + // See what values need to be updated in the field data. |
|
1687 | + $mask = content_alter_db_mask($previous_field, $new_field); |
|
1688 | + |
|
1689 | + // We use batch processing to prevent timeout when updating a large number |
|
1690 | + // of nodes. If there is no previous data to adjust, we can just go straight |
|
1691 | + // to altering the schema, otherwise use batch processing to update |
|
1692 | + // the database one node at a time, then update the schema. |
|
1693 | + if (empty($mask)) { |
|
1694 | 1694 | return content_alter_db($previous_field, $new_field); |
1695 | - } |
|
1696 | - $updates = array( |
|
1695 | + } |
|
1696 | + $updates = array( |
|
1697 | 1697 | 'mask' => $mask['mask'], |
1698 | 1698 | 'alt_mask' => $mask['alt_mask'], |
1699 | 1699 | 'delta' => $mask['delta'], |
1700 | 1700 | ); |
1701 | - $batch = array( |
|
1701 | + $batch = array( |
|
1702 | 1702 | 'operations' => array( |
1703 | - array('content_field_batch_update', array($previous_field['field_name'] => $updates)), |
|
1704 | - array('content_alter_db', array($previous_field, $new_field)) |
|
1703 | + array('content_field_batch_update', array($previous_field['field_name'] => $updates)), |
|
1704 | + array('content_alter_db', array($previous_field, $new_field)) |
|
1705 | 1705 | ), |
1706 | 1706 | 'finished' => '_content_alter_fields_finished', |
1707 | 1707 | 'title' => t('Processing'), |
1708 | 1708 | 'error_message' => t('The update has encountered an error.'), |
1709 | 1709 | 'file' => './'. drupal_get_path('module', 'content') .'/includes/content.admin.inc', |
1710 | - ); |
|
1711 | - batch_set($batch); |
|
1712 | - if (!empty($url)) { |
|
1710 | + ); |
|
1711 | + batch_set($batch); |
|
1712 | + if (!empty($url)) { |
|
1713 | 1713 | batch_process($url, $url); |
1714 | - } |
|
1714 | + } |
|
1715 | 1715 | } |
1716 | 1716 | |
1717 | 1717 | /** |
1718 | 1718 | * Content Replace Fields 'finished' callback. |
1719 | 1719 | */ |
1720 | 1720 | function _content_alter_fields_finished($success, $results, $operations) { |
1721 | - if ($success) { |
|
1721 | + if ($success) { |
|
1722 | 1722 | drupal_set_message(t('The database has been altered and data has been migrated or deleted.')); |
1723 | - } |
|
1724 | - else { |
|
1723 | + } |
|
1724 | + else { |
|
1725 | 1725 | drupal_set_message(t('An error occurred and database alteration did not complete.'), 'error'); |
1726 | 1726 | $message = format_plural(count($results), '1 item successfully processed:', '@count items successfully processed:'); |
1727 | 1727 | $message .= theme('item_list', $results); |
1728 | 1728 | drupal_set_message($message); |
1729 | - } |
|
1729 | + } |
|
1730 | 1730 | } |
1731 | 1731 | |
1732 | 1732 | /** |
@@ -1741,28 +1741,28 @@ discard block |
||
1741 | 1741 | * some columns still have values, so all these things need to be tested. |
1742 | 1742 | */ |
1743 | 1743 | function content_alter_db_mask($previous_field, $new_field) { |
1744 | - // Get an array of column values that will be dropped by this |
|
1745 | - // schema change and create a mask to feed to content_batch_update. |
|
1744 | + // Get an array of column values that will be dropped by this |
|
1745 | + // schema change and create a mask to feed to content_batch_update. |
|
1746 | 1746 | |
1747 | - $dropped = content_alter_db_analyze($previous_field, $new_field); |
|
1748 | - if (empty($dropped)) { |
|
1747 | + $dropped = content_alter_db_analyze($previous_field, $new_field); |
|
1748 | + if (empty($dropped)) { |
|
1749 | 1749 | return array(); |
1750 | - } |
|
1751 | - $mask = array('mask' => array()); |
|
1752 | - foreach (array_keys($previous_field['columns']) as $column_name) { |
|
1750 | + } |
|
1751 | + $mask = array('mask' => array()); |
|
1752 | + foreach (array_keys($previous_field['columns']) as $column_name) { |
|
1753 | 1753 | // The basic mask will empty the dropped columns. |
1754 | 1754 | if (isset($dropped['columns']) && in_array($column_name, $dropped['columns'])) { |
1755 | - $mask['mask'][$column_name] = NULL; |
|
1755 | + $mask['mask'][$column_name] = NULL; |
|
1756 | 1756 | } |
1757 | 1757 | // Over the delta we'll empty all columns. |
1758 | 1758 | if (isset($dropped['delta'])) { |
1759 | - $mask['alt_mask'][$column_name] = NULL; |
|
1759 | + $mask['alt_mask'][$column_name] = NULL; |
|
1760 | + } |
|
1760 | 1761 | } |
1761 | - } |
|
1762 | - if (isset($dropped['delta'])) { |
|
1762 | + if (isset($dropped['delta'])) { |
|
1763 | 1763 | $mask['delta'] = $dropped['delta']; |
1764 | - } |
|
1765 | - return $mask; |
|
1764 | + } |
|
1765 | + return $mask; |
|
1766 | 1766 | } |
1767 | 1767 | |
1768 | 1768 | /** |
@@ -1785,36 +1785,36 @@ discard block |
||
1785 | 1785 | * ), |
1786 | 1786 | */ |
1787 | 1787 | function content_field_batch_update($updates, &$context) { |
1788 | - if (empty($field)) { |
|
1788 | + if (empty($field)) { |
|
1789 | 1789 | $context['finished'] = 1; |
1790 | 1790 | return; |
1791 | - } |
|
1792 | - $field_name = $updates['field_name']; |
|
1793 | - $field = content_fields($field_name); |
|
1791 | + } |
|
1792 | + $field_name = $updates['field_name']; |
|
1793 | + $field = content_fields($field_name); |
|
1794 | 1794 | |
1795 | - if (!isset($context['sandbox']['progress'])) { |
|
1795 | + if (!isset($context['sandbox']['progress'])) { |
|
1796 | 1796 | $db_info = content_database_info($field); |
1797 | 1797 | |
1798 | 1798 | // Might run into non-existent tables when cleaning up a corrupted |
1799 | 1799 | // database, like some of the old content storage changes in the |
1800 | 1800 | // .install files. |
1801 | 1801 | if (!db_table_exists($db_info['table'])) { |
1802 | - return $context['finished'] = 1; |
|
1802 | + return $context['finished'] = 1; |
|
1803 | 1803 | } |
1804 | 1804 | $nodes = array(); |
1805 | 1805 | $result = db_query("SELECT nid FROM {". $db_info['table'] ."}"); |
1806 | 1806 | while ($node = db_fetch_array($result)) { |
1807 | - $nodes[] = $node['nid']; |
|
1807 | + $nodes[] = $node['nid']; |
|
1808 | 1808 | } |
1809 | 1809 | $context['sandbox']['progress'] = 0; |
1810 | 1810 | $context['sandbox']['max'] = count($nodes); |
1811 | 1811 | $context['sandbox']['nodes'] = $nodes; |
1812 | - } |
|
1812 | + } |
|
1813 | 1813 | |
1814 | - // Process nodes by groups of 5. |
|
1815 | - $count = min(5, count($context['sandbox']['nodes'])); |
|
1814 | + // Process nodes by groups of 5. |
|
1815 | + $count = min(5, count($context['sandbox']['nodes'])); |
|
1816 | 1816 | |
1817 | - for ($i = 1; $i <= $count; $i++) { |
|
1817 | + for ($i = 1; $i <= $count; $i++) { |
|
1818 | 1818 | // For each nid, load the node, empty the column values |
1819 | 1819 | // or the whole field, and re-save it. |
1820 | 1820 | $nid = array_shift($context['sandbox']['nodes']); |
@@ -1826,13 +1826,13 @@ discard block |
||
1826 | 1826 | // Update our progress information. |
1827 | 1827 | $context['sandbox']['progress']++; |
1828 | 1828 | $context['message'] = t('Processing %title', array('%title' => $node->title)); |
1829 | - } |
|
1829 | + } |
|
1830 | 1830 | |
1831 | - // Inform the batch engine that we are not finished, |
|
1832 | - // and provide an estimation of the completion level we reached. |
|
1833 | - if ($context['sandbox']['progress'] != $context['sandbox']['max']) { |
|
1831 | + // Inform the batch engine that we are not finished, |
|
1832 | + // and provide an estimation of the completion level we reached. |
|
1833 | + if ($context['sandbox']['progress'] != $context['sandbox']['max']) { |
|
1834 | 1834 | $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; |
1835 | - } |
|
1835 | + } |
|
1836 | 1836 | } |
1837 | 1837 | |
1838 | 1838 | /** |
@@ -1869,48 +1869,48 @@ discard block |
||
1869 | 1869 | * ), |
1870 | 1870 | */ |
1871 | 1871 | function content_field_replace($nid, $updates) { |
1872 | - $node = node_load($nid, NULL, TRUE); |
|
1873 | - foreach ($updates as $field_name => $update) { |
|
1872 | + $node = node_load($nid, NULL, TRUE); |
|
1873 | + foreach ($updates as $field_name => $update) { |
|
1874 | 1874 | $items = isset($node->$field_name) ? $node->$field_name : array(); |
1875 | 1875 | foreach ($items as $delta => $value) { |
1876 | - $field_mask = (isset($update['delta']) && isset($update['alt_mask']) && $delta >= $update['delta']) ? $update['alt_mask'] : $mask['mask']; |
|
1877 | - // Merge the mask into the field values to do the replacements. |
|
1878 | - $items[$delta] = array_merge($items[$delta], $field_mask); |
|
1876 | + $field_mask = (isset($update['delta']) && isset($update['alt_mask']) && $delta >= $update['delta']) ? $update['alt_mask'] : $mask['mask']; |
|
1877 | + // Merge the mask into the field values to do the replacements. |
|
1878 | + $items[$delta] = array_merge($items[$delta], $field_mask); |
|
1879 | 1879 | } |
1880 | 1880 | // Test if the new values will make items qualify as empty. |
1881 | 1881 | $items = content_set_empty($field, $items); |
1882 | 1882 | $node->$field_name = $items; |
1883 | - } |
|
1884 | - node_save($node); |
|
1885 | - return $node; |
|
1883 | + } |
|
1884 | + node_save($node); |
|
1885 | + return $node; |
|
1886 | 1886 | } |
1887 | 1887 | |
1888 | 1888 | /** |
1889 | 1889 | * Helper form element validator : integer. |
1890 | 1890 | */ |
1891 | 1891 | function _element_validate_integer($element, &$form_state) { |
1892 | - $value = $element['#value']; |
|
1893 | - if ($value !== '' && (!is_numeric($value) || intval($value) != $value)) { |
|
1892 | + $value = $element['#value']; |
|
1893 | + if ($value !== '' && (!is_numeric($value) || intval($value) != $value)) { |
|
1894 | 1894 | form_error($element, t('%name must be an integer.', array('%name' => $element['#title']))); |
1895 | - } |
|
1895 | + } |
|
1896 | 1896 | } |
1897 | 1897 | |
1898 | 1898 | /** |
1899 | 1899 | * Helper form element validator : integer > 0. |
1900 | 1900 | */ |
1901 | 1901 | function _element_validate_integer_positive($element, &$form_state) { |
1902 | - $value = $element['#value']; |
|
1903 | - if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value <= 0)) { |
|
1902 | + $value = $element['#value']; |
|
1903 | + if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value <= 0)) { |
|
1904 | 1904 | form_error($element, t('%name must be a positive integer.', array('%name' => $element['#title']))); |
1905 | - } |
|
1905 | + } |
|
1906 | 1906 | } |
1907 | 1907 | |
1908 | 1908 | /** |
1909 | 1909 | * Helper form element validator : number. |
1910 | 1910 | */ |
1911 | 1911 | function _element_validate_number($element, &$form_state) { |
1912 | - $value = $element['#value']; |
|
1913 | - if ($value != '' && !is_numeric($value)) { |
|
1912 | + $value = $element['#value']; |
|
1913 | + if ($value != '' && !is_numeric($value)) { |
|
1914 | 1914 | form_error($element, t('%name must be a number.', array('%name' => $element['#title']))); |
1915 | - } |
|
1915 | + } |
|
1916 | 1916 | } |
@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | // Make the description smaller |
28 | 28 | $row[] = array('data' => filter_xss_admin($type->description), 'class' => 'description'); |
29 | 29 | // Set the edit column. |
30 | - $row[] = array('data' => l(t('edit'), 'admin/content/node-type/'. $type_url_str)); |
|
30 | + $row[] = array('data' => l(t('edit'), 'admin/content/node-type/'.$type_url_str)); |
|
31 | 31 | // Set links for managing fields. |
32 | 32 | // TODO: a hook to allow other content modules to add more stuff? |
33 | - $row[] = array('data' => l(t('manage fields'), 'admin/content/node-type/'. $type_url_str .'/fields')); |
|
33 | + $row[] = array('data' => l(t('manage fields'), 'admin/content/node-type/'.$type_url_str.'/fields')); |
|
34 | 34 | // Set the delete column. |
35 | 35 | if ($type->custom) { |
36 | - $row[] = array('data' => l(t('delete'), 'admin/content/node-type/'. $type_url_str .'/delete')); |
|
36 | + $row[] = array('data' => l(t('delete'), 'admin/content/node-type/'.$type_url_str.'/delete')); |
|
37 | 37 | } |
38 | 38 | else { |
39 | 39 | $row[] = array('data' => ''); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | // Allow external modules alter the table headers and rows. |
47 | 47 | foreach (module_implements('content_types_overview_alter') as $module) { |
48 | - $function = $module .'_content_types_overview_alter'; |
|
48 | + $function = $module.'_content_types_overview_alter'; |
|
49 | 49 | $function($header, $rows); |
50 | 50 | } |
51 | 51 | |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | $rows[] = array(array('data' => t('No content types available.'), 'colspan' => '7', 'class' => 'message')); |
54 | 54 | } |
55 | 55 | |
56 | - return theme('table', $header, $rows) .theme('content_overview_links'); |
|
56 | + return theme('table', $header, $rows).theme('content_overview_links'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function theme_content_overview_links() { |
60 | - return '<div class="content-overview-links">'. l(t('» Add a new content type'), 'admin/content/types/add') .'</div>'; |
|
60 | + return '<div class="content-overview-links">'.l(t('» Add a new content type'), 'admin/content/types/add').'</div>'; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $row[] = t($field_types[$field['type']]['label']); |
79 | 79 | |
80 | 80 | $types = array(); |
81 | - $result = db_query("SELECT nt.name, nt.type FROM {". content_instance_tablename() ."} nfi ". |
|
81 | + $result = db_query("SELECT nt.name, nt.type FROM {".content_instance_tablename()."} nfi ". |
|
82 | 82 | "LEFT JOIN {node_type} nt ON nt.type = nfi.type_name ". |
83 | 83 | "WHERE nfi.field_name = '%s' ". |
84 | 84 | // Keep disabled modules out of table. |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | "ORDER BY nt.name ASC", $field['field_name']); |
87 | 87 | while ($type = db_fetch_array($result)) { |
88 | 88 | $content_type = content_types($type['type']); |
89 | - $types[] = l($type['name'], 'admin/content/node-type/'. $content_type['url_str'] .'/fields'); |
|
89 | + $types[] = l($type['name'], 'admin/content/node-type/'.$content_type['url_str'].'/fields'); |
|
90 | 90 | } |
91 | 91 | $row[] = implode(', ', $types); |
92 | 92 | |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | 'label' => array('#value' => check_plain($field['widget']['label'])), |
174 | 174 | 'field_name' => array('#value' => $field['field_name']), |
175 | 175 | 'type' => array('#value' => t($field_types[$field['type']]['label'])), |
176 | - 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'])), |
|
177 | - 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/remove')), |
|
176 | + 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'.$type['url_str'].'/fields/'.$field['field_name'])), |
|
177 | + 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'.$type['url_str'].'/fields/'.$field['field_name'].'/remove')), |
|
178 | 178 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
179 | 179 | 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
180 | 180 | 'prev_parent' => array('#type' => 'hidden', '#value' => ''), |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | 'label' => array('#value' => check_plain($group['label'])), |
200 | 200 | 'group_name' => array('#value' => $group['group_name']), |
201 | 201 | 'group_type' => array('#value' => t($group_types[$group['group_type']])), |
202 | - 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'])), |
|
203 | - 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'] .'/remove')), |
|
202 | + 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'.$type['url_str'].'/groups/'.$group['group_name'])), |
|
203 | + 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'.$type['url_str'].'/groups/'.$group['group_name'].'/remove')), |
|
204 | 204 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
205 | 205 | 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
206 | 206 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $group['group_name']), |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | 'type' => array( |
267 | 267 | '#type' => 'select', |
268 | 268 | '#options' => $field_type_options, |
269 | - '#description' => theme('advanced_help_topic', 'content', 'fields') . t('Type of data to store.'), |
|
269 | + '#description' => theme('advanced_help_topic', 'content', 'fields').t('Type of data to store.'), |
|
270 | 270 | ), |
271 | 271 | 'widget_type' => array( |
272 | 272 | '#type' => 'select', |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | |
398 | 398 | // Add the 'field_' prefix. |
399 | 399 | if (substr($field_name, 0, 6) != 'field_') { |
400 | - $field_name = 'field_'. $field_name; |
|
400 | + $field_name = 'field_'.$field_name; |
|
401 | 401 | form_set_value($form['_add_new_field']['field_name'], $field_name, $form_state); |
402 | 402 | } |
403 | 403 | |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | foreach ($form_values as $key => $values) { |
495 | 495 | // Groups are handled in fieldgroup_content_overview_form_submit(). |
496 | 496 | if (in_array($key, $form['#fields'])) { |
497 | - db_query("UPDATE {". content_instance_tablename() ."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", |
|
497 | + db_query("UPDATE {".content_instance_tablename()."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", |
|
498 | 498 | $values['weight'], $type_name, $key); |
499 | 499 | } |
500 | 500 | elseif (in_array($key, $form['#extra'])) { |
@@ -503,10 +503,10 @@ discard block |
||
503 | 503 | } |
504 | 504 | |
505 | 505 | if ($extra) { |
506 | - variable_set('content_extra_weights_'. $type_name, $extra); |
|
506 | + variable_set('content_extra_weights_'.$type_name, $extra); |
|
507 | 507 | } |
508 | 508 | else { |
509 | - variable_del('content_extra_weights_'. $type_name); |
|
509 | + variable_del('content_extra_weights_'.$type_name); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | content_clear_type_cache(); |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | if (content_field_instance_create($field)) { |
523 | 523 | // Store new field information for fieldgroup submit handler. |
524 | 524 | $form_state['fields_added']['_add_new_field'] = $field['field_name']; |
525 | - $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
|
525 | + $destinations[] = 'admin/content/node-type/'.$type['url_str'].'/fields/'.$field['field_name']; |
|
526 | 526 | } |
527 | 527 | else { |
528 | 528 | drupal_set_message(t('There was a problem creating field %label.', array( |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | if (content_field_instance_create($field)) { |
545 | 545 | // Store new field information for fieldgroup submit handler. |
546 | 546 | $form_state['fields_added']['_add_existing_field'] = $field['field_name']; |
547 | - $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
|
547 | + $destinations[] = 'admin/content/node-type/'.$type['url_str'].'/fields/'.$field['field_name']; |
|
548 | 548 | } |
549 | 549 | else { |
550 | 550 | drupal_set_message(t('There was a problem adding field %label.', array('%label' => $field['field_name']))); |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | |
591 | 591 | if (empty($fields)) { |
592 | 592 | drupal_set_message(t('There are no fields configured for this content type. You can add new fields on the <a href="@link">Manage fields</a> page.', array( |
593 | - '@link' => url('admin/content/node-type/'. $type['url_str'] .'/fields'))), 'warning'); |
|
593 | + '@link' => url('admin/content/node-type/'.$type['url_str'].'/fields'))), 'warning'); |
|
594 | 594 | return $form; |
595 | 595 | } |
596 | 596 | |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | if (!isset($type['fields'][$field['field_name']]) && !$field['locked']) { |
784 | 784 | $field_type = $field_types[$field['type']]; |
785 | 785 | $text = t('@type: @field (@label)', array('@type' => t($field_type['label']), '@label' => t($field['widget']['label']), '@field' => $field['field_name'])); |
786 | - $options[$field['field_name']] = (drupal_strlen($text) > 80) ? truncate_utf8($text, 77) . '...' : $text; |
|
786 | + $options[$field['field_name']] = (drupal_strlen($text) > 80) ? truncate_utf8($text, 77).'...' : $text; |
|
787 | 787 | } |
788 | 788 | } |
789 | 789 | // Sort the list by type, then by field name, then by label. |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | } |
886 | 886 | |
887 | 887 | $type = content_types($form_values['type_name']); |
888 | - $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $form_values['field_name']; |
|
888 | + $form_state['redirect'] = 'admin/content/node-type/'.$type['url_str'].'/fields/'.$form_values['field_name']; |
|
889 | 889 | $form_state['rebuild'] = FALSE; |
890 | 890 | } |
891 | 891 | |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | |
909 | 909 | $output = confirm_form($form, |
910 | 910 | t('Are you sure you want to remove the field %field?', array('%field' => $field['widget']['label'])), |
911 | - 'admin/content/node-type/'. $type['url_str'] .'/fields', |
|
911 | + 'admin/content/node-type/'.$type['url_str'].'/fields', |
|
912 | 912 | t('If you have any content left in this field, it will be lost. This action cannot be undone.'), |
913 | 913 | t('Remove'), t('Cancel'), |
914 | 914 | 'confirm' |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | '%field' => $field['widget']['label'], |
947 | 947 | '%type' => $type['name']))); |
948 | 948 | } |
949 | - $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; |
|
949 | + $form_state['redirect'] = 'admin/content/node-type/'.$type['url_str'].'/fields'; |
|
950 | 950 | } |
951 | 951 | } |
952 | 952 | |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | '#default_value' => $field['widget']['weight'], |
1043 | 1043 | ); |
1044 | 1044 | |
1045 | - $additions = (array) module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget']); |
|
1045 | + $additions = (array)module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget']); |
|
1046 | 1046 | drupal_alter('widget_settings', $additions, 'form', $field['widget']); |
1047 | 1047 | $form['widget'] = array_merge($form['widget'], $additions); |
1048 | 1048 | |
@@ -1083,7 +1083,7 @@ discard block |
||
1083 | 1083 | ); |
1084 | 1084 | |
1085 | 1085 | // Default value widget. |
1086 | - $widget_form = array('#node' => (object) array('type' => $type_name)); |
|
1086 | + $widget_form = array('#node' => (object)array('type' => $type_name)); |
|
1087 | 1087 | $widget_form_state = array('values' => array($field['field_name'] => $default_value)); |
1088 | 1088 | // Make sure the default value is not a required field. |
1089 | 1089 | $widget_field = $field; |
@@ -1127,7 +1127,7 @@ discard block |
||
1127 | 1127 | $form['widget']['default_value_fieldset']['advanced_options']['markup_default_value_php'] = array( |
1128 | 1128 | '#type' => 'item', |
1129 | 1129 | '#title' => t('Code'), |
1130 | - '#value' => !empty($field['widget']['default_value_php']) ? '<code>'. check_plain($field['widget']['default_value_php']) .'</code>' : t('<none>'), |
|
1130 | + '#value' => !empty($field['widget']['default_value_php']) ? '<code>'.check_plain($field['widget']['default_value_php']).'</code>' : t('<none>'), |
|
1131 | 1131 | '#description' => empty($field['widget']['default_value_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override any value specified above.'), |
1132 | 1132 | ); |
1133 | 1133 | } |
@@ -1145,9 +1145,9 @@ discard block |
||
1145 | 1145 | ); |
1146 | 1146 | $description = t('Maximum number of values users can enter for this field.'); |
1147 | 1147 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
1148 | - $description .= '<br/>'. t("'Unlimited' will provide an 'Add more' button so the users can add as many values as they like."); |
|
1148 | + $description .= '<br/>'.t("'Unlimited' will provide an 'Add more' button so the users can add as many values as they like."); |
|
1149 | 1149 | } |
1150 | - $description .= '<br/><strong>'. t('Warning! Changing this setting after data has been created could result in the loss of data!') .'</strong>'; |
|
1150 | + $description .= '<br/><strong>'.t('Warning! Changing this setting after data has been created could result in the loss of data!').'</strong>'; |
|
1151 | 1151 | $form['field']['multiple'] = array( |
1152 | 1152 | '#type' => 'select', |
1153 | 1153 | '#title' => t('Number of values'), |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | '#value' => serialize($field), |
1162 | 1162 | ); |
1163 | 1163 | |
1164 | - $additions = (array) module_invoke($field_type['module'], 'field_settings', 'form', $field); |
|
1164 | + $additions = (array)module_invoke($field_type['module'], 'field_settings', 'form', $field); |
|
1165 | 1165 | drupal_alter('field_settings', $additions, 'form', $field); |
1166 | 1166 | $form['field'] = array_merge($form['field'], $additions); |
1167 | 1167 | |
@@ -1290,7 +1290,7 @@ discard block |
||
1290 | 1290 | $node = array(); |
1291 | 1291 | $node[$form_values['field_name']] = $default_value; |
1292 | 1292 | $field['required'] = FALSE; |
1293 | - $field_function = $field_type['module'] .'_field'; |
|
1293 | + $field_function = $field_type['module'].'_field'; |
|
1294 | 1294 | |
1295 | 1295 | $errors_before = form_get_errors(); |
1296 | 1296 | |
@@ -1341,7 +1341,7 @@ discard block |
||
1341 | 1341 | else { |
1342 | 1342 | drupal_set_message(t('Saved field %label.', array('%label' => $form_values['label']))); |
1343 | 1343 | $type = content_types($form_values['type_name']); |
1344 | - $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; |
|
1344 | + $form_state['redirect'] = 'admin/content/node-type/'.$type['url_str'].'/fields'; |
|
1345 | 1345 | } |
1346 | 1346 | } |
1347 | 1347 | |
@@ -1518,7 +1518,7 @@ discard block |
||
1518 | 1518 | // drop all delta values higher than the new maximum delta value. |
1519 | 1519 | // Not needed if the new multiple is unlimited or if the new table is the content table. |
1520 | 1520 | if ($new_table != $base_tablename && $new_field['multiple'] < $previous_field['multiple'] && $new_field['multiple'] != 1) { |
1521 | - db_query("DELETE FROM {". $new_table ."} WHERE delta >= ". max(1, $new_field['multiple'])); |
|
1521 | + db_query("DELETE FROM {".$new_table."} WHERE delta >= ".max(1, $new_field['multiple'])); |
|
1522 | 1522 | } |
1523 | 1523 | |
1524 | 1524 | // If going from multiple to non-multiple, make sure the field tables have |
@@ -1548,12 +1548,12 @@ discard block |
||
1548 | 1548 | $new_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
1549 | 1549 | $columns = array_keys($migrate_columns); |
1550 | 1550 | if ($new_field['multiple']) { |
1551 | - db_query('INSERT INTO {'. $new_table .'} (vid, nid, delta, '. implode(', ', $columns) .') '. |
|
1552 | - ' SELECT vid, nid, 0, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
|
1551 | + db_query('INSERT INTO {'.$new_table.'} (vid, nid, delta, '.implode(', ', $columns).') '. |
|
1552 | + ' SELECT vid, nid, 0, '.implode(', ', $columns).' FROM {'.$previous_table.'}'); |
|
1553 | 1553 | } |
1554 | 1554 | else { |
1555 | - db_query('INSERT INTO {'. $new_table .'} (vid, nid, '. implode(', ', $columns) .') '. |
|
1556 | - ' SELECT vid, nid, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
|
1555 | + db_query('INSERT INTO {'.$new_table.'} (vid, nid, '.implode(', ', $columns).') '. |
|
1556 | + ' SELECT vid, nid, '.implode(', ', $columns).' FROM {'.$previous_table.'}'); |
|
1557 | 1557 | } |
1558 | 1558 | foreach ($columns as $column_name) { |
1559 | 1559 | db_drop_field($ret, $previous_table, $column_name); |
@@ -1567,10 +1567,10 @@ discard block |
||
1567 | 1567 | // rebuild the schema now. |
1568 | 1568 | content_alter_db_cleanup(); |
1569 | 1569 | if ($previous_field['multiple']) { |
1570 | - $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE delta = 0 AND n.type = '%s'", $new_field['type_name']); |
|
1570 | + $result = db_query("SELECT * FROM {".$previous_table."} c JOIN {node} n ON c.nid = n.nid WHERE delta = 0 AND n.type = '%s'", $new_field['type_name']); |
|
1571 | 1571 | } |
1572 | 1572 | else { |
1573 | - $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s'", $new_field['type_name']); |
|
1573 | + $result = db_query("SELECT * FROM {".$previous_table."} c JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s'", $new_field['type_name']); |
|
1574 | 1574 | } |
1575 | 1575 | $record = array(); |
1576 | 1576 | while ($data = db_fetch_array($result)) { |
@@ -1591,7 +1591,7 @@ discard block |
||
1591 | 1591 | } |
1592 | 1592 | } |
1593 | 1593 | } |
1594 | - if (db_result(db_query('SELECT COUNT(*) FROM {'. $new_table . |
|
1594 | + if (db_result(db_query('SELECT COUNT(*) FROM {'.$new_table. |
|
1595 | 1595 | '} WHERE vid = %d AND nid = %d', $data['vid'], $data['nid']))) { |
1596 | 1596 | $keys = $new_field['multiple'] ? array('vid', 'delta') : array('vid'); |
1597 | 1597 | drupal_write_record($new_table, $record, $keys); |
@@ -1656,12 +1656,12 @@ discard block |
||
1656 | 1656 | // Group rows: account for weight. |
1657 | 1657 | if (module_exists('fieldgroup')) { |
1658 | 1658 | foreach ($group_rows as $name) { |
1659 | - $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name .' '); |
|
1659 | + $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name.' '); |
|
1660 | 1660 | } |
1661 | 1661 | } |
1662 | 1662 | // Field rows : account for weight and parenting. |
1663 | 1663 | foreach ($field_rows as $name) { |
1664 | - $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name .' '); |
|
1664 | + $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name.' '); |
|
1665 | 1665 | if (module_exists('fieldgroup')) { |
1666 | 1666 | if ($parent = $form[$name]['parent']['#value']) { |
1667 | 1667 | $form[$name]['#depth'] = 1; |
@@ -1706,7 +1706,7 @@ discard block |
||
1706 | 1706 | 'finished' => '_content_alter_fields_finished', |
1707 | 1707 | 'title' => t('Processing'), |
1708 | 1708 | 'error_message' => t('The update has encountered an error.'), |
1709 | - 'file' => './'. drupal_get_path('module', 'content') .'/includes/content.admin.inc', |
|
1709 | + 'file' => './'.drupal_get_path('module', 'content').'/includes/content.admin.inc', |
|
1710 | 1710 | ); |
1711 | 1711 | batch_set($batch); |
1712 | 1712 | if (!empty($url)) { |
@@ -1802,7 +1802,7 @@ discard block |
||
1802 | 1802 | return $context['finished'] = 1; |
1803 | 1803 | } |
1804 | 1804 | $nodes = array(); |
1805 | - $result = db_query("SELECT nid FROM {". $db_info['table'] ."}"); |
|
1805 | + $result = db_query("SELECT nid FROM {".$db_info['table']."}"); |
|
1806 | 1806 | while ($node = db_fetch_array($result)) { |
1807 | 1807 | $nodes[] = $node['nid']; |
1808 | 1808 | } |
@@ -1821,7 +1821,7 @@ discard block |
||
1821 | 1821 | $node = content_field_replace($nid, array($updates)); |
1822 | 1822 | |
1823 | 1823 | // Store result for post-processing in the finished callback. |
1824 | - $context['results'][] = l($node->title, 'node/'. $node->nid); |
|
1824 | + $context['results'][] = l($node->title, 'node/'.$node->nid); |
|
1825 | 1825 | |
1826 | 1826 | // Update our progress information. |
1827 | 1827 | $context['sandbox']['progress']++; |
@@ -1831,7 +1831,7 @@ discard block |
||
1831 | 1831 | // Inform the batch engine that we are not finished, |
1832 | 1832 | // and provide an estimation of the completion level we reached. |
1833 | 1833 | if ($context['sandbox']['progress'] != $context['sandbox']['max']) { |
1834 | - $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; |
|
1834 | + $context['finished'] = $context['sandbox']['progress']/$context['sandbox']['max']; |
|
1835 | 1835 | } |
1836 | 1836 | } |
1837 | 1837 |
@@ -34,8 +34,7 @@ discard block |
||
34 | 34 | // Set the delete column. |
35 | 35 | if ($type->custom) { |
36 | 36 | $row[] = array('data' => l(t('delete'), 'admin/content/node-type/'. $type_url_str .'/delete')); |
37 | - } |
|
38 | - else { |
|
37 | + } else { |
|
39 | 38 | $row[] = array('data' => ''); |
40 | 39 | } |
41 | 40 | |
@@ -94,8 +93,7 @@ discard block |
||
94 | 93 | } |
95 | 94 | if (empty($rows)) { |
96 | 95 | $output = t('No fields have been defined for any content type yet.'); |
97 | - } |
|
98 | - else { |
|
96 | + } else { |
|
99 | 97 | $output = theme('table', $header, $rows); |
100 | 98 | } |
101 | 99 | return $output; |
@@ -496,16 +494,14 @@ discard block |
||
496 | 494 | if (in_array($key, $form['#fields'])) { |
497 | 495 | db_query("UPDATE {". content_instance_tablename() ."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", |
498 | 496 | $values['weight'], $type_name, $key); |
499 | - } |
|
500 | - elseif (in_array($key, $form['#extra'])) { |
|
497 | + } elseif (in_array($key, $form['#extra'])) { |
|
501 | 498 | $extra[$key] = $values['weight']; |
502 | 499 | } |
503 | 500 | } |
504 | 501 | |
505 | 502 | if ($extra) { |
506 | 503 | variable_set('content_extra_weights_'. $type_name, $extra); |
507 | - } |
|
508 | - else { |
|
504 | + } else { |
|
509 | 505 | variable_del('content_extra_weights_'. $type_name); |
510 | 506 | } |
511 | 507 | |
@@ -523,8 +519,7 @@ discard block |
||
523 | 519 | // Store new field information for fieldgroup submit handler. |
524 | 520 | $form_state['fields_added']['_add_new_field'] = $field['field_name']; |
525 | 521 | $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
526 | - } |
|
527 | - else { |
|
522 | + } else { |
|
528 | 523 | drupal_set_message(t('There was a problem creating field %label.', array( |
529 | 524 | '%label' => $field['label']))); |
530 | 525 | } |
@@ -538,15 +533,13 @@ discard block |
||
538 | 533 | |
539 | 534 | if ($existing_field['locked']) { |
540 | 535 | drupal_set_message(t('The field %label cannot be added to a content type because it is locked.', array('%label' => $field['field_name']))); |
541 | - } |
|
542 | - else { |
|
536 | + } else { |
|
543 | 537 | module_load_include('inc', 'content', 'includes/content.crud'); |
544 | 538 | if (content_field_instance_create($field)) { |
545 | 539 | // Store new field information for fieldgroup submit handler. |
546 | 540 | $form_state['fields_added']['_add_existing_field'] = $field['field_name']; |
547 | 541 | $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
548 | - } |
|
549 | - else { |
|
542 | + } else { |
|
550 | 543 | drupal_set_message(t('There was a problem adding field %label.', array('%label' => $field['field_name']))); |
551 | 544 | } |
552 | 545 | } |
@@ -756,16 +749,14 @@ discard block |
||
756 | 749 | |
757 | 750 | if ($field_type) { |
758 | 751 | return !empty($options[$field_type]) ? $options[$field_type] : array(); |
759 | - } |
|
760 | - elseif ($by_label) { |
|
752 | + } elseif ($by_label) { |
|
761 | 753 | $field_types = _content_field_types(); |
762 | 754 | $options_by_label = array(); |
763 | 755 | foreach ($options as $field_type => $widgets) { |
764 | 756 | $options_by_label[t($field_types[$field_type]['label'])] = $widgets; |
765 | 757 | } |
766 | 758 | return $options_by_label; |
767 | - } |
|
768 | - else { |
|
759 | + } else { |
|
769 | 760 | return $options; |
770 | 761 | } |
771 | 762 | } |
@@ -878,8 +869,7 @@ discard block |
||
878 | 869 | if (content_field_instance_update($field)) { |
879 | 870 | drupal_set_message(t('Updated basic settings for field %label.', array( |
880 | 871 | '%label' => $label))); |
881 | - } |
|
882 | - else { |
|
872 | + } else { |
|
883 | 873 | drupal_set_message(t('There was a problem updating the basic settings for field %label.', array( |
884 | 874 | '%label' => $label))); |
885 | 875 | } |
@@ -940,8 +930,7 @@ discard block |
||
940 | 930 | drupal_set_message(t('Removed field %field from %type.', array( |
941 | 931 | '%field' => $field['widget']['label'], |
942 | 932 | '%type' => $type['name']))); |
943 | - } |
|
944 | - else { |
|
933 | + } else { |
|
945 | 934 | drupal_set_message(t('There was a problem deleting %field from %type.', array( |
946 | 935 | '%field' => $field['widget']['label'], |
947 | 936 | '%type' => $type['name']))); |
@@ -1122,8 +1111,7 @@ discard block |
||
1122 | 1111 | '@link_devel' => 'http://www.drupal.org/project/devel', |
1123 | 1112 | '%type' => $type_name)), |
1124 | 1113 | ); |
1125 | - } |
|
1126 | - else { |
|
1114 | + } else { |
|
1127 | 1115 | $form['widget']['default_value_fieldset']['advanced_options']['markup_default_value_php'] = array( |
1128 | 1116 | '#type' => 'item', |
1129 | 1117 | '#title' => t('Code'), |
@@ -1248,8 +1236,7 @@ discard block |
||
1248 | 1236 | ob_end_clean(); |
1249 | 1237 | if (!is_array($return)) { |
1250 | 1238 | $error = TRUE; |
1251 | - } |
|
1252 | - else { |
|
1239 | + } else { |
|
1253 | 1240 | foreach ($return as $item) { |
1254 | 1241 | if (!is_array($item)) { |
1255 | 1242 | $error = TRUE; |
@@ -1269,15 +1256,13 @@ discard block |
||
1269 | 1256 | '!sample' => $sample, |
1270 | 1257 | '@value' => print_r($return, TRUE)))); |
1271 | 1258 | return; |
1272 | - } |
|
1273 | - else { |
|
1259 | + } else { |
|
1274 | 1260 | $default_value = $return; |
1275 | 1261 | $is_code = TRUE; |
1276 | 1262 | form_set_value(array('#parents' => array('default_value_php')), $php, $form_state); |
1277 | 1263 | form_set_value(array('#parents' => array('default_value')), array(), $form_state); |
1278 | 1264 | } |
1279 | - } |
|
1280 | - elseif (!empty($form_values['default_value_widget'])) { |
|
1265 | + } elseif (!empty($form_values['default_value_widget'])) { |
|
1281 | 1266 | // Fields that handle their own multiple values may use an expected |
1282 | 1267 | // value as the top-level key, so just pop off the top element. |
1283 | 1268 | $key = array_shift(array_keys($form_values['default_value_widget'])); |
@@ -1306,8 +1291,7 @@ discard block |
||
1306 | 1291 | if (trim($form_values['default_value_php'])) { |
1307 | 1292 | form_set_error('default_value_php', t("The PHP code for 'default value' returned @value, which is invalid.", array( |
1308 | 1293 | '@value' => print_r($default_value, TRUE)))); |
1309 | - } |
|
1310 | - else { |
|
1294 | + } else { |
|
1311 | 1295 | form_set_error('default_value', t('The default value is invalid.')); |
1312 | 1296 | } |
1313 | 1297 | } |
@@ -1337,8 +1321,7 @@ discard block |
||
1337 | 1321 | if ($destinations) { |
1338 | 1322 | drupal_set_message(t('Added field %label.', array('%label' => $form_values['label']))); |
1339 | 1323 | $form_state['redirect'] = content_get_destinations($destinations); |
1340 | - } |
|
1341 | - else { |
|
1324 | + } else { |
|
1342 | 1325 | drupal_set_message(t('Saved field %label.', array('%label' => $form_values['label']))); |
1343 | 1326 | $type = content_types($form_values['type_name']); |
1344 | 1327 | $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; |
@@ -1455,8 +1438,7 @@ discard block |
||
1455 | 1438 | if (empty($new_field)) { |
1456 | 1439 | if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
1457 | 1440 | db_drop_table($ret, $previous_table); |
1458 | - } |
|
1459 | - else { |
|
1441 | + } else { |
|
1460 | 1442 | foreach ($previous_schema['fields'] as $column => $attributes) { |
1461 | 1443 | if (!in_array($column, array('nid', 'vid', 'delta'))) { |
1462 | 1444 | db_drop_field($ret, $previous_table, $column); |
@@ -1478,8 +1460,7 @@ discard block |
||
1478 | 1460 | // Create new table and columns, if not already created. |
1479 | 1461 | if (!db_table_exists($new_table)) { |
1480 | 1462 | db_create_table($ret, $new_table, $new_schema); |
1481 | - } |
|
1482 | - else { |
|
1463 | + } else { |
|
1483 | 1464 | // Or add fields and/or indexes to an existing table. |
1484 | 1465 | foreach ($new_schema['fields'] as $column => $attributes) { |
1485 | 1466 | if (!in_array($column, array('nid', 'vid', 'delta'))) { |
@@ -1530,8 +1511,7 @@ discard block |
||
1530 | 1511 | db_drop_field($ret, $new_table, 'delta'); |
1531 | 1512 | db_drop_primary_key($ret, $new_table); |
1532 | 1513 | db_add_primary_key($ret, $new_table, array('vid')); |
1533 | - } |
|
1534 | - else if ($previous_field['multiple'] == 0 && $new_field['multiple'] > 0) { |
|
1514 | + } else if ($previous_field['multiple'] == 0 && $new_field['multiple'] > 0) { |
|
1535 | 1515 | db_add_field($ret, $new_table, 'delta', array( |
1536 | 1516 | 'type' => 'int', |
1537 | 1517 | 'unsigned' => TRUE, |
@@ -1550,8 +1530,7 @@ discard block |
||
1550 | 1530 | if ($new_field['multiple']) { |
1551 | 1531 | db_query('INSERT INTO {'. $new_table .'} (vid, nid, delta, '. implode(', ', $columns) .') '. |
1552 | 1532 | ' SELECT vid, nid, 0, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
1553 | - } |
|
1554 | - else { |
|
1533 | + } else { |
|
1555 | 1534 | db_query('INSERT INTO {'. $new_table .'} (vid, nid, '. implode(', ', $columns) .') '. |
1556 | 1535 | ' SELECT vid, nid, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
1557 | 1536 | } |
@@ -1568,8 +1547,7 @@ discard block |
||
1568 | 1547 | content_alter_db_cleanup(); |
1569 | 1548 | if ($previous_field['multiple']) { |
1570 | 1549 | $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE delta = 0 AND n.type = '%s'", $new_field['type_name']); |
1571 | - } |
|
1572 | - else { |
|
1550 | + } else { |
|
1573 | 1551 | $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s'", $new_field['type_name']); |
1574 | 1552 | } |
1575 | 1553 | $record = array(); |
@@ -1582,8 +1560,7 @@ discard block |
||
1582 | 1560 | foreach ($migrate_columns as $column => $attributes) { |
1583 | 1561 | if (is_null($data[$column])) { |
1584 | 1562 | $record[$column] = NULL; |
1585 | - } |
|
1586 | - else { |
|
1563 | + } else { |
|
1587 | 1564 | $record[$column] = $data[$column]; |
1588 | 1565 | // Prevent double serializtion in drupal_write_record. |
1589 | 1566 | if (isset($attributes['serialize']) && $attributes['serialize']) { |
@@ -1595,8 +1572,7 @@ discard block |
||
1595 | 1572 | '} WHERE vid = %d AND nid = %d', $data['vid'], $data['nid']))) { |
1596 | 1573 | $keys = $new_field['multiple'] ? array('vid', 'delta') : array('vid'); |
1597 | 1574 | drupal_write_record($new_table, $record, $keys); |
1598 | - } |
|
1599 | - else { |
|
1575 | + } else { |
|
1600 | 1576 | drupal_write_record($new_table, $record); |
1601 | 1577 | } |
1602 | 1578 | } |
@@ -1720,8 +1696,7 @@ discard block |
||
1720 | 1696 | function _content_alter_fields_finished($success, $results, $operations) { |
1721 | 1697 | if ($success) { |
1722 | 1698 | drupal_set_message(t('The database has been altered and data has been migrated or deleted.')); |
1723 | - } |
|
1724 | - else { |
|
1699 | + } else { |
|
1725 | 1700 | drupal_set_message(t('An error occurred and database alteration did not complete.'), 'error'); |
1726 | 1701 | $message = format_plural(count($results), '1 item successfully processed:', '@count items successfully processed:'); |
1727 | 1702 | $message .= theme('item_list', $results); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $weights = array(); |
158 | 158 | |
159 | 159 | $form = array( |
160 | - '#tree' => TRUE, |
|
160 | + '#tree' => true, |
|
161 | 161 | '#type_name' => $type['type'], |
162 | 162 | '#fields' => array_keys($fields), |
163 | 163 | '#groups' => array_keys($groups), |
@@ -179,14 +179,14 @@ discard block |
||
179 | 179 | 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
180 | 180 | 'prev_parent' => array('#type' => 'hidden', '#value' => ''), |
181 | 181 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $field['field_name']), |
182 | - '#leaf' => TRUE, |
|
182 | + '#leaf' => true, |
|
183 | 183 | '#row_type' => 'field', |
184 | 184 | 'field' => array('#type' => 'value', '#value' => $field), |
185 | 185 | ); |
186 | 186 | if ($field['locked']) { |
187 | 187 | $form[$name]['configure'] = array('#value' => t('Locked')); |
188 | 188 | $form[$name]['remove'] = array(); |
189 | - $form[$name]['#disabled_row'] = TRUE; |
|
189 | + $form[$name]['#disabled_row'] = true; |
|
190 | 190 | } |
191 | 191 | $form['#field_rows'][] = $name; |
192 | 192 | $weights[] = $weight; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
205 | 205 | 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
206 | 206 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $group['group_name']), |
207 | - '#root' => TRUE, |
|
207 | + '#root' => true, |
|
208 | 208 | '#row_type' => 'group', |
209 | 209 | 'group' => array('#type' => 'value', '#value' => $group), |
210 | 210 | ); |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | 'configure' => array('#value' => isset($extra[$name]['configure']) ? $extra[$name]['configure'] : ''), |
229 | 229 | 'remove' => array('#value' => isset($extra[$name]['remove']) ? $extra[$name]['remove'] : ''), |
230 | 230 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
231 | - '#leaf' => TRUE, |
|
232 | - '#root' => TRUE, |
|
233 | - '#disabled_row' => TRUE, |
|
231 | + '#leaf' => true, |
|
232 | + '#root' => true, |
|
233 | + '#disabled_row' => true, |
|
234 | 234 | '#row_type' => 'extra', |
235 | 235 | ); |
236 | 236 | $form['#field_rows'][] = $name; |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | // Additional row : add new field. |
241 | 241 | $weight = max($weights) + 1; |
242 | 242 | $field_type_options = content_field_type_options(); |
243 | - $widget_type_options = content_widget_type_options(NULL, TRUE); |
|
243 | + $widget_type_options = content_widget_type_options(null, true); |
|
244 | 244 | if ($field_type_options && $widget_type_options) { |
245 | 245 | array_unshift($field_type_options, t('- Select a field type -')); |
246 | 246 | array_unshift($widget_type_options, t('- Select a widget -')); |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
277 | 277 | 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
278 | 278 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
279 | - '#leaf' => TRUE, |
|
280 | - '#add_new' => TRUE, |
|
279 | + '#leaf' => true, |
|
280 | + '#add_new' => true, |
|
281 | 281 | '#row_type' => 'add_new_field', |
282 | 282 | ); |
283 | 283 | $form['#field_rows'][] = $name; |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
309 | 309 | 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
310 | 310 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
311 | - '#leaf' => TRUE, |
|
312 | - '#add_new' => TRUE, |
|
311 | + '#leaf' => true, |
|
312 | + '#add_new' => true, |
|
313 | 313 | '#row_type' => 'add_existing_field', |
314 | 314 | ); |
315 | 315 | $form['#field_rows'][] = $name; |
@@ -348,8 +348,8 @@ discard block |
||
348 | 348 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
349 | 349 | 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
350 | 350 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
351 | - '#root' => TRUE, |
|
352 | - '#add_new' => TRUE, |
|
351 | + '#root' => true, |
|
352 | + '#add_new' => true, |
|
353 | 353 | '#row_type' => 'add_new_group', |
354 | 354 | ); |
355 | 355 | if (count($group_types) > 1) { |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | // Field name already exists. |
417 | 417 | // We need to check inactive fields as well, so we can't use content_fields(). |
418 | 418 | module_load_include('inc', 'content', 'includes/content.crud'); |
419 | - $fields = content_field_instance_read(array(), TRUE); |
|
420 | - $used = FALSE; |
|
419 | + $fields = content_field_instance_read(array(), true); |
|
420 | + $used = false; |
|
421 | 421 | foreach ($fields as $existing_field) { |
422 | 422 | $used |= ($existing_field['field_name'] == $field_name); |
423 | 423 | } |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | $contexts = content_build_modes($contexts_selector); |
582 | 582 | |
583 | 583 | $form = array( |
584 | - '#tree' => TRUE, |
|
584 | + '#tree' => true, |
|
585 | 585 | '#type_name' => $type['type'], |
586 | 586 | '#fields' => array_keys($fields), |
587 | 587 | '#groups' => array_keys($groups), |
@@ -704,12 +704,12 @@ discard block |
||
704 | 704 | $field = content_fields($key, $form['#type_name']); |
705 | 705 | // We have some numeric keys here, so we can't use array_merge. |
706 | 706 | $field['display_settings'] = $values + $field['display_settings']; |
707 | - content_field_instance_update($field, FALSE); |
|
707 | + content_field_instance_update($field, false); |
|
708 | 708 | } |
709 | 709 | } |
710 | 710 | |
711 | 711 | // Clear caches and rebuild menu. |
712 | - content_clear_type_cache(TRUE); |
|
712 | + content_clear_type_cache(true); |
|
713 | 713 | menu_rebuild(); |
714 | 714 | |
715 | 715 | drupal_set_message(t('Your settings have been saved.')); |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | * If no field type is provided, returns a nested array of |
743 | 743 | * all widget types, keyed by field type human name |
744 | 744 | */ |
745 | -function content_widget_type_options($field_type = NULL, $by_label = FALSE) { |
|
745 | +function content_widget_type_options($field_type = null, $by_label = false) { |
|
746 | 746 | static $options; |
747 | 747 | |
748 | 748 | if (!isset($options)) { |
@@ -815,13 +815,13 @@ discard block |
||
815 | 815 | '#type' => 'textfield', |
816 | 816 | '#value' => $field_name, |
817 | 817 | '#description' => t("The machine-readable name of the field. This name cannot be changed."), |
818 | - '#disabled' => TRUE, |
|
818 | + '#disabled' => true, |
|
819 | 819 | ); |
820 | 820 | $form['basic']['label'] = array( |
821 | 821 | '#type' => 'textfield', |
822 | 822 | '#title' => t('Label'), |
823 | 823 | '#default_value' => $label, |
824 | - '#required' => TRUE, |
|
824 | + '#required' => true, |
|
825 | 825 | '#description' => t('A human-readable name to be used as the label for this field in the %type content type.', array('%type' => $type['name'])), |
826 | 826 | ); |
827 | 827 | $form['basic']['type'] = array( |
@@ -830,12 +830,12 @@ discard block |
||
830 | 830 | '#options' => content_field_type_options(), |
831 | 831 | '#default_value' => $field_type, |
832 | 832 | '#description' => t('The type of data you would like to store in the database with this field. This option cannot be changed.'), |
833 | - '#disabled' => TRUE, |
|
833 | + '#disabled' => true, |
|
834 | 834 | ); |
835 | 835 | $form['basic']['widget_type'] = array( |
836 | 836 | '#type' => 'select', |
837 | 837 | '#title' => t('Widget type'), |
838 | - '#required' => TRUE, |
|
838 | + '#required' => true, |
|
839 | 839 | '#options' => content_widget_type_options($field_type), |
840 | 840 | '#default_value' => $form_values['widget_type'], |
841 | 841 | '#description' => t('The type of form element you would like to present to the user when creating this field in the %type content type.', array('%type' => $type['name'])), |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | |
887 | 887 | $type = content_types($form_values['type_name']); |
888 | 888 | $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $form_values['field_name']; |
889 | - $form_state['rebuild'] = FALSE; |
|
889 | + $form_state['rebuild'] = false; |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
@@ -985,7 +985,7 @@ discard block |
||
985 | 985 | |
986 | 986 | // Remove menu tabs when we are in an 'add new' sequence. |
987 | 987 | if ($add_new_sequence) { |
988 | - menu_set_item(NULL, menu_get_item('node')); |
|
988 | + menu_set_item(null, menu_get_item('node')); |
|
989 | 989 | } |
990 | 990 | |
991 | 991 | $form = array(); |
@@ -1002,19 +1002,19 @@ discard block |
||
1002 | 1002 | '#type' => 'textfield', |
1003 | 1003 | '#title' => t('Label'), |
1004 | 1004 | '#value' => $field['widget']['label'], |
1005 | - '#disabled' => TRUE, |
|
1005 | + '#disabled' => true, |
|
1006 | 1006 | ); |
1007 | 1007 | $form['basic']['field_name'] = array( |
1008 | 1008 | '#type' => 'hidden', |
1009 | 1009 | '#title' => t('Field name'), |
1010 | 1010 | '#value' => $field['field_name'], |
1011 | - '#disabled' => TRUE, |
|
1011 | + '#disabled' => true, |
|
1012 | 1012 | ); |
1013 | 1013 | $form['basic']['type'] = array( |
1014 | 1014 | '#type' => 'hidden', |
1015 | 1015 | '#title' => t('Field type'), |
1016 | 1016 | '#value' => $field['type'], |
1017 | - '#disabled' => TRUE, |
|
1017 | + '#disabled' => true, |
|
1018 | 1018 | ); |
1019 | 1019 | $widget_options = content_widget_type_options($field['type']); |
1020 | 1020 | $form['basic']['widget_type'] = array( |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | '#title' => t('Widget type'), |
1023 | 1023 | '#options' => $widget_options, |
1024 | 1024 | '#default_value' => $field['widget']['type'] ? $field['widget']['type'] : key($widget_options), |
1025 | - '#disabled' => TRUE, |
|
1025 | + '#disabled' => true, |
|
1026 | 1026 | ); |
1027 | 1027 | $form['basic']['change'] = array( |
1028 | 1028 | '#type' => 'submit', |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | '#default_value' => $field['widget']['description'], |
1053 | 1053 | '#rows' => 5, |
1054 | 1054 | '#description' => t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => _content_filter_xss_display_allowed_tags())), |
1055 | - '#required' => FALSE, |
|
1055 | + '#required' => false, |
|
1056 | 1056 | ); |
1057 | 1057 | |
1058 | 1058 | // Add handling for default value if not provided by field. |
@@ -1078,8 +1078,8 @@ discard block |
||
1078 | 1078 | $form['widget']['default_value_fieldset'] = array( |
1079 | 1079 | '#type' => 'fieldset', |
1080 | 1080 | '#title' => t('Default value'), |
1081 | - '#collapsible' => TRUE, |
|
1082 | - '#collapsed' => TRUE, |
|
1081 | + '#collapsible' => true, |
|
1082 | + '#collapsed' => true, |
|
1083 | 1083 | ); |
1084 | 1084 | |
1085 | 1085 | // Default value widget. |
@@ -1087,11 +1087,11 @@ discard block |
||
1087 | 1087 | $widget_form_state = array('values' => array($field['field_name'] => $default_value)); |
1088 | 1088 | // Make sure the default value is not a required field. |
1089 | 1089 | $widget_field = $field; |
1090 | - $widget_field['required'] = FALSE; |
|
1090 | + $widget_field['required'] = false; |
|
1091 | 1091 | module_load_include('inc', 'content', 'includes/content.node_form'); |
1092 | 1092 | $form_element = content_field_form($widget_form, $widget_form_state, $widget_field, 0); |
1093 | 1093 | $form['widget']['default_value_fieldset']['default_value_widget'] = $form_element; |
1094 | - $form['widget']['default_value_fieldset']['default_value_widget']['#tree'] = TRUE; |
|
1094 | + $form['widget']['default_value_fieldset']['default_value_widget']['#tree'] = true; |
|
1095 | 1095 | // Set up form info that the default value widget will need to find in the form. |
1096 | 1096 | $form['#field_info'] = array($widget_field['field_name'] => $widget_field); |
1097 | 1097 | |
@@ -1099,7 +1099,7 @@ discard block |
||
1099 | 1099 | $form['widget']['default_value_fieldset']['advanced_options'] = array( |
1100 | 1100 | '#type' => 'fieldset', |
1101 | 1101 | '#title' => t('PHP code'), |
1102 | - '#collapsible' => TRUE, |
|
1102 | + '#collapsible' => true, |
|
1103 | 1103 | '#collapsed' => empty($field['widget']['default_value_php']), |
1104 | 1104 | ); |
1105 | 1105 | |
@@ -1116,7 +1116,7 @@ discard block |
||
1116 | 1116 | '#title' => t('Code'), |
1117 | 1117 | '#default_value' => isset($field['widget']['default_value_php']) ? $field['widget']['default_value_php'] : '', |
1118 | 1118 | '#rows' => 6, |
1119 | - '#tree' => TRUE, |
|
1119 | + '#tree' => true, |
|
1120 | 1120 | '#description' => t('Advanced usage only: PHP code that returns a default value. Should not include <?php ?> delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format: <pre>!sample</pre>To figure out the expected format, you can use the <em>devel load</em> tab provided by <a href="@link_devel">devel module</a> on a %type content page.', array( |
1121 | 1121 | '!sample' => $sample, |
1122 | 1122 | '@link_devel' => 'http://www.drupal.org/project/devel', |
@@ -1236,23 +1236,23 @@ discard block |
||
1236 | 1236 | // If this is a programmed form, get rid of the default value widget, |
1237 | 1237 | // we have the default values already. |
1238 | 1238 | if ($form['#programmed']) { |
1239 | - form_set_value(array('#parents' => array('default_value_widget')), NULL, $form_state); |
|
1239 | + form_set_value(array('#parents' => array('default_value_widget')), null, $form_state); |
|
1240 | 1240 | return; |
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | if (isset($form_values['default_value_php']) && |
1244 | 1244 | ($php = trim($form_values['default_value_php']))) { |
1245 | - $error = FALSE; |
|
1245 | + $error = false; |
|
1246 | 1246 | ob_start(); |
1247 | 1247 | $return = eval($php); |
1248 | 1248 | ob_end_clean(); |
1249 | 1249 | if (!is_array($return)) { |
1250 | - $error = TRUE; |
|
1250 | + $error = true; |
|
1251 | 1251 | } |
1252 | 1252 | else { |
1253 | 1253 | foreach ($return as $item) { |
1254 | 1254 | if (!is_array($item)) { |
1255 | - $error = TRUE; |
|
1255 | + $error = true; |
|
1256 | 1256 | break; |
1257 | 1257 | } |
1258 | 1258 | } |
@@ -1267,12 +1267,12 @@ discard block |
||
1267 | 1267 | |
1268 | 1268 | form_set_error('default_value_php', t('The default value PHP code returned an incorrect value.<br/>Expected format: <pre>!sample</pre> Returned value: @value', array( |
1269 | 1269 | '!sample' => $sample, |
1270 | - '@value' => print_r($return, TRUE)))); |
|
1270 | + '@value' => print_r($return, true)))); |
|
1271 | 1271 | return; |
1272 | 1272 | } |
1273 | 1273 | else { |
1274 | 1274 | $default_value = $return; |
1275 | - $is_code = TRUE; |
|
1275 | + $is_code = true; |
|
1276 | 1276 | form_set_value(array('#parents' => array('default_value_php')), $php, $form_state); |
1277 | 1277 | form_set_value(array('#parents' => array('default_value')), array(), $form_state); |
1278 | 1278 | } |
@@ -1282,14 +1282,14 @@ discard block |
||
1282 | 1282 | // value as the top-level key, so just pop off the top element. |
1283 | 1283 | $key = array_shift(array_keys($form_values['default_value_widget'])); |
1284 | 1284 | $default_value = $form_values['default_value_widget'][$key]; |
1285 | - $is_code = FALSE; |
|
1285 | + $is_code = false; |
|
1286 | 1286 | form_set_value(array('#parents' => array('default_value_php')), '', $form_state); |
1287 | 1287 | form_set_value(array('#parents' => array('default_value')), $default_value, $form_state); |
1288 | 1288 | } |
1289 | 1289 | if (isset($default_value)) { |
1290 | 1290 | $node = array(); |
1291 | 1291 | $node[$form_values['field_name']] = $default_value; |
1292 | - $field['required'] = FALSE; |
|
1292 | + $field['required'] = false; |
|
1293 | 1293 | $field_function = $field_type['module'] .'_field'; |
1294 | 1294 | |
1295 | 1295 | $errors_before = form_get_errors(); |
@@ -1297,7 +1297,7 @@ discard block |
||
1297 | 1297 | // Widget now does its own validation, should be no need |
1298 | 1298 | // to add anything for widget validation here. |
1299 | 1299 | if (function_exists($field_function)) { |
1300 | - $field_function('validate', $node, $field, $default_value, $form, NULL); |
|
1300 | + $field_function('validate', $node, $field, $default_value, $form, null); |
|
1301 | 1301 | } |
1302 | 1302 | // The field validation routine won't set an error on the right field, |
1303 | 1303 | // so set it here. |
@@ -1305,7 +1305,7 @@ discard block |
||
1305 | 1305 | if (count($errors_after) > count($errors_before)) { |
1306 | 1306 | if (trim($form_values['default_value_php'])) { |
1307 | 1307 | form_set_error('default_value_php', t("The PHP code for 'default value' returned @value, which is invalid.", array( |
1308 | - '@value' => print_r($default_value, TRUE)))); |
|
1308 | + '@value' => print_r($default_value, true)))); |
|
1309 | 1309 | } |
1310 | 1310 | else { |
1311 | 1311 | form_set_error('default_value', t('The default value is invalid.')); |
@@ -1319,8 +1319,8 @@ discard block |
||
1319 | 1319 | * Button submit handler. |
1320 | 1320 | */ |
1321 | 1321 | function content_field_edit_form_submit_update_basic($form, &$form_state) { |
1322 | - $form_state['change_basic'] = TRUE; |
|
1323 | - $form_state['rebuild'] = TRUE; |
|
1322 | + $form_state['change_basic'] = true; |
|
1323 | + $form_state['rebuild'] = true; |
|
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | /** |
@@ -1534,8 +1534,8 @@ discard block |
||
1534 | 1534 | else if ($previous_field['multiple'] == 0 && $new_field['multiple'] > 0) { |
1535 | 1535 | db_add_field($ret, $new_table, 'delta', array( |
1536 | 1536 | 'type' => 'int', |
1537 | - 'unsigned' => TRUE, |
|
1538 | - 'not null' => TRUE, |
|
1537 | + 'unsigned' => true, |
|
1538 | + 'not null' => true, |
|
1539 | 1539 | 'default' => 0)); |
1540 | 1540 | db_drop_primary_key($ret, $new_table); |
1541 | 1541 | db_add_primary_key($ret, $new_table, array('vid', 'delta')); |
@@ -1581,7 +1581,7 @@ discard block |
||
1581 | 1581 | } |
1582 | 1582 | foreach ($migrate_columns as $column => $attributes) { |
1583 | 1583 | if (is_null($data[$column])) { |
1584 | - $record[$column] = NULL; |
|
1584 | + $record[$column] = null; |
|
1585 | 1585 | } |
1586 | 1586 | else { |
1587 | 1587 | $record[$column] = $data[$column]; |
@@ -1639,7 +1639,7 @@ discard block |
||
1639 | 1639 | // TODO: this could be optimized. We don't need to rebuild in *every case*... |
1640 | 1640 | // Or do we? This affects the schema and menu and may have unfortunate |
1641 | 1641 | // delayed effects if we don't clear everything out at this point. |
1642 | - content_clear_type_cache(TRUE); |
|
1642 | + content_clear_type_cache(true); |
|
1643 | 1643 | } |
1644 | 1644 | |
1645 | 1645 | /** |
@@ -1752,11 +1752,11 @@ discard block |
||
1752 | 1752 | foreach (array_keys($previous_field['columns']) as $column_name) { |
1753 | 1753 | // The basic mask will empty the dropped columns. |
1754 | 1754 | if (isset($dropped['columns']) && in_array($column_name, $dropped['columns'])) { |
1755 | - $mask['mask'][$column_name] = NULL; |
|
1755 | + $mask['mask'][$column_name] = null; |
|
1756 | 1756 | } |
1757 | 1757 | // Over the delta we'll empty all columns. |
1758 | 1758 | if (isset($dropped['delta'])) { |
1759 | - $mask['alt_mask'][$column_name] = NULL; |
|
1759 | + $mask['alt_mask'][$column_name] = null; |
|
1760 | 1760 | } |
1761 | 1761 | } |
1762 | 1762 | if (isset($dropped['delta'])) { |
@@ -1869,7 +1869,7 @@ discard block |
||
1869 | 1869 | * ), |
1870 | 1870 | */ |
1871 | 1871 | function content_field_replace($nid, $updates) { |
1872 | - $node = node_load($nid, NULL, TRUE); |
|
1872 | + $node = node_load($nid, null, true); |
|
1873 | 1873 | foreach ($updates as $field_name => $update) { |
1874 | 1874 | $items = isset($node->$field_name) ? $node->$field_name : array(); |
1875 | 1875 | foreach ($items as $delta => $value) { |
@@ -10,54 +10,54 @@ discard block |
||
10 | 10 | * Callback function to supply a list of content types. |
11 | 11 | */ |
12 | 12 | function content_content_field_ctools_content_types() { |
13 | - return array( |
|
13 | + return array( |
|
14 | 14 | 'title' => t('Content field'), |
15 | 15 | 'defaults' => array('label' => '', 'formatter' => ''), |
16 | 16 | 'content type' => 'content_content_field_content_type_content_type', |
17 | - ); |
|
17 | + ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Return all field content types available. |
22 | 22 | */ |
23 | 23 | function content_content_field_content_type_content_types() { |
24 | - // This will hold all the individual field content types. |
|
25 | - $types = array(); |
|
24 | + // This will hold all the individual field content types. |
|
25 | + $types = array(); |
|
26 | 26 | |
27 | - // Get all fields on the site. |
|
28 | - $field_types = _content_field_types(); |
|
27 | + // Get all fields on the site. |
|
28 | + $field_types = _content_field_types(); |
|
29 | 29 | |
30 | - foreach (content_types() as $type_name => $type) { |
|
30 | + foreach (content_types() as $type_name => $type) { |
|
31 | 31 | foreach ($type['fields'] as $field_name => $field) { |
32 | - if (!isset($types[$field_name])) { |
|
32 | + if (!isset($types[$field_name])) { |
|
33 | 33 | $types[$field_name] = array( |
34 | - 'category' => t('Node'), |
|
35 | - 'icon' => 'icon_cck_field.png', |
|
36 | - 'title' => t('Field: @widget_label (@field_name) - @field_type', array( |
|
34 | + 'category' => t('Node'), |
|
35 | + 'icon' => 'icon_cck_field.png', |
|
36 | + 'title' => t('Field: @widget_label (@field_name) - @field_type', array( |
|
37 | 37 | '@widget_label' => t($field['widget']['label']), |
38 | 38 | '@field_name' => $field_name, |
39 | 39 | '@field_type' => t($field_types[$field['type']]['label']), |
40 | - )), |
|
41 | - 'description' => t('Field on the referenced node.'), |
|
42 | - 'types' => array(), |
|
40 | + )), |
|
41 | + 'description' => t('Field on the referenced node.'), |
|
42 | + 'types' => array(), |
|
43 | 43 | ); |
44 | 44 | if (isset($field_types[$field['type']]['content_icon'])) { |
45 | - $types[$field_name]['icon'] = $field_types[$field['type']]['content_icon']; |
|
45 | + $types[$field_name]['icon'] = $field_types[$field['type']]['content_icon']; |
|
46 | 46 | } |
47 | - } |
|
48 | - $types[$field_name]['types'][$type_name] = $type['name']; |
|
47 | + } |
|
48 | + $types[$field_name]['types'][$type_name] = $type['name']; |
|
49 | + } |
|
49 | 50 | } |
50 | - } |
|
51 | 51 | |
52 | - // Create the required context for each field related to the content types. |
|
53 | - foreach ($types as $field_name => $field_content_type) { |
|
52 | + // Create the required context for each field related to the content types. |
|
53 | + foreach ($types as $field_name => $field_content_type) { |
|
54 | 54 | $types[$field_name]['required context'] = new ctools_context_required(t('Node'), 'node', array( |
55 | - 'type' => array_keys($types[$field_name]['types']), |
|
55 | + 'type' => array_keys($types[$field_name]['types']), |
|
56 | 56 | )); |
57 | 57 | unset($types[$field_name]['types']); |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - return $types; |
|
60 | + return $types; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -68,148 +68,148 @@ discard block |
||
68 | 68 | * lets us translate the name properly. |
69 | 69 | */ |
70 | 70 | function content_content_field_content_type_content_type($subtype) { |
71 | - // Previous versions of CCK included the content type as part of the subtype. |
|
72 | - // This allows those to continue to sort of work, at least during render. |
|
73 | - if (strpos($subtype, ':') !== FALSE) { |
|
71 | + // Previous versions of CCK included the content type as part of the subtype. |
|
72 | + // This allows those to continue to sort of work, at least during render. |
|
73 | + if (strpos($subtype, ':') !== FALSE) { |
|
74 | 74 | list($content_type, $subtype) = explode(':', $subtype, 2); |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | - $types = content_content_field_content_type_content_types(); |
|
78 | - if (isset($types[$subtype])) { |
|
77 | + $types = content_content_field_content_type_content_types(); |
|
78 | + if (isset($types[$subtype])) { |
|
79 | 79 | return $types[$subtype]; |
80 | - } |
|
80 | + } |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | 84 | * Output function for the 'field' content type. |
85 | 85 | */ |
86 | 86 | function content_content_field_content_type_render($subtype, $conf, $panel_args, $context) { |
87 | - // Previous versions of CCK included the content type as part of the subtype. |
|
88 | - // This allows those to continue to sort of work, at least during render. |
|
89 | - if (strpos($subtype, ':') !== FALSE) { |
|
87 | + // Previous versions of CCK included the content type as part of the subtype. |
|
88 | + // This allows those to continue to sort of work, at least during render. |
|
89 | + if (strpos($subtype, ':') !== FALSE) { |
|
90 | 90 | list($content_type, $subtype) = explode(':', $subtype, 2); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - if (is_array($context)) { |
|
93 | + if (is_array($context)) { |
|
94 | 94 | $context = array_pop($context); |
95 | - } |
|
96 | - // If we do not have a node, then we cannot generate output. |
|
97 | - if (!isset($context->data)) { |
|
95 | + } |
|
96 | + // If we do not have a node, then we cannot generate output. |
|
97 | + if (!isset($context->data)) { |
|
98 | 98 | return; |
99 | - } |
|
100 | - $node = drupal_clone($context->data); |
|
99 | + } |
|
100 | + $node = drupal_clone($context->data); |
|
101 | 101 | |
102 | - // Extract the node type from the node in context, the field name from the |
|
103 | - // panels content type subtype, and get the content field structure. |
|
104 | - $field_name = $subtype; |
|
105 | - $field = content_fields($field_name, $node->type); |
|
102 | + // Extract the node type from the node in context, the field name from the |
|
103 | + // panels content type subtype, and get the content field structure. |
|
104 | + $field_name = $subtype; |
|
105 | + $field = content_fields($field_name, $node->type); |
|
106 | 106 | |
107 | - // Get the formatter that was selected in the settings dialog. |
|
108 | - $formatter = $conf['formatter']; |
|
107 | + // Get the formatter that was selected in the settings dialog. |
|
108 | + $formatter = $conf['formatter']; |
|
109 | 109 | |
110 | - // Check view access to the field. |
|
111 | - if (!content_access('view', $field, NULL, $node)) { |
|
110 | + // Check view access to the field. |
|
111 | + if (!content_access('view', $field, NULL, $node)) { |
|
112 | 112 | return; |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - // Force panel settings into the field's display settings. |
|
116 | - $field['display_settings']['label']['format'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label']; |
|
117 | - $field['display_settings']['full']['format'] = $formatter; |
|
118 | - $node->build_mode = NODE_BUILD_NORMAL; |
|
119 | - // TODO : allow panel-specific template suggestions for content-field.tpl.php ? |
|
115 | + // Force panel settings into the field's display settings. |
|
116 | + $field['display_settings']['label']['format'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label']; |
|
117 | + $field['display_settings']['full']['format'] = $formatter; |
|
118 | + $node->build_mode = NODE_BUILD_NORMAL; |
|
119 | + // TODO : allow panel-specific template suggestions for content-field.tpl.php ? |
|
120 | 120 | |
121 | - $output = content_view_field($field, $node); |
|
121 | + $output = content_view_field($field, $node); |
|
122 | 122 | |
123 | - $block = new stdClass(); |
|
124 | - $block->module = 'content'; |
|
125 | - $block->delta = $field_name; |
|
126 | - if ($conf['label'] == 'normal') { |
|
123 | + $block = new stdClass(); |
|
124 | + $block->module = 'content'; |
|
125 | + $block->delta = $field_name; |
|
126 | + if ($conf['label'] == 'normal') { |
|
127 | 127 | $block->title = t($field['widget']['label']); |
128 | - } |
|
129 | - $block->content = $output; |
|
128 | + } |
|
129 | + $block->content = $output; |
|
130 | 130 | |
131 | - return $block; |
|
131 | + return $block; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | 135 | * Returns a settings form for the custom type. |
136 | 136 | */ |
137 | 137 | function content_content_field_content_type_edit_form(&$form, &$form_state) { |
138 | - $conf = $form_state['conf']; |
|
138 | + $conf = $form_state['conf']; |
|
139 | 139 | |
140 | - $form['label'] = array( |
|
140 | + $form['label'] = array( |
|
141 | 141 | '#type' => 'select', |
142 | 142 | '#title' => t('Field label'), |
143 | 143 | '#default_value' => isset($conf['label']) ? $conf['label'] : '', |
144 | 144 | '#options' => array( |
145 | - 'normal' => t('Block title'), |
|
146 | - 'above' => t('Above'), |
|
147 | - 'inline' => t('Inline'), |
|
145 | + 'normal' => t('Block title'), |
|
146 | + 'above' => t('Above'), |
|
147 | + 'inline' => t('Inline'), |
|
148 | 148 | ), |
149 | 149 | '#description' => t('Configure how the label is going to be displayed. This option takes no effect when "Override title" option is enabled, the specified block title is displayed instead.'), |
150 | - ); |
|
150 | + ); |
|
151 | 151 | |
152 | - // Extract the field name from the panels content type subtype. |
|
153 | - $field_name = $form_state['subtype_name']; |
|
152 | + // Extract the field name from the panels content type subtype. |
|
153 | + $field_name = $form_state['subtype_name']; |
|
154 | 154 | |
155 | - // Previous versions of CCK included the content type as part of the subtype. |
|
156 | - // This allows those to continue to sort of work. |
|
157 | - if (strpos($field_name, ':') !== FALSE) { |
|
155 | + // Previous versions of CCK included the content type as part of the subtype. |
|
156 | + // This allows those to continue to sort of work. |
|
157 | + if (strpos($field_name, ':') !== FALSE) { |
|
158 | 158 | list($content_type, $field_name) = explode(':', $field_name, 2); |
159 | - } |
|
159 | + } |
|
160 | 160 | |
161 | - // Get all the information about our field. |
|
162 | - $field = content_fields($field_name); |
|
161 | + // Get all the information about our field. |
|
162 | + $field = content_fields($field_name); |
|
163 | 163 | |
164 | - // Get information about all the field types on the site. |
|
165 | - $field_types = _content_field_types(); |
|
164 | + // Get information about all the field types on the site. |
|
165 | + $field_types = _content_field_types(); |
|
166 | 166 | |
167 | - // Get the information about the type that our field is. |
|
168 | - $type_info = $field_types[$field['type']]; |
|
167 | + // Get the information about the type that our field is. |
|
168 | + $type_info = $field_types[$field['type']]; |
|
169 | 169 | |
170 | - // Put the possible formatters for our type into an array. |
|
171 | - $options = array(); |
|
172 | - foreach ($type_info['formatters'] as $formatter_name => $formatter) { |
|
170 | + // Put the possible formatters for our type into an array. |
|
171 | + $options = array(); |
|
172 | + foreach ($type_info['formatters'] as $formatter_name => $formatter) { |
|
173 | 173 | $options[$formatter_name] = $formatter['label']; |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - $form['formatter'] = array( |
|
176 | + $form['formatter'] = array( |
|
177 | 177 | '#type' => 'select', |
178 | 178 | '#title' => t('Field formatter'), |
179 | 179 | '#default_value' => isset($conf['formatter']) ? $conf['formatter'] : 'default', |
180 | 180 | '#options' => $options, |
181 | 181 | '#description' => t('Select a formatter.'), |
182 | 182 | '#required' => TRUE, |
183 | - ); |
|
183 | + ); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | function content_content_field_content_type_edit_form_submit(&$form, &$form_state) { |
187 | - // Copy everything from our defaults. |
|
188 | - foreach (array_keys($form_state['plugin']['defaults']) as $key) { |
|
187 | + // Copy everything from our defaults. |
|
188 | + foreach (array_keys($form_state['plugin']['defaults']) as $key) { |
|
189 | 189 | $form_state['conf'][$key] = $form_state['values'][$key]; |
190 | - } |
|
190 | + } |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | 194 | * Admin title for field content type. |
195 | 195 | */ |
196 | 196 | function content_content_field_content_type_admin_title($subtype, $conf, $context) { |
197 | - // Previous versions of CCK included the content type as part of the subtype. |
|
198 | - // This allows those to continue to sort of work, at least during render. |
|
199 | - if (strpos($subtype, ':') !== FALSE) { |
|
197 | + // Previous versions of CCK included the content type as part of the subtype. |
|
198 | + // This allows those to continue to sort of work, at least during render. |
|
199 | + if (strpos($subtype, ':') !== FALSE) { |
|
200 | 200 | list($content_type, $subtype) = explode(':', $subtype, 2); |
201 | - } |
|
201 | + } |
|
202 | 202 | |
203 | - // Get all fields on the site. |
|
204 | - $field_types = _content_field_types(); |
|
203 | + // Get all fields on the site. |
|
204 | + $field_types = _content_field_types(); |
|
205 | 205 | |
206 | - // Get all the information about our field. |
|
207 | - $field = content_fields($subtype); |
|
206 | + // Get all the information about our field. |
|
207 | + $field = content_fields($subtype); |
|
208 | 208 | |
209 | - return t('"@s" field: @widget_label (@field_name) - @field_type', array( |
|
209 | + return t('"@s" field: @widget_label (@field_name) - @field_type', array( |
|
210 | 210 | '@s' => $context->identifier, |
211 | 211 | '@widget_label' => t($field['widget']['label']), |
212 | 212 | '@field_name' => $subtype, |
213 | 213 | '@field_type' => t($field_types[$field['type']]['label']), |
214 | - )); |
|
214 | + )); |
|
215 | 215 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | function content_content_field_content_type_content_type($subtype) { |
71 | 71 | // Previous versions of CCK included the content type as part of the subtype. |
72 | 72 | // This allows those to continue to sort of work, at least during render. |
73 | - if (strpos($subtype, ':') !== FALSE) { |
|
73 | + if (strpos($subtype, ':') !== false) { |
|
74 | 74 | list($content_type, $subtype) = explode(':', $subtype, 2); |
75 | 75 | } |
76 | 76 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | function content_content_field_content_type_render($subtype, $conf, $panel_args, $context) { |
87 | 87 | // Previous versions of CCK included the content type as part of the subtype. |
88 | 88 | // This allows those to continue to sort of work, at least during render. |
89 | - if (strpos($subtype, ':') !== FALSE) { |
|
89 | + if (strpos($subtype, ':') !== false) { |
|
90 | 90 | list($content_type, $subtype) = explode(':', $subtype, 2); |
91 | 91 | } |
92 | 92 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $formatter = $conf['formatter']; |
109 | 109 | |
110 | 110 | // Check view access to the field. |
111 | - if (!content_access('view', $field, NULL, $node)) { |
|
111 | + if (!content_access('view', $field, null, $node)) { |
|
112 | 112 | return; |
113 | 113 | } |
114 | 114 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | // Previous versions of CCK included the content type as part of the subtype. |
156 | 156 | // This allows those to continue to sort of work. |
157 | - if (strpos($field_name, ':') !== FALSE) { |
|
157 | + if (strpos($field_name, ':') !== false) { |
|
158 | 158 | list($content_type, $field_name) = explode(':', $field_name, 2); |
159 | 159 | } |
160 | 160 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | '#default_value' => isset($conf['formatter']) ? $conf['formatter'] : 'default', |
180 | 180 | '#options' => $options, |
181 | 181 | '#description' => t('Select a formatter.'), |
182 | - '#required' => TRUE, |
|
182 | + '#required' => true, |
|
183 | 183 | ); |
184 | 184 | } |
185 | 185 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | function content_content_field_content_type_admin_title($subtype, $conf, $context) { |
197 | 197 | // Previous versions of CCK included the content type as part of the subtype. |
198 | 198 | // This allows those to continue to sort of work, at least during render. |
199 | - if (strpos($subtype, ':') !== FALSE) { |
|
199 | + if (strpos($subtype, ':') !== false) { |
|
200 | 200 | list($content_type, $subtype) = explode(':', $subtype, 2); |
201 | 201 | } |
202 | 202 |
@@ -12,40 +12,40 @@ discard block |
||
12 | 12 | * Implementation of hook_diff() |
13 | 13 | */ |
14 | 14 | function content_diff($old_node, $new_node) { |
15 | - $result = array(); |
|
16 | - // Prevent against invalid 'nodes' built by broken 3rd party code. |
|
17 | - if (isset($new_node->type)) { |
|
15 | + $result = array(); |
|
16 | + // Prevent against invalid 'nodes' built by broken 3rd party code. |
|
17 | + if (isset($new_node->type)) { |
|
18 | 18 | $type = content_types($new_node->type); |
19 | 19 | $field_types = _content_field_types(); |
20 | 20 | foreach ($type['fields'] as $field) { |
21 | - // Ignore fields the current user is not allowed to view. |
|
22 | - if (!content_access('view', $field, NULL, $new_node)) { |
|
21 | + // Ignore fields the current user is not allowed to view. |
|
22 | + if (!content_access('view', $field, NULL, $new_node)) { |
|
23 | 23 | continue; |
24 | - } |
|
25 | - $function = $field_types[$field['type']]['module'] . '_content_diff_values'; |
|
26 | - $function = function_exists($function) ? $function : 'content_content_diff_values'; |
|
27 | - $old_values = array(); |
|
28 | - $new_values = array(); |
|
29 | - if (isset($old_node->$field['field_name'])) { |
|
24 | + } |
|
25 | + $function = $field_types[$field['type']]['module'] . '_content_diff_values'; |
|
26 | + $function = function_exists($function) ? $function : 'content_content_diff_values'; |
|
27 | + $old_values = array(); |
|
28 | + $new_values = array(); |
|
29 | + if (isset($old_node->$field['field_name'])) { |
|
30 | 30 | $old_values = $function($old_node, $field, $old_node->$field['field_name']); |
31 | - } |
|
32 | - if (isset($new_node->$field['field_name'])) { |
|
31 | + } |
|
32 | + if (isset($new_node->$field['field_name'])) { |
|
33 | 33 | $new_values = $function($new_node, $field, $new_node->$field['field_name']); |
34 | - } |
|
35 | - if ($old_values || $new_values) { |
|
34 | + } |
|
35 | + if ($old_values || $new_values) { |
|
36 | 36 | $result[$field['field_name']] = array( |
37 | - '#name' => $field['widget']['label'], |
|
38 | - '#old' => $old_values, |
|
39 | - '#new' => $new_values, |
|
40 | - '#weight' => $field['widget']['weight'], |
|
41 | - '#format' => array( |
|
37 | + '#name' => $field['widget']['label'], |
|
38 | + '#old' => $old_values, |
|
39 | + '#new' => $new_values, |
|
40 | + '#weight' => $field['widget']['weight'], |
|
41 | + '#format' => array( |
|
42 | 42 | 'show_header' => FALSE, |
43 | - ), |
|
43 | + ), |
|
44 | 44 | ); |
45 | - } |
|
45 | + } |
|
46 | 46 | } |
47 | - } |
|
48 | - return $result; |
|
47 | + } |
|
48 | + return $result; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -54,75 +54,75 @@ discard block |
||
54 | 54 | * Note that diff.module takes care of running check_plain on the output. |
55 | 55 | */ |
56 | 56 | function content_content_diff_values($node, $field, $items) { |
57 | - $return = array(); |
|
58 | - foreach ($items as $item) { |
|
57 | + $return = array(); |
|
58 | + foreach ($items as $item) { |
|
59 | 59 | foreach (explode("\n", $item['value']) as $i) { |
60 | - $return[] = $i; |
|
60 | + $return[] = $i; |
|
61 | + } |
|
61 | 62 | } |
62 | - } |
|
63 | - return $return; |
|
63 | + return $return; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | if (module_exists('userreference')) { |
67 | - /** |
|
68 | - * Implementation of hook_content_diff_values. |
|
69 | - */ |
|
70 | - function userreference_content_diff_values($node, $field, $items) { |
|
67 | + /** |
|
68 | + * Implementation of hook_content_diff_values. |
|
69 | + */ |
|
70 | + function userreference_content_diff_values($node, $field, $items) { |
|
71 | 71 | static $titles = array(); |
72 | 72 | // Gather ids. |
73 | 73 | $ids = array(); |
74 | 74 | foreach ($items as $item) { |
75 | - if ($item['uid'] && is_numeric($item['uid'])) { |
|
75 | + if ($item['uid'] && is_numeric($item['uid'])) { |
|
76 | 76 | $ids[] = $item['uid']; |
77 | - } |
|
77 | + } |
|
78 | 78 | } |
79 | 79 | // Fetch titles we don't know yet. |
80 | 80 | $queried_ids = array_diff($ids, array_keys($titles)); |
81 | 81 | if ($queried_ids) { |
82 | - $result = db_query('SELECT uid, name FROM {users} WHERE uid IN ('. db_placeholders($queried_ids) .')', $queried_ids); |
|
83 | - while ($row = db_fetch_array($result)) { |
|
82 | + $result = db_query('SELECT uid, name FROM {users} WHERE uid IN ('. db_placeholders($queried_ids) .')', $queried_ids); |
|
83 | + while ($row = db_fetch_array($result)) { |
|
84 | 84 | $titles[$row['uid']] = $row['name']; |
85 | - } |
|
85 | + } |
|
86 | 86 | } |
87 | 87 | // Return result. |
88 | 88 | $return = array(); |
89 | 89 | foreach ($items as $item) { |
90 | - if ($item['uid'] && isset($titles[$item['uid']])) { |
|
90 | + if ($item['uid'] && isset($titles[$item['uid']])) { |
|
91 | 91 | $return[] = $titles[$item['uid']]; |
92 | - } |
|
92 | + } |
|
93 | 93 | } |
94 | 94 | return $return; |
95 | - } |
|
95 | + } |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | if (module_exists('nodereference')) { |
99 | - /** |
|
100 | - * Implementation of hook_content_diff_values. |
|
101 | - */ |
|
102 | - function nodereference_content_diff_values($node, $field, $items) { |
|
99 | + /** |
|
100 | + * Implementation of hook_content_diff_values. |
|
101 | + */ |
|
102 | + function nodereference_content_diff_values($node, $field, $items) { |
|
103 | 103 | static $titles = array(); |
104 | 104 | // Gather ids. |
105 | 105 | $ids = array(); |
106 | 106 | foreach ($items as $item) { |
107 | - if ($item['nid'] && is_numeric($item['nid'])) { |
|
107 | + if ($item['nid'] && is_numeric($item['nid'])) { |
|
108 | 108 | $ids[] = $item['nid']; |
109 | - } |
|
109 | + } |
|
110 | 110 | } |
111 | 111 | // Fetch titles we don't know yet. |
112 | 112 | $queried_ids = array_diff($ids, array_keys($titles)); |
113 | 113 | if ($queried_ids) { |
114 | - $result = db_query('SELECT nid, title FROM {node} WHERE nid IN ('. db_placeholders($queried_ids) .')', $queried_ids); |
|
115 | - while ($row = db_fetch_array($result)) { |
|
114 | + $result = db_query('SELECT nid, title FROM {node} WHERE nid IN ('. db_placeholders($queried_ids) .')', $queried_ids); |
|
115 | + while ($row = db_fetch_array($result)) { |
|
116 | 116 | $titles[$row['nid']] = $row['title']; |
117 | - } |
|
117 | + } |
|
118 | 118 | } |
119 | 119 | // Return result. |
120 | 120 | $return = array(); |
121 | 121 | foreach ($items as $item) { |
122 | - if ($item['nid'] && isset($titles[$item['nid']])) { |
|
122 | + if ($item['nid'] && isset($titles[$item['nid']])) { |
|
123 | 123 | $return[] = $titles[$item['nid']]; |
124 | - } |
|
124 | + } |
|
125 | 125 | } |
126 | 126 | return $return; |
127 | - } |
|
127 | + } |
|
128 | 128 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | if (!content_access('view', $field, NULL, $new_node)) { |
23 | 23 | continue; |
24 | 24 | } |
25 | - $function = $field_types[$field['type']]['module'] . '_content_diff_values'; |
|
25 | + $function = $field_types[$field['type']]['module'].'_content_diff_values'; |
|
26 | 26 | $function = function_exists($function) ? $function : 'content_content_diff_values'; |
27 | 27 | $old_values = array(); |
28 | 28 | $new_values = array(); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | // Fetch titles we don't know yet. |
80 | 80 | $queried_ids = array_diff($ids, array_keys($titles)); |
81 | 81 | if ($queried_ids) { |
82 | - $result = db_query('SELECT uid, name FROM {users} WHERE uid IN ('. db_placeholders($queried_ids) .')', $queried_ids); |
|
82 | + $result = db_query('SELECT uid, name FROM {users} WHERE uid IN ('.db_placeholders($queried_ids).')', $queried_ids); |
|
83 | 83 | while ($row = db_fetch_array($result)) { |
84 | 84 | $titles[$row['uid']] = $row['name']; |
85 | 85 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | // Fetch titles we don't know yet. |
112 | 112 | $queried_ids = array_diff($ids, array_keys($titles)); |
113 | 113 | if ($queried_ids) { |
114 | - $result = db_query('SELECT nid, title FROM {node} WHERE nid IN ('. db_placeholders($queried_ids) .')', $queried_ids); |
|
114 | + $result = db_query('SELECT nid, title FROM {node} WHERE nid IN ('.db_placeholders($queried_ids).')', $queried_ids); |
|
115 | 115 | while ($row = db_fetch_array($result)) { |
116 | 116 | $titles[$row['nid']] = $row['title']; |
117 | 117 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | $field_types = _content_field_types(); |
20 | 20 | foreach ($type['fields'] as $field) { |
21 | 21 | // Ignore fields the current user is not allowed to view. |
22 | - if (!content_access('view', $field, NULL, $new_node)) { |
|
22 | + if (!content_access('view', $field, null, $new_node)) { |
|
23 | 23 | continue; |
24 | 24 | } |
25 | 25 | $function = $field_types[$field['type']]['module'] . '_content_diff_values'; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | '#new' => $new_values, |
40 | 40 | '#weight' => $field['widget']['weight'], |
41 | 41 | '#format' => array( |
42 | - 'show_header' => FALSE, |
|
42 | + 'show_header' => false, |
|
43 | 43 | ), |
44 | 44 | ); |
45 | 45 | } |
@@ -7,181 +7,181 @@ |
||
7 | 7 | * (on behalf of token.module) |
8 | 8 | */ |
9 | 9 | function token_content_build_modes() { |
10 | - return array( |
|
10 | + return array( |
|
11 | 11 | 'token' => array( |
12 | - 'title' => t('Token'), |
|
13 | - 'build modes' => array( |
|
12 | + 'title' => t('Token'), |
|
13 | + 'build modes' => array( |
|
14 | 14 | 'token' => array( |
15 | - 'title' => t('Token'), |
|
16 | - 'views style' => FALSE, |
|
15 | + 'title' => t('Token'), |
|
16 | + 'views style' => FALSE, |
|
17 | + ), |
|
17 | 18 | ), |
18 | - ), |
|
19 | 19 | ), |
20 | - ); |
|
20 | + ); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | // Two helper functions that generate appropriate tokens for CCK-added fields. |
24 | 24 | function content_token_values($type, $object = NULL, $options = array()) { |
25 | - $tokens = array(); |
|
26 | - if ($type == 'node') { |
|
25 | + $tokens = array(); |
|
26 | + if ($type == 'node') { |
|
27 | 27 | // Prevent against invalid 'nodes' built by broken 3rd party code. |
28 | 28 | if (isset($object->type)) { |
29 | - // Let PHP free the $node object when we are done. Working directly on the |
|
30 | - // incoming $object causes memory leak issues on long-running scripts such |
|
31 | - // as migrations. See http://drupal.org/node/736440. |
|
32 | - $node = drupal_clone($object); |
|
33 | - $content_type = content_types($node->type); |
|
34 | - $node->build_mode = 'token'; |
|
35 | - $node->content = array(); |
|
36 | - content_view($node); |
|
37 | - // The formatted values will only be known after the content has been rendered. |
|
38 | - drupal_render($node->content); |
|
39 | - content_alter($node); |
|
40 | - |
|
41 | - $field_types = _content_field_types(); |
|
42 | - foreach ($content_type['fields'] as $field_name => $field) { |
|
29 | + // Let PHP free the $node object when we are done. Working directly on the |
|
30 | + // incoming $object causes memory leak issues on long-running scripts such |
|
31 | + // as migrations. See http://drupal.org/node/736440. |
|
32 | + $node = drupal_clone($object); |
|
33 | + $content_type = content_types($node->type); |
|
34 | + $node->build_mode = 'token'; |
|
35 | + $node->content = array(); |
|
36 | + content_view($node); |
|
37 | + // The formatted values will only be known after the content has been rendered. |
|
38 | + drupal_render($node->content); |
|
39 | + content_alter($node); |
|
40 | + |
|
41 | + $field_types = _content_field_types(); |
|
42 | + foreach ($content_type['fields'] as $field_name => $field) { |
|
43 | 43 | $items = isset($node->{$field_name}) ? $node->{$field_name} : array(); |
44 | 44 | $function = $field_types[$field['type']]['module'] . '_token_values'; |
45 | 45 | if (!empty($items) && function_exists($function)) { |
46 | - $token_values = (array) $function('field', $items, $options); |
|
47 | - foreach ($token_values as $token => $value) { |
|
46 | + $token_values = (array) $function('field', $items, $options); |
|
47 | + foreach ($token_values as $token => $value) { |
|
48 | 48 | $tokens[$field_name .'-'. $token] = $value; |
49 | - } |
|
49 | + } |
|
50 | + } |
|
50 | 51 | } |
51 | - } |
|
52 | 52 | } |
53 | - } |
|
54 | - return $tokens; |
|
53 | + } |
|
54 | + return $tokens; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | function content_token_list($type = 'all') { |
58 | - if ($type == 'node' || $type == 'all') { |
|
58 | + if ($type == 'node' || $type == 'all') { |
|
59 | 59 | $list = array(); |
60 | 60 | $field_types = _content_field_types(); |
61 | 61 | |
62 | 62 | foreach (content_fields() as $field) { |
63 | - $sub_list = array(); |
|
64 | - $function = $field_types[$field['type']]['module'] . '_token_list'; |
|
65 | - if (function_exists($function)) { |
|
63 | + $sub_list = array(); |
|
64 | + $function = $field_types[$field['type']]['module'] . '_token_list'; |
|
65 | + if (function_exists($function)) { |
|
66 | 66 | $sub_list = $function('field'); |
67 | 67 | foreach ($sub_list as $category => $token_list) { |
68 | - foreach ($token_list as $token => $description) { |
|
68 | + foreach ($token_list as $token => $description) { |
|
69 | 69 | $list['CCK '. $category][$field['field_name'] .'-'. $token] = $description; |
70 | - } |
|
70 | + } |
|
71 | + } |
|
71 | 72 | } |
72 | - } |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return $list; |
76 | - } |
|
76 | + } |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | if (module_exists('nodereference')) { |
80 | - function nodereference_token_list($type = 'all') { |
|
80 | + function nodereference_token_list($type = 'all') { |
|
81 | 81 | if ($type == 'field' || $type == 'all') { |
82 | - $tokens = array(); |
|
82 | + $tokens = array(); |
|
83 | 83 | |
84 | - $tokens['node reference']['nid'] = t('Referenced node ID'); |
|
85 | - $tokens['node reference']['title'] = t('Referenced node title'); |
|
86 | - $tokens['node reference']['title-raw'] = t('Referenced node unfiltered title. WARNING - raw user input.'); |
|
87 | - $tokens['node reference']['link'] = t("Formatted html link to the referenced node."); |
|
88 | - $tokens['node reference']['path'] = t("Relative path alias to the referenced node."); |
|
89 | - $tokens['node reference']['url'] = t("Absolute path alias to the referenced node."); |
|
84 | + $tokens['node reference']['nid'] = t('Referenced node ID'); |
|
85 | + $tokens['node reference']['title'] = t('Referenced node title'); |
|
86 | + $tokens['node reference']['title-raw'] = t('Referenced node unfiltered title. WARNING - raw user input.'); |
|
87 | + $tokens['node reference']['link'] = t("Formatted html link to the referenced node."); |
|
88 | + $tokens['node reference']['path'] = t("Relative path alias to the referenced node."); |
|
89 | + $tokens['node reference']['url'] = t("Absolute path alias to the referenced node."); |
|
90 | 90 | |
91 | - return $tokens; |
|
91 | + return $tokens; |
|
92 | + } |
|
92 | 93 | } |
93 | - } |
|
94 | 94 | |
95 | - function nodereference_token_values($type, $object = NULL, $options = array()) { |
|
95 | + function nodereference_token_values($type, $object = NULL, $options = array()) { |
|
96 | 96 | if ($type == 'field') { |
97 | - $item = $object[0]; |
|
97 | + $item = $object[0]; |
|
98 | 98 | |
99 | - $title = is_numeric($item['nid']) ? _nodereference_titles($item['nid']) : ''; |
|
100 | - $tokens['nid'] = $item['nid']; |
|
101 | - $tokens['title'] = $title ? check_plain($title) : ''; |
|
102 | - $tokens['title-raw'] = $title; |
|
103 | - $tokens['link'] = isset($item['view']) ? $item['view'] : ''; |
|
104 | - $tokens['path'] = is_numeric($item['nid']) ? url('node/' . $item['nid']) : ''; |
|
105 | - $tokens['url'] = is_numeric($item['nid']) ? url('node/' . $item['nid'], array('absolute' => TRUE)) : ''; |
|
99 | + $title = is_numeric($item['nid']) ? _nodereference_titles($item['nid']) : ''; |
|
100 | + $tokens['nid'] = $item['nid']; |
|
101 | + $tokens['title'] = $title ? check_plain($title) : ''; |
|
102 | + $tokens['title-raw'] = $title; |
|
103 | + $tokens['link'] = isset($item['view']) ? $item['view'] : ''; |
|
104 | + $tokens['path'] = is_numeric($item['nid']) ? url('node/' . $item['nid']) : ''; |
|
105 | + $tokens['url'] = is_numeric($item['nid']) ? url('node/' . $item['nid'], array('absolute' => TRUE)) : ''; |
|
106 | 106 | |
107 | - return $tokens; |
|
107 | + return $tokens; |
|
108 | + } |
|
108 | 109 | } |
109 | - } |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | if (module_exists('number')) { |
113 | - function number_token_list($type = 'all') { |
|
113 | + function number_token_list($type = 'all') { |
|
114 | 114 | if ($type == 'field' || $type == 'all') { |
115 | - $tokens = array(); |
|
115 | + $tokens = array(); |
|
116 | 116 | |
117 | - $tokens['number']['raw'] = t('Raw number value'); |
|
118 | - $tokens['number']['formatted'] = t('Formatted number value'); |
|
117 | + $tokens['number']['raw'] = t('Raw number value'); |
|
118 | + $tokens['number']['formatted'] = t('Formatted number value'); |
|
119 | 119 | |
120 | - return $tokens; |
|
120 | + return $tokens; |
|
121 | + } |
|
121 | 122 | } |
122 | - } |
|
123 | 123 | |
124 | - function number_token_values($type, $object = NULL, $options = array()) { |
|
124 | + function number_token_values($type, $object = NULL, $options = array()) { |
|
125 | 125 | if ($type == 'field') { |
126 | - $item = $object[0]; |
|
126 | + $item = $object[0]; |
|
127 | 127 | |
128 | - $tokens['raw'] = $item['value']; |
|
129 | - $tokens['formatted'] = isset($item['view']) ? $item['view'] : ''; |
|
128 | + $tokens['raw'] = $item['value']; |
|
129 | + $tokens['formatted'] = isset($item['view']) ? $item['view'] : ''; |
|
130 | 130 | |
131 | - return $tokens; |
|
131 | + return $tokens; |
|
132 | + } |
|
132 | 133 | } |
133 | - } |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | if (module_exists('text')) { |
137 | - function text_token_list($type = 'all') { |
|
137 | + function text_token_list($type = 'all') { |
|
138 | 138 | if ($type == 'field' || $type == 'all') { |
139 | - $tokens = array(); |
|
139 | + $tokens = array(); |
|
140 | 140 | |
141 | - $tokens['text']['raw'] = t('Raw, unfiltered text'); |
|
142 | - $tokens['text']['formatted'] = t('Formatted and filtered text'); |
|
141 | + $tokens['text']['raw'] = t('Raw, unfiltered text'); |
|
142 | + $tokens['text']['formatted'] = t('Formatted and filtered text'); |
|
143 | 143 | |
144 | - return $tokens; |
|
144 | + return $tokens; |
|
145 | + } |
|
145 | 146 | } |
146 | - } |
|
147 | 147 | |
148 | - function text_token_values($type, $object = NULL, $options = array()) { |
|
148 | + function text_token_values($type, $object = NULL, $options = array()) { |
|
149 | 149 | if ($type == 'field') { |
150 | - $item = $object[0]; |
|
150 | + $item = $object[0]; |
|
151 | 151 | |
152 | - $tokens['raw'] = $item['value']; |
|
153 | - $tokens['formatted'] = isset($item['view']) ? $item['view'] : ''; |
|
154 | - return $tokens; |
|
152 | + $tokens['raw'] = $item['value']; |
|
153 | + $tokens['formatted'] = isset($item['view']) ? $item['view'] : ''; |
|
154 | + return $tokens; |
|
155 | + } |
|
155 | 156 | } |
156 | - } |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | if (module_exists('userreference')) { |
160 | - function userreference_token_list($type = 'all') { |
|
160 | + function userreference_token_list($type = 'all') { |
|
161 | 161 | if ($type == 'field' || $type == 'all') { |
162 | - $tokens = array(); |
|
162 | + $tokens = array(); |
|
163 | 163 | |
164 | - $tokens['user reference']['uid'] = t('Referenced user ID'); |
|
165 | - $tokens['user reference']['name'] = t('Referenced user name'); |
|
166 | - $tokens['user reference']['link'] = t('Formatted HTML link to referenced user'); |
|
167 | - $tokens['user reference']['path'] = t("Relative path alias to the referenced user."); |
|
168 | - $tokens['user reference']['url'] = t("Absolute path alias to the referenced user."); |
|
164 | + $tokens['user reference']['uid'] = t('Referenced user ID'); |
|
165 | + $tokens['user reference']['name'] = t('Referenced user name'); |
|
166 | + $tokens['user reference']['link'] = t('Formatted HTML link to referenced user'); |
|
167 | + $tokens['user reference']['path'] = t("Relative path alias to the referenced user."); |
|
168 | + $tokens['user reference']['url'] = t("Absolute path alias to the referenced user."); |
|
169 | 169 | |
170 | - return $tokens; |
|
170 | + return $tokens; |
|
171 | + } |
|
171 | 172 | } |
172 | - } |
|
173 | 173 | |
174 | - function userreference_token_values($type, $object = NULL, $options = array()) { |
|
174 | + function userreference_token_values($type, $object = NULL, $options = array()) { |
|
175 | 175 | if ($type == 'field') { |
176 | - $item = $object[0]; |
|
176 | + $item = $object[0]; |
|
177 | 177 | |
178 | - $tokens['uid'] = $item['uid']; |
|
179 | - $tokens['name'] = isset($item['view']) ? strip_tags($item['view']) : ''; |
|
180 | - $tokens['link'] = isset($item['view']) ? $item['view'] : ''; |
|
181 | - $tokens['path'] = is_numeric($item['uid']) ? url('user/' . $item['uid']) : ''; |
|
182 | - $tokens['url'] = is_numeric($item['uid']) ? url('user/' . $item['uid'], array('absolute' => TRUE)) : ''; |
|
178 | + $tokens['uid'] = $item['uid']; |
|
179 | + $tokens['name'] = isset($item['view']) ? strip_tags($item['view']) : ''; |
|
180 | + $tokens['link'] = isset($item['view']) ? $item['view'] : ''; |
|
181 | + $tokens['path'] = is_numeric($item['uid']) ? url('user/' . $item['uid']) : ''; |
|
182 | + $tokens['url'] = is_numeric($item['uid']) ? url('user/' . $item['uid'], array('absolute' => TRUE)) : ''; |
|
183 | 183 | |
184 | - return $tokens; |
|
184 | + return $tokens; |
|
185 | + } |
|
185 | 186 | } |
186 | - } |
|
187 | 187 | } |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | $field_types = _content_field_types(); |
42 | 42 | foreach ($content_type['fields'] as $field_name => $field) { |
43 | 43 | $items = isset($node->{$field_name}) ? $node->{$field_name} : array(); |
44 | - $function = $field_types[$field['type']]['module'] . '_token_values'; |
|
44 | + $function = $field_types[$field['type']]['module'].'_token_values'; |
|
45 | 45 | if (!empty($items) && function_exists($function)) { |
46 | - $token_values = (array) $function('field', $items, $options); |
|
46 | + $token_values = (array)$function('field', $items, $options); |
|
47 | 47 | foreach ($token_values as $token => $value) { |
48 | - $tokens[$field_name .'-'. $token] = $value; |
|
48 | + $tokens[$field_name.'-'.$token] = $value; |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | } |
@@ -61,12 +61,12 @@ discard block |
||
61 | 61 | |
62 | 62 | foreach (content_fields() as $field) { |
63 | 63 | $sub_list = array(); |
64 | - $function = $field_types[$field['type']]['module'] . '_token_list'; |
|
64 | + $function = $field_types[$field['type']]['module'].'_token_list'; |
|
65 | 65 | if (function_exists($function)) { |
66 | 66 | $sub_list = $function('field'); |
67 | 67 | foreach ($sub_list as $category => $token_list) { |
68 | 68 | foreach ($token_list as $token => $description) { |
69 | - $list['CCK '. $category][$field['field_name'] .'-'. $token] = $description; |
|
69 | + $list['CCK '.$category][$field['field_name'].'-'.$token] = $description; |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $tokens['node reference']['title-raw'] = t('Referenced node unfiltered title. WARNING - raw user input.'); |
87 | 87 | $tokens['node reference']['link'] = t("Formatted html link to the referenced node."); |
88 | 88 | $tokens['node reference']['path'] = t("Relative path alias to the referenced node."); |
89 | - $tokens['node reference']['url'] = t("Absolute path alias to the referenced node."); |
|
89 | + $tokens['node reference']['url'] = t("Absolute path alias to the referenced node."); |
|
90 | 90 | |
91 | 91 | return $tokens; |
92 | 92 | } |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | $tokens['title'] = $title ? check_plain($title) : ''; |
102 | 102 | $tokens['title-raw'] = $title; |
103 | 103 | $tokens['link'] = isset($item['view']) ? $item['view'] : ''; |
104 | - $tokens['path'] = is_numeric($item['nid']) ? url('node/' . $item['nid']) : ''; |
|
105 | - $tokens['url'] = is_numeric($item['nid']) ? url('node/' . $item['nid'], array('absolute' => TRUE)) : ''; |
|
104 | + $tokens['path'] = is_numeric($item['nid']) ? url('node/'.$item['nid']) : ''; |
|
105 | + $tokens['url'] = is_numeric($item['nid']) ? url('node/'.$item['nid'], array('absolute' => TRUE)) : ''; |
|
106 | 106 | |
107 | 107 | return $tokens; |
108 | 108 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | if ($type == 'field') { |
150 | 150 | $item = $object[0]; |
151 | 151 | |
152 | - $tokens['raw'] = $item['value']; |
|
152 | + $tokens['raw'] = $item['value']; |
|
153 | 153 | $tokens['formatted'] = isset($item['view']) ? $item['view'] : ''; |
154 | 154 | return $tokens; |
155 | 155 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $tokens['user reference']['name'] = t('Referenced user name'); |
166 | 166 | $tokens['user reference']['link'] = t('Formatted HTML link to referenced user'); |
167 | 167 | $tokens['user reference']['path'] = t("Relative path alias to the referenced user."); |
168 | - $tokens['user reference']['url'] = t("Absolute path alias to the referenced user."); |
|
168 | + $tokens['user reference']['url'] = t("Absolute path alias to the referenced user."); |
|
169 | 169 | |
170 | 170 | return $tokens; |
171 | 171 | } |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | $tokens['uid'] = $item['uid']; |
179 | 179 | $tokens['name'] = isset($item['view']) ? strip_tags($item['view']) : ''; |
180 | 180 | $tokens['link'] = isset($item['view']) ? $item['view'] : ''; |
181 | - $tokens['path'] = is_numeric($item['uid']) ? url('user/' . $item['uid']) : ''; |
|
182 | - $tokens['url'] = is_numeric($item['uid']) ? url('user/' . $item['uid'], array('absolute' => TRUE)) : ''; |
|
181 | + $tokens['path'] = is_numeric($item['uid']) ? url('user/'.$item['uid']) : ''; |
|
182 | + $tokens['url'] = is_numeric($item['uid']) ? url('user/'.$item['uid'], array('absolute' => TRUE)) : ''; |
|
183 | 183 | |
184 | 184 | return $tokens; |
185 | 185 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | 'build modes' => array( |
14 | 14 | 'token' => array( |
15 | 15 | 'title' => t('Token'), |
16 | - 'views style' => FALSE, |
|
16 | + 'views style' => false, |
|
17 | 17 | ), |
18 | 18 | ), |
19 | 19 | ), |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | } |
22 | 22 | |
23 | 23 | // Two helper functions that generate appropriate tokens for CCK-added fields. |
24 | -function content_token_values($type, $object = NULL, $options = array()) { |
|
24 | +function content_token_values($type, $object = null, $options = array()) { |
|
25 | 25 | $tokens = array(); |
26 | 26 | if ($type == 'node') { |
27 | 27 | // Prevent against invalid 'nodes' built by broken 3rd party code. |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - function nodereference_token_values($type, $object = NULL, $options = array()) { |
|
95 | + function nodereference_token_values($type, $object = null, $options = array()) { |
|
96 | 96 | if ($type == 'field') { |
97 | 97 | $item = $object[0]; |
98 | 98 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $tokens['title-raw'] = $title; |
103 | 103 | $tokens['link'] = isset($item['view']) ? $item['view'] : ''; |
104 | 104 | $tokens['path'] = is_numeric($item['nid']) ? url('node/' . $item['nid']) : ''; |
105 | - $tokens['url'] = is_numeric($item['nid']) ? url('node/' . $item['nid'], array('absolute' => TRUE)) : ''; |
|
105 | + $tokens['url'] = is_numeric($item['nid']) ? url('node/' . $item['nid'], array('absolute' => true)) : ''; |
|
106 | 106 | |
107 | 107 | return $tokens; |
108 | 108 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - function number_token_values($type, $object = NULL, $options = array()) { |
|
124 | + function number_token_values($type, $object = null, $options = array()) { |
|
125 | 125 | if ($type == 'field') { |
126 | 126 | $item = $object[0]; |
127 | 127 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | - function text_token_values($type, $object = NULL, $options = array()) { |
|
148 | + function text_token_values($type, $object = null, $options = array()) { |
|
149 | 149 | if ($type == 'field') { |
150 | 150 | $item = $object[0]; |
151 | 151 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | - function userreference_token_values($type, $object = NULL, $options = array()) { |
|
174 | + function userreference_token_values($type, $object = null, $options = array()) { |
|
175 | 175 | if ($type == 'field') { |
176 | 176 | $item = $object[0]; |
177 | 177 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | $tokens['name'] = isset($item['view']) ? strip_tags($item['view']) : ''; |
180 | 180 | $tokens['link'] = isset($item['view']) ? $item['view'] : ''; |
181 | 181 | $tokens['path'] = is_numeric($item['uid']) ? url('user/' . $item['uid']) : ''; |
182 | - $tokens['url'] = is_numeric($item['uid']) ? url('user/' . $item['uid'], array('absolute' => TRUE)) : ''; |
|
182 | + $tokens['url'] = is_numeric($item['uid']) ? url('user/' . $item['uid'], array('absolute' => true)) : ''; |
|
183 | 183 | |
184 | 184 | return $tokens; |
185 | 185 | } |
@@ -10,155 +10,155 @@ |
||
10 | 10 | * Callback function to supply a list of content types. |
11 | 11 | */ |
12 | 12 | function fieldgroup_content_fieldgroup_ctools_content_types() { |
13 | - return array( |
|
13 | + return array( |
|
14 | 14 | 'title' => t('Content fieldgroup'), |
15 | 15 | 'defaults' => array('label' => 'hidden', 'format' => 'simple', 'empty' => ''), |
16 | - ); |
|
16 | + ); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Return all fieldgroup content types available. |
21 | 21 | */ |
22 | 22 | function fieldgroup_content_fieldgroup_content_type_content_types() { |
23 | - // This will hold all the individual fieldgroup content types. |
|
24 | - $types = array(); |
|
23 | + // This will hold all the individual fieldgroup content types. |
|
24 | + $types = array(); |
|
25 | 25 | |
26 | - // The outer loop goes through each node type with groups. |
|
27 | - foreach (fieldgroup_groups() as $node_type_groups) { |
|
26 | + // The outer loop goes through each node type with groups. |
|
27 | + foreach (fieldgroup_groups() as $node_type_groups) { |
|
28 | 28 | // The inner loop gives us each fieldgroup on each node type with groups. |
29 | 29 | foreach ($node_type_groups as $group) { |
30 | - // Skip field groups that are not of standard type. |
|
31 | - if ($group['group_type'] != 'standard') { |
|
30 | + // Skip field groups that are not of standard type. |
|
31 | + if ($group['group_type'] != 'standard') { |
|
32 | 32 | continue; |
33 | - } |
|
33 | + } |
|
34 | 34 | |
35 | - // Name the content type a combination of fieldgroup and node type names. |
|
36 | - $content_type_name = $group['type_name'] . ':' . $group['group_name']; |
|
35 | + // Name the content type a combination of fieldgroup and node type names. |
|
36 | + $content_type_name = $group['type_name'] . ':' . $group['group_name']; |
|
37 | 37 | |
38 | - // Assemble the information about the content type. |
|
39 | - $info = array( |
|
38 | + // Assemble the information about the content type. |
|
39 | + $info = array( |
|
40 | 40 | 'category' => t('Node'), |
41 | 41 | 'icon' => 'icon_cck_field_group.png', |
42 | 42 | 'title' => t('Field group: @group in @type', array( |
43 | - '@group' => t($group['label']), |
|
44 | - '@type' => node_get_types('name', $group['type_name']), |
|
43 | + '@group' => t($group['label']), |
|
44 | + '@type' => node_get_types('name', $group['type_name']), |
|
45 | 45 | )), |
46 | 46 | 'description' => t('All fields from this field group on the referenced node.'), |
47 | 47 | 'required context' => new ctools_context_required(t('Node'), 'node', array('type' => array($group['type_name']))), |
48 | - ); |
|
48 | + ); |
|
49 | 49 | |
50 | - $types[$content_type_name] = $info; |
|
50 | + $types[$content_type_name] = $info; |
|
51 | + } |
|
51 | 52 | } |
52 | - } |
|
53 | 53 | |
54 | - return $types; |
|
54 | + return $types; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Output function for the 'fieldgroup' content type. |
59 | 59 | */ |
60 | 60 | function fieldgroup_content_fieldgroup_content_type_render($subtype, $conf, $panel_args, $context) { |
61 | - if (!isset($context->data)) { |
|
61 | + if (!isset($context->data)) { |
|
62 | 62 | return; |
63 | - } |
|
64 | - $node = drupal_clone($context->data); |
|
63 | + } |
|
64 | + $node = drupal_clone($context->data); |
|
65 | 65 | |
66 | - // Make sure old data doesn't cause problems: |
|
67 | - if (empty($conf['label'])) { |
|
66 | + // Make sure old data doesn't cause problems: |
|
67 | + if (empty($conf['label'])) { |
|
68 | 68 | $conf['label'] = 'hidden'; |
69 | - } |
|
70 | - if (empty($conf['format'])) { |
|
69 | + } |
|
70 | + if (empty($conf['format'])) { |
|
71 | 71 | $conf['format'] = 'simple'; |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | - // Extract the node type and fieldgroup name from the subtype. |
|
75 | - list($node_type, $group_name) = explode(':', $subtype, 2); |
|
74 | + // Extract the node type and fieldgroup name from the subtype. |
|
75 | + list($node_type, $group_name) = explode(':', $subtype, 2); |
|
76 | 76 | |
77 | - // Get a list of all fieldgroups for this node type. |
|
78 | - $groups = fieldgroup_groups($node_type); |
|
77 | + // Get a list of all fieldgroups for this node type. |
|
78 | + $groups = fieldgroup_groups($node_type); |
|
79 | 79 | |
80 | - if (!isset($groups[$group_name])) { |
|
80 | + if (!isset($groups[$group_name])) { |
|
81 | 81 | return; |
82 | - } |
|
83 | - $group = $groups[$group_name]; |
|
84 | - |
|
85 | - // Render the field group. |
|
86 | - $node->build_mode = NODE_BUILD_NORMAL; |
|
87 | - $group['settings']['display']['label'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label']; |
|
88 | - $group['settings']['display']['full']['format'] = $conf['format']; |
|
89 | - $group['settings']['display']['full']['exclude'] = 0; |
|
90 | - $output = fieldgroup_view_group($group, $node); |
|
91 | - |
|
92 | - $block = new stdClass(); |
|
93 | - if ($conf['label'] == 'normal') { |
|
82 | + } |
|
83 | + $group = $groups[$group_name]; |
|
84 | + |
|
85 | + // Render the field group. |
|
86 | + $node->build_mode = NODE_BUILD_NORMAL; |
|
87 | + $group['settings']['display']['label'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label']; |
|
88 | + $group['settings']['display']['full']['format'] = $conf['format']; |
|
89 | + $group['settings']['display']['full']['exclude'] = 0; |
|
90 | + $output = fieldgroup_view_group($group, $node); |
|
91 | + |
|
92 | + $block = new stdClass(); |
|
93 | + if ($conf['label'] == 'normal') { |
|
94 | 94 | $block->title = t($group['label']); |
95 | - } |
|
96 | - $block->content = !empty($output) ? $output : $conf['empty']; |
|
97 | - return $block; |
|
95 | + } |
|
96 | + $block->content = !empty($output) ? $output : $conf['empty']; |
|
97 | + return $block; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Returns a settings form for the custom type. |
102 | 102 | */ |
103 | 103 | function fieldgroup_content_fieldgroup_content_type_edit_form(&$form, &$form_state) { |
104 | - $conf = $form_state['conf']; |
|
104 | + $conf = $form_state['conf']; |
|
105 | 105 | |
106 | - $label_options = array( |
|
106 | + $label_options = array( |
|
107 | 107 | 'normal' => t('Block title'), |
108 | 108 | 'above' => t('Above'), |
109 | - ); |
|
110 | - $form['label'] = array( |
|
109 | + ); |
|
110 | + $form['label'] = array( |
|
111 | 111 | '#type' => 'select', |
112 | 112 | '#title' => t('Field group label'), |
113 | 113 | '#default_value' => !empty($conf['label']) && isset($label_options[$conf['label']]) ? $conf['label'] : 'hidden', |
114 | 114 | '#options' => $label_options, |
115 | 115 | '#description' => t('Configure how the field group label is going to be displayed. This option takes no effect when "Override title" option is enabled, the specified block title is displayed instead.'), |
116 | - ); |
|
116 | + ); |
|
117 | 117 | |
118 | - $format_options = array( |
|
118 | + $format_options = array( |
|
119 | 119 | 'simple' => t('Simple'), |
120 | 120 | 'fieldset' => t('Fieldset'), |
121 | 121 | 'fieldset_collapsible' => t('Fieldset - Collapsible'), |
122 | 122 | 'fieldset_collapsed' => t('Fieldset - Collapsed'), |
123 | - ); |
|
124 | - $form['format'] = array( |
|
123 | + ); |
|
124 | + $form['format'] = array( |
|
125 | 125 | '#type' => 'select', |
126 | 126 | '#title' => t('Field group format'), |
127 | 127 | '#default_value' => !empty($conf['format']) && isset($format_options[$conf['format']]) ? $conf['format'] : 'simple', |
128 | 128 | '#options' => $format_options, |
129 | 129 | '#description' => t('This option allows you to configure the field group format.'), |
130 | - ); |
|
130 | + ); |
|
131 | 131 | |
132 | - $form['empty'] = array( |
|
132 | + $form['empty'] = array( |
|
133 | 133 | '#type' => 'textarea', |
134 | 134 | '#title' => t('Empty text'), |
135 | 135 | '#description' => t('Text to display if group has no data. Note that title will not display unless overridden.'), |
136 | 136 | '#rows' => 5, |
137 | 137 | '#default_value' => $conf['empty'], |
138 | - ); |
|
138 | + ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | function fieldgroup_content_fieldgroup_content_type_edit_form_submit(&$form, &$form_state) { |
142 | - // Copy everything from our defaults. |
|
143 | - foreach (array_keys($form_state['plugin']['defaults']) as $key) { |
|
142 | + // Copy everything from our defaults. |
|
143 | + foreach (array_keys($form_state['plugin']['defaults']) as $key) { |
|
144 | 144 | $form_state['conf'][$key] = $form_state['values'][$key]; |
145 | - } |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
149 | 149 | * Admin title for fieldgroup content type. |
150 | 150 | */ |
151 | 151 | function fieldgroup_content_fieldgroup_content_type_admin_title($subtype, $conf, $context) { |
152 | - // Extract the node type and fieldgroup name from the subtype. |
|
153 | - list($node_type, $group_name) = explode(':', $subtype, 2); |
|
152 | + // Extract the node type and fieldgroup name from the subtype. |
|
153 | + list($node_type, $group_name) = explode(':', $subtype, 2); |
|
154 | 154 | |
155 | - // Get information about this field group for this node type. |
|
156 | - $groups = fieldgroup_groups($node_type); |
|
157 | - $group = $groups[$group_name]; |
|
155 | + // Get information about this field group for this node type. |
|
156 | + $groups = fieldgroup_groups($node_type); |
|
157 | + $group = $groups[$group_name]; |
|
158 | 158 | |
159 | - return t('"@s" field group: @group in @type', array( |
|
159 | + return t('"@s" field group: @group in @type', array( |
|
160 | 160 | '@s' => $context->identifier, |
161 | 161 | '@group' => t($group['label']), |
162 | 162 | '@type' => node_get_types('name', $node_type), |
163 | - )); |
|
163 | + )); |
|
164 | 164 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | // Name the content type a combination of fieldgroup and node type names. |
36 | - $content_type_name = $group['type_name'] . ':' . $group['group_name']; |
|
36 | + $content_type_name = $group['type_name'].':'.$group['group_name']; |
|
37 | 37 | |
38 | 38 | // Assemble the information about the content type. |
39 | 39 | $info = array( |
@@ -16,230 +16,230 @@ discard block |
||
16 | 16 | * Implementation of hook_init(). |
17 | 17 | */ |
18 | 18 | function fieldgroup_init() { |
19 | - drupal_add_css(drupal_get_path('module', 'fieldgroup') .'/fieldgroup.css'); |
|
19 | + drupal_add_css(drupal_get_path('module', 'fieldgroup') .'/fieldgroup.css'); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Implementation of hook_ctools_plugin_directory(). |
24 | 24 | */ |
25 | 25 | function fieldgroup_ctools_plugin_directory($module, $plugin) { |
26 | - if ($module == 'ctools' && $plugin == 'content_types') { |
|
26 | + if ($module == 'ctools' && $plugin == 'content_types') { |
|
27 | 27 | return 'panels/' . $plugin; |
28 | - } |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Implementation of hook_menu(). |
33 | 33 | */ |
34 | 34 | function fieldgroup_menu() { |
35 | - $items = array(); |
|
35 | + $items = array(); |
|
36 | 36 | |
37 | - // Make sure this doesn't fire until content_types is working, |
|
38 | - // needed to avoid errors on initial installation. |
|
39 | - if (!defined('MAINTENANCE_MODE')) { |
|
37 | + // Make sure this doesn't fire until content_types is working, |
|
38 | + // needed to avoid errors on initial installation. |
|
39 | + if (!defined('MAINTENANCE_MODE')) { |
|
40 | 40 | foreach (node_get_types() as $type) { |
41 | - $type_name = $type->type; |
|
42 | - $content_type = content_types($type_name); |
|
43 | - $type_url_str = $content_type['url_str']; |
|
44 | - $items['admin/content/node-type/'. $type_url_str .'/groups/%'] = array( |
|
41 | + $type_name = $type->type; |
|
42 | + $content_type = content_types($type_name); |
|
43 | + $type_url_str = $content_type['url_str']; |
|
44 | + $items['admin/content/node-type/'. $type_url_str .'/groups/%'] = array( |
|
45 | 45 | 'title' => 'Edit group', |
46 | 46 | 'page callback' => 'drupal_get_form', |
47 | 47 | 'page arguments' => array('fieldgroup_group_edit_form', $type_name, 5), |
48 | 48 | 'access arguments' => array('administer content types'), |
49 | 49 | 'type' => MENU_CALLBACK, |
50 | - ); |
|
51 | - $items['admin/content/node-type/'. $type_url_str .'/groups/%/remove'] = array( |
|
50 | + ); |
|
51 | + $items['admin/content/node-type/'. $type_url_str .'/groups/%/remove'] = array( |
|
52 | 52 | 'title' => 'Edit group', |
53 | 53 | 'page callback' => 'drupal_get_form', |
54 | 54 | 'page arguments' => array('fieldgroup_remove_group', $type_name, 5), |
55 | 55 | 'access arguments' => array('administer content types'), |
56 | 56 | 'type' => MENU_CALLBACK, |
57 | - ); |
|
57 | + ); |
|
58 | 58 | } |
59 | - } |
|
60 | - return $items; |
|
59 | + } |
|
60 | + return $items; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Implementation of hook_theme(). |
65 | 65 | */ |
66 | 66 | function fieldgroup_theme() { |
67 | - return array( |
|
67 | + return array( |
|
68 | 68 | 'fieldgroup_simple' => array( |
69 | - 'template' => 'fieldgroup-simple', |
|
70 | - 'arguments' => array('element' => NULL), |
|
69 | + 'template' => 'fieldgroup-simple', |
|
70 | + 'arguments' => array('element' => NULL), |
|
71 | 71 | ), |
72 | 72 | 'fieldgroup_fieldset' => array( |
73 | - 'arguments' => array('element' => NULL), |
|
73 | + 'arguments' => array('element' => NULL), |
|
74 | 74 | ), |
75 | 75 | 'fieldgroup_display_overview_form' => array( |
76 | - 'arguments' => array('form' => NULL), |
|
76 | + 'arguments' => array('form' => NULL), |
|
77 | 77 | ), |
78 | - ); |
|
78 | + ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Implementation of hook_elements(). |
83 | 83 | */ |
84 | 84 | function fieldgroup_elements() { |
85 | - return array( |
|
85 | + return array( |
|
86 | 86 | 'fieldgroup_simple' => array(), |
87 | 87 | 'fieldgroup_fieldset' => array('#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL,), |
88 | - ); |
|
88 | + ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Implementation of hook_fieldapi(). |
93 | 93 | */ |
94 | 94 | function fieldgroup_content_fieldapi($op, $field) { |
95 | - switch ($op) { |
|
95 | + switch ($op) { |
|
96 | 96 | case 'delete instance': |
97 | 97 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
98 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
99 | - break; |
|
100 | - } |
|
98 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
99 | + break; |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | function fieldgroup_group_edit_form(&$form_state, $type_name, $group_name) { |
104 | - $content_type = content_types($type_name); |
|
105 | - $groups = fieldgroup_groups($content_type['type']); |
|
104 | + $content_type = content_types($type_name); |
|
105 | + $groups = fieldgroup_groups($content_type['type']); |
|
106 | 106 | |
107 | - if (!$group = $groups[$group_name]) { |
|
107 | + if (!$group = $groups[$group_name]) { |
|
108 | 108 | drupal_not_found(); |
109 | 109 | exit; |
110 | - } |
|
110 | + } |
|
111 | 111 | |
112 | - $form['label'] = array( |
|
112 | + $form['label'] = array( |
|
113 | 113 | '#type' => 'textfield', |
114 | 114 | '#title' => t('Label'), |
115 | 115 | '#default_value' => $group['label'], |
116 | 116 | '#required' => TRUE, |
117 | - ); |
|
117 | + ); |
|
118 | 118 | |
119 | - // Set a default value for group type early in the form so it |
|
120 | - // can be overridden by subsequent form elements added by other modules. |
|
121 | - $group_type = !empty($group['group_type']) ? $group['group_type'] : 'standard'; |
|
122 | - $form['group_type'] = array('#type' => 'hidden', '#default_value' => $group_type); |
|
119 | + // Set a default value for group type early in the form so it |
|
120 | + // can be overridden by subsequent form elements added by other modules. |
|
121 | + $group_type = !empty($group['group_type']) ? $group['group_type'] : 'standard'; |
|
122 | + $form['group_type'] = array('#type' => 'hidden', '#default_value' => $group_type); |
|
123 | 123 | |
124 | - $form['settings']['#tree'] = TRUE; |
|
125 | - $form['settings']['form'] = array( |
|
124 | + $form['settings']['#tree'] = TRUE; |
|
125 | + $form['settings']['form'] = array( |
|
126 | 126 | '#type' => 'fieldset', |
127 | 127 | '#title' => t('Form settings'), |
128 | 128 | '#description' => t('These settings apply to the group in the node editing form.'), |
129 | - ); |
|
130 | - $form['settings']['form']['style'] = array( |
|
129 | + ); |
|
130 | + $form['settings']['form']['style'] = array( |
|
131 | 131 | '#type' => 'radios', |
132 | 132 | '#title' => t('Style'), |
133 | 133 | '#default_value' => $group['settings']['form']['style'], |
134 | 134 | '#options' => array( |
135 | - 'fieldset' => t('always open'), |
|
136 | - 'fieldset_collapsible' => t('collapsible'), |
|
137 | - 'fieldset_collapsed' => t('collapsed'), |
|
135 | + 'fieldset' => t('always open'), |
|
136 | + 'fieldset_collapsible' => t('collapsible'), |
|
137 | + 'fieldset_collapsed' => t('collapsed'), |
|
138 | 138 | ) |
139 | - ); |
|
140 | - $form['settings']['form']['description'] = array( |
|
139 | + ); |
|
140 | + $form['settings']['form']['description'] = array( |
|
141 | 141 | '#type' => 'textarea', |
142 | 142 | '#title' => t('Help text'), |
143 | 143 | '#default_value' => $group['settings']['form']['description'], |
144 | 144 | '#rows' => 5, |
145 | 145 | '#description' => t('Instructions to present to the user on the editing form.'), |
146 | 146 | '#required' => FALSE, |
147 | - ); |
|
148 | - $form['settings']['display'] = array( |
|
147 | + ); |
|
148 | + $form['settings']['display'] = array( |
|
149 | 149 | '#type' => 'fieldset', |
150 | 150 | '#title' => t('Display settings'), |
151 | 151 | '#description' => t('These settings apply to the group on node display.'), |
152 | - ); |
|
153 | - $form['settings']['display']['description'] = array( |
|
152 | + ); |
|
153 | + $form['settings']['display']['description'] = array( |
|
154 | 154 | '#type' => 'textarea', |
155 | 155 | '#title' => t('Description'), |
156 | 156 | '#default_value' => $group['settings']['display']['description'], |
157 | 157 | '#rows' => 5, |
158 | 158 | '#description' => t('A description of the group.'), |
159 | 159 | '#required' => FALSE, |
160 | - ); |
|
160 | + ); |
|
161 | 161 | |
162 | - foreach (array_keys(content_build_modes()) as $key) { |
|
162 | + foreach (array_keys(content_build_modes()) as $key) { |
|
163 | 163 | $form['settings']['display'][$key]['format'] = array('#type' => 'value', '#value' => isset($group['settings']['display'][$key]['format']) ? $group['settings']['display'][$key]['format'] : 'fieldset'); |
164 | 164 | $form['settings']['display'][$key]['exclude'] = array('#type' => 'value', '#value' => isset($group['settings']['display'][$key]['exclude']) ? $group['settings']['display'][$key]['exclude'] : 0); |
165 | - } |
|
166 | - $form['settings']['display']['label'] = array('#type' => 'value', '#value' => $group['settings']['display']['label']); |
|
167 | - $form['weight'] = array('#type' => 'hidden', '#default_value' => $group['weight']); |
|
168 | - $form['group_name'] = array('#type' => 'hidden', '#default_value' => $group_name); |
|
165 | + } |
|
166 | + $form['settings']['display']['label'] = array('#type' => 'value', '#value' => $group['settings']['display']['label']); |
|
167 | + $form['weight'] = array('#type' => 'hidden', '#default_value' => $group['weight']); |
|
168 | + $form['group_name'] = array('#type' => 'hidden', '#default_value' => $group_name); |
|
169 | 169 | |
170 | - $form['#content_type'] = $content_type; |
|
170 | + $form['#content_type'] = $content_type; |
|
171 | 171 | |
172 | - $form['submit'] = array( |
|
172 | + $form['submit'] = array( |
|
173 | 173 | '#type' => 'submit', |
174 | 174 | '#value' => t('Save'), |
175 | 175 | '#weight' => 10, |
176 | - ); |
|
176 | + ); |
|
177 | 177 | |
178 | - return $form; |
|
178 | + return $form; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | function fieldgroup_group_edit_form_submit($form, &$form_state) { |
182 | - $form_values = $form_state['values']; |
|
183 | - $content_type = $form['#content_type']; |
|
184 | - fieldgroup_save_group($content_type['type'], $form_values); |
|
185 | - $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
182 | + $form_values = $form_state['values']; |
|
183 | + $content_type = $form['#content_type']; |
|
184 | + fieldgroup_save_group($content_type['type'], $form_values); |
|
185 | + $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | function fieldgroup_remove_group(&$form_state, $type_name, $group_name) { |
189 | - $content_type = content_types($type_name); |
|
190 | - $groups = fieldgroup_groups($content_type['type']); |
|
191 | - $group = isset($groups[$group_name]) ? $groups[$group_name] : ''; |
|
189 | + $content_type = content_types($type_name); |
|
190 | + $groups = fieldgroup_groups($content_type['type']); |
|
191 | + $group = isset($groups[$group_name]) ? $groups[$group_name] : ''; |
|
192 | 192 | |
193 | - if (empty($group)) { |
|
193 | + if (empty($group)) { |
|
194 | 194 | drupal_not_found(); |
195 | 195 | exit; |
196 | - } |
|
196 | + } |
|
197 | 197 | |
198 | - $form['#submit'][] = 'fieldgroup_remove_group_submit'; |
|
199 | - $form['#content_type'] = $content_type; |
|
200 | - $form['#group_name'] = $group_name; |
|
198 | + $form['#submit'][] = 'fieldgroup_remove_group_submit'; |
|
199 | + $form['#content_type'] = $content_type; |
|
200 | + $form['#group_name'] = $group_name; |
|
201 | 201 | |
202 | - return confirm_form($form, |
|
203 | - t('Are you sure you want to remove the group %label?', |
|
204 | - array('%label' => t($group['label']))), |
|
205 | - 'admin/content/node-type/'. $content_type['url_str'] .'/fields', t('This action cannot be undone.'), |
|
206 | - t('Remove'), t('Cancel')); |
|
202 | + return confirm_form($form, |
|
203 | + t('Are you sure you want to remove the group %label?', |
|
204 | + array('%label' => t($group['label']))), |
|
205 | + 'admin/content/node-type/'. $content_type['url_str'] .'/fields', t('This action cannot be undone.'), |
|
206 | + t('Remove'), t('Cancel')); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | function fieldgroup_remove_group_submit($form, &$form_state) { |
210 | - $form_values = $form_state['values']; |
|
211 | - $content_type = $form['#content_type']; |
|
212 | - $group_name = $form['#group_name']; |
|
213 | - fieldgroup_delete($content_type['type'], $group_name); |
|
214 | - drupal_set_message(t('The group %group_name has been removed.', array('%group_name' => $group_name))); |
|
215 | - $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
210 | + $form_values = $form_state['values']; |
|
211 | + $content_type = $form['#content_type']; |
|
212 | + $group_name = $form['#group_name']; |
|
213 | + fieldgroup_delete($content_type['type'], $group_name); |
|
214 | + drupal_set_message(t('The group %group_name has been removed.', array('%group_name' => $group_name))); |
|
215 | + $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | 219 | * Returns all groups for a content type |
220 | 220 | */ |
221 | 221 | function fieldgroup_groups($content_type = '', $sorted = FALSE, $reset = FALSE) { |
222 | - global $language; |
|
223 | - static $groups, $groups_sorted; |
|
224 | - if (!isset($groups) || $reset) { |
|
222 | + global $language; |
|
223 | + static $groups, $groups_sorted; |
|
224 | + if (!isset($groups) || $reset) { |
|
225 | 225 | if ($cached = cache_get('fieldgroup_data:'. $language->language, content_cache_tablename())) { |
226 | - $data = $cached->data; |
|
227 | - $groups = $data['groups']; |
|
228 | - $groups_sorted = $data['groups_sorted']; |
|
226 | + $data = $cached->data; |
|
227 | + $groups = $data['groups']; |
|
228 | + $groups_sorted = $data['groups_sorted']; |
|
229 | 229 | } |
230 | 230 | else { |
231 | - $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name"); |
|
232 | - $groups = array(); |
|
233 | - $groups_sorted = array(); |
|
234 | - while ($group = db_fetch_array($result)) { |
|
231 | + $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name"); |
|
232 | + $groups = array(); |
|
233 | + $groups_sorted = array(); |
|
234 | + while ($group = db_fetch_array($result)) { |
|
235 | 235 | $group['settings'] = unserialize($group['settings']); |
236 | 236 | $group['fields'] = array(); |
237 | 237 | |
238 | 238 | // Allow external modules to translate field group strings. |
239 | 239 | $group_strings = array( |
240 | - 'label' => $group['label'], |
|
241 | - 'form_description' => $group['settings']['form']['description'], |
|
242 | - 'display_description' => $group['settings']['display']['description'], |
|
240 | + 'label' => $group['label'], |
|
241 | + 'form_description' => $group['settings']['form']['description'], |
|
242 | + 'display_description' => $group['settings']['display']['description'], |
|
243 | 243 | ); |
244 | 244 | drupal_alter('content_fieldgroup_strings', $group_strings, $group['type_name'], $group['group_name']); |
245 | 245 | $group['label'] = $group_strings['label']; |
@@ -248,58 +248,58 @@ discard block |
||
248 | 248 | |
249 | 249 | $groups[$group['type_name']][$group['group_name']] = $group; |
250 | 250 | $groups_sorted[$group['type_name']][] = &$groups[$group['type_name']][$group['group_name']]; |
251 | - } |
|
252 | - //load fields |
|
253 | - $result = db_query("SELECT nfi.*, ng.group_name FROM {". fieldgroup_tablename() ."} ng ". |
|
254 | - "INNER JOIN {". fieldgroup_fields_tablename() ."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ". |
|
255 | - "INNER JOIN {". content_instance_tablename() ."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ". |
|
256 | - "WHERE nfi.widget_active = 1 ORDER BY nfi.weight"); |
|
257 | - while ($field = db_fetch_array($result)) { |
|
251 | + } |
|
252 | + //load fields |
|
253 | + $result = db_query("SELECT nfi.*, ng.group_name FROM {". fieldgroup_tablename() ."} ng ". |
|
254 | + "INNER JOIN {". fieldgroup_fields_tablename() ."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ". |
|
255 | + "INNER JOIN {". content_instance_tablename() ."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ". |
|
256 | + "WHERE nfi.widget_active = 1 ORDER BY nfi.weight"); |
|
257 | + while ($field = db_fetch_array($result)) { |
|
258 | 258 | // Allow external modules to translate field strings. |
259 | 259 | $field_strings = array( |
260 | - 'widget_label' => $field['label'], |
|
261 | - 'widget_description' => $field['description'], |
|
260 | + 'widget_label' => $field['label'], |
|
261 | + 'widget_description' => $field['description'], |
|
262 | 262 | ); |
263 | 263 | drupal_alter('content_field_strings', $field_strings, $field['type_name'], $field['field_name']); |
264 | 264 | $field['label'] = $field_strings['widget_label']; |
265 | 265 | $field['description'] = $field_strings['widget_description']; |
266 | 266 | |
267 | 267 | $groups[$field['type_name']][$field['group_name']]['fields'][$field['field_name']] = $field; |
268 | - } |
|
269 | - cache_set('fieldgroup_data:'. $language->language, array('groups' => $groups, 'groups_sorted' => $groups_sorted), content_cache_tablename()); |
|
268 | + } |
|
269 | + cache_set('fieldgroup_data:'. $language->language, array('groups' => $groups, 'groups_sorted' => $groups_sorted), content_cache_tablename()); |
|
270 | + } |
|
270 | 271 | } |
271 | - } |
|
272 | - if (empty($content_type)) { |
|
272 | + if (empty($content_type)) { |
|
273 | 273 | return $groups; |
274 | - } |
|
275 | - elseif (empty($groups) || empty($groups[$content_type])) { |
|
274 | + } |
|
275 | + elseif (empty($groups) || empty($groups[$content_type])) { |
|
276 | 276 | return array(); |
277 | - } |
|
278 | - return $sorted ? $groups_sorted[$content_type] : $groups[$content_type]; |
|
277 | + } |
|
278 | + return $sorted ? $groups_sorted[$content_type] : $groups[$content_type]; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | |
282 | 282 | function _fieldgroup_groups_label($content_type) { |
283 | - $groups = fieldgroup_groups($content_type); |
|
283 | + $groups = fieldgroup_groups($content_type); |
|
284 | 284 | |
285 | - $labels[''] = '<'. t('none') .'>'; |
|
286 | - foreach ($groups as $group_name => $group) { |
|
285 | + $labels[''] = '<'. t('none') .'>'; |
|
286 | + foreach ($groups as $group_name => $group) { |
|
287 | 287 | $labels[$group_name] = t($group['label']); |
288 | - } |
|
289 | - return $labels; |
|
288 | + } |
|
289 | + return $labels; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | function _fieldgroup_field_get_group($content_type, $field_name) { |
293 | - return db_result(db_query("SELECT group_name FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name)); |
|
293 | + return db_result(db_query("SELECT group_name FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name)); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | 297 | * Implementation of hook_form_alter() |
298 | 298 | */ |
299 | 299 | function fieldgroup_form_alter(&$form, $form_state, $form_id) { |
300 | - if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
300 | + if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
301 | 301 | foreach (fieldgroup_groups($form['type']['#value']) as $group_name => $group) { |
302 | - $form[$group_name] = array( |
|
302 | + $form[$group_name] = array( |
|
303 | 303 | '#type' => 'fieldset', |
304 | 304 | '#title' => check_plain(t($group['label'])), |
305 | 305 | '#collapsed' => $group['settings']['form']['style'] == 'fieldset_collapsed', |
@@ -307,62 +307,62 @@ discard block |
||
307 | 307 | '#weight' => $group['weight'], |
308 | 308 | '#description' => content_filter_xss(t($group['settings']['form']['description'])), |
309 | 309 | '#attributes' => array('class' => strtr($group['group_name'], '_', '-')), |
310 | - ); |
|
310 | + ); |
|
311 | 311 | |
312 | - $has_accessible_field = FALSE; |
|
313 | - foreach ($group['fields'] as $field_name => $field) { |
|
312 | + $has_accessible_field = FALSE; |
|
313 | + foreach ($group['fields'] as $field_name => $field) { |
|
314 | 314 | if (isset($form[$field_name])) { |
315 | - $form[$group_name][$field_name] = $form[$field_name]; |
|
316 | - // Track whether this group has any accessible fields within it. |
|
317 | - if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== FALSE) { |
|
315 | + $form[$group_name][$field_name] = $form[$field_name]; |
|
316 | + // Track whether this group has any accessible fields within it. |
|
317 | + if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== FALSE) { |
|
318 | 318 | $has_accessible_field = TRUE; |
319 | - } |
|
320 | - unset($form[$field_name]); |
|
319 | + } |
|
320 | + unset($form[$field_name]); |
|
321 | + } |
|
321 | 322 | } |
322 | - } |
|
323 | - if (!empty($group['fields']) && !element_children($form[$group_name])) { |
|
323 | + if (!empty($group['fields']) && !element_children($form[$group_name])) { |
|
324 | 324 | //hide the fieldgroup, because the fields are hidden too |
325 | 325 | unset($form[$group_name]); |
326 | - } |
|
326 | + } |
|
327 | 327 | |
328 | - if (!$has_accessible_field) { |
|
328 | + if (!$has_accessible_field) { |
|
329 | 329 | // Hide the fieldgroup, because the fields are inaccessible. |
330 | 330 | $form[$group_name]['#access'] = FALSE; |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | - // Allow other modules to alter the form. |
|
334 | - // Can't use module_invoke_all because we want |
|
335 | - // to be able to use a reference to $form and $form_state. |
|
336 | - foreach (module_implements('fieldgroup_form') as $module) { |
|
333 | + // Allow other modules to alter the form. |
|
334 | + // Can't use module_invoke_all because we want |
|
335 | + // to be able to use a reference to $form and $form_state. |
|
336 | + foreach (module_implements('fieldgroup_form') as $module) { |
|
337 | 337 | $function = $module .'_fieldgroup_form'; |
338 | 338 | $function($form, $form_state, $form_id, $group); |
339 | - } |
|
339 | + } |
|
340 | 340 | |
341 | 341 | } |
342 | 342 | |
343 | - } |
|
344 | - // The group is only added here so it will appear in the export |
|
345 | - // when using Content Copy. |
|
346 | - elseif ($form_id == 'content_field_edit_form' && isset($form['widget'])) { |
|
343 | + } |
|
344 | + // The group is only added here so it will appear in the export |
|
345 | + // when using Content Copy. |
|
346 | + elseif ($form_id == 'content_field_edit_form' && isset($form['widget'])) { |
|
347 | 347 | $content_type = content_types($form['type_name']['#value']); |
348 | 348 | $form['widget']['group'] = array( |
349 | - '#type' => 'value', |
|
350 | - '#value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']), |
|
349 | + '#type' => 'value', |
|
350 | + '#value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']), |
|
351 | 351 | ); |
352 | - } |
|
353 | - elseif ($form_id == 'content_field_overview_form') { |
|
352 | + } |
|
353 | + elseif ($form_id == 'content_field_overview_form') { |
|
354 | 354 | $form['#validate'][] = 'fieldgroup_field_overview_form_validate'; |
355 | 355 | $form['#submit'][] = 'fieldgroup_field_overview_form_submit'; |
356 | - } |
|
357 | - elseif ($form_id == 'content_display_overview_form' && !empty($form['#groups'])) { |
|
356 | + } |
|
357 | + elseif ($form_id == 'content_display_overview_form' && !empty($form['#groups'])) { |
|
358 | 358 | $form['#submit'][] = 'fieldgroup_display_overview_form_submit'; |
359 | 359 | if (!isset($form['submit'])) { |
360 | - $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 10); |
|
360 | + $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 10); |
|
361 | 361 | } |
362 | - } |
|
363 | - elseif ($form_id == 'content_field_remove_form') { |
|
362 | + } |
|
363 | + elseif ($form_id == 'content_field_remove_form') { |
|
364 | 364 | $form['#submit'][] = 'fieldgroup_field_remove_form_submit'; |
365 | - } |
|
365 | + } |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -371,185 +371,185 @@ discard block |
||
371 | 371 | * Pulled into separate function to be re-usable. |
372 | 372 | */ |
373 | 373 | function fieldgroup_validate_name($group, $type_name) { |
374 | - $errors = array(); |
|
374 | + $errors = array(); |
|
375 | 375 | |
376 | - // No label. |
|
377 | - if (!$group['label']) { |
|
376 | + // No label. |
|
377 | + if (!$group['label']) { |
|
378 | 378 | $errors['label'][] = t('You need to provide a label.'); |
379 | - } |
|
379 | + } |
|
380 | 380 | |
381 | - // No group name. |
|
382 | - if (!$group['group_name']) { |
|
381 | + // No group name. |
|
382 | + if (!$group['group_name']) { |
|
383 | 383 | $errors['group_name'][] = t('You need to provide a group name.'); |
384 | - } |
|
385 | - // Group name validation. |
|
386 | - else { |
|
384 | + } |
|
385 | + // Group name validation. |
|
386 | + else { |
|
387 | 387 | $group_name = $group['group_name']; |
388 | 388 | $group['group_type'] = !empty($group['group_type']) ? $group['group_type'] : 'standard'; |
389 | 389 | |
390 | 390 | // Add the 'group_' prefix. |
391 | 391 | if (substr($group_name, 0, 6) != 'group_') { |
392 | - $group_name = 'group_'. $group_name; |
|
392 | + $group_name = 'group_'. $group_name; |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | // Invalid field name. |
396 | 396 | if (!preg_match('!^group_[a-z0-9_]+$!', $group_name)) { |
397 | - $errors['group_name'][] = t('The group name %group_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%group_name' => $group_name)); |
|
397 | + $errors['group_name'][] = t('The group name %group_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%group_name' => $group_name)); |
|
398 | 398 | } |
399 | 399 | if (strlen($group_name) > 32) { |
400 | - $errors['group_name'][] = t('The group name %group_name is too long. The name is limited to 32 characters, including the \'group_\' prefix.', array('%group_name' => $group_name)); |
|
400 | + $errors['group_name'][] = t('The group name %group_name is too long. The name is limited to 32 characters, including the \'group_\' prefix.', array('%group_name' => $group_name)); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | // Group name already exists. |
404 | 404 | $groups = fieldgroup_groups($type_name); |
405 | 405 | if (isset($groups[$group_name])) { |
406 | - $errors['group_name'][] = t('The group name %group_name already exists.', array('%group_name' => $group_name)); |
|
406 | + $errors['group_name'][] = t('The group name %group_name already exists.', array('%group_name' => $group_name)); |
|
407 | 407 | } |
408 | 408 | if (empty($errors['group_name'])) { |
409 | - $group['group_name'] = $group_name; |
|
409 | + $group['group_name'] = $group_name; |
|
410 | + } |
|
410 | 411 | } |
411 | - } |
|
412 | - return array('group_name' => $group['group_name'], 'errors' => $errors); |
|
412 | + return array('group_name' => $group['group_name'], 'errors' => $errors); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | function fieldgroup_field_overview_form_validate($form, &$form_state) { |
416 | - $form_values = $form_state['values']; |
|
417 | - $group = $form_values['_add_new_group']; |
|
416 | + $form_values = $form_state['values']; |
|
417 | + $group = $form_values['_add_new_group']; |
|
418 | 418 | |
419 | - if (array_filter(array($group['label'], $group['group_name']))) { |
|
419 | + if (array_filter(array($group['label'], $group['group_name']))) { |
|
420 | 420 | $validation = fieldgroup_validate_name($group, $form['#type_name']); |
421 | 421 | if (!empty($validation['errors'])) { |
422 | - foreach ($validation['errors'] as $type => $messages) { |
|
422 | + foreach ($validation['errors'] as $type => $messages) { |
|
423 | 423 | foreach ($messages as $message) { |
424 | - if ($type == 'label') { |
|
424 | + if ($type == 'label') { |
|
425 | 425 | form_set_error('_add_new_group][label', t('Add new group:') .' '. $message); |
426 | - } |
|
427 | - else { |
|
426 | + } |
|
427 | + else { |
|
428 | 428 | form_set_error('_add_new_group][group_name', t('Add new group:') .' '. $message); |
429 | - } |
|
429 | + } |
|
430 | + } |
|
430 | 431 | } |
431 | - } |
|
432 | 432 | } |
433 | 433 | $group_name = $validation['group_name']; |
434 | 434 | form_set_value($form['_add_new_group']['group_name'], $group_name, $form_state); |
435 | - } |
|
436 | - else { |
|
435 | + } |
|
436 | + else { |
|
437 | 437 | // Fail validation if attempt to nest fields under a new group without the |
438 | 438 | // proper information. Not raising an error would cause the nested fields |
439 | 439 | // to get weights the user doesn't expect. |
440 | 440 | |
441 | 441 | foreach ($form_values as $key => $values) { |
442 | - if ($values['parent'] == '_add_new_group') { |
|
442 | + if ($values['parent'] == '_add_new_group') { |
|
443 | 443 | form_set_error('_add_new_group][label', t('Add new group: you need to provide a label.')); |
444 | 444 | form_set_error('_add_new_group][group_name', t('Add new group: you need to provide a group name.')); |
445 | 445 | break; |
446 | - } |
|
446 | + } |
|
447 | + } |
|
447 | 448 | } |
448 | - } |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | function fieldgroup_field_overview_form_submit($form, &$form_state) { |
452 | - $form_values = $form_state['values']; |
|
453 | - $type_name = $form['#type_name']; |
|
452 | + $form_values = $form_state['values']; |
|
453 | + $type_name = $form['#type_name']; |
|
454 | 454 | |
455 | - // Create new group if needed. |
|
456 | - if (!empty($form_values['_add_new_group']['label'])) { |
|
455 | + // Create new group if needed. |
|
456 | + if (!empty($form_values['_add_new_group']['label'])) { |
|
457 | 457 | $group = $form_values['_add_new_group']; |
458 | 458 | $group['settings'] = field_group_default_settings($group['group_type']); |
459 | 459 | fieldgroup_save_group($type_name, $group); |
460 | 460 | $new_group_name = $group['group_name']; |
461 | - } |
|
461 | + } |
|
462 | 462 | |
463 | - // Parse incoming rows. |
|
464 | - $add_field_rows = array('_add_new_field', '_add_existing_field'); |
|
465 | - $field_rows = array_merge($form['#fields'], $add_field_rows); |
|
466 | - foreach ($form_values as $key => $values) { |
|
463 | + // Parse incoming rows. |
|
464 | + $add_field_rows = array('_add_new_field', '_add_existing_field'); |
|
465 | + $field_rows = array_merge($form['#fields'], $add_field_rows); |
|
466 | + foreach ($form_values as $key => $values) { |
|
467 | 467 | // If 'field' row: update field parenting. |
468 | 468 | if (in_array($key, $field_rows)) { |
469 | - // If newly added fields were added to a group: |
|
470 | - if (in_array($key, $add_field_rows)) { |
|
469 | + // If newly added fields were added to a group: |
|
470 | + if (in_array($key, $add_field_rows)) { |
|
471 | 471 | // We replace the '_add_*_field' key with the actual name of |
472 | 472 | // the field that got added. |
473 | 473 | // content_field_overview_form_submit() placed those |
474 | 474 | // in $form_state['fields_added'] for us. |
475 | 475 | if (isset($form_state['fields_added'][$key])) { |
476 | - $key = $form_state['fields_added'][$key]; |
|
476 | + $key = $form_state['fields_added'][$key]; |
|
477 | 477 | } |
478 | 478 | else { |
479 | - // No field was actually created : skip to next row. |
|
480 | - continue; |
|
479 | + // No field was actually created : skip to next row. |
|
480 | + continue; |
|
481 | 481 | } |
482 | - } |
|
483 | - // If the field was added to the newly created group, replace the |
|
484 | - // '_add_new_group' value with the actual name of the group. |
|
485 | - $parent = ($values['parent'] == '_add_new_group' && isset($new_group_name)) ? $new_group_name : $values['parent']; |
|
486 | - // TODO: check the parent group does exist ? |
|
487 | - fieldgroup_update_fields(array('field_name' => $key, 'group' => $parent, 'type_name' => $type_name)); |
|
482 | + } |
|
483 | + // If the field was added to the newly created group, replace the |
|
484 | + // '_add_new_group' value with the actual name of the group. |
|
485 | + $parent = ($values['parent'] == '_add_new_group' && isset($new_group_name)) ? $new_group_name : $values['parent']; |
|
486 | + // TODO: check the parent group does exist ? |
|
487 | + fieldgroup_update_fields(array('field_name' => $key, 'group' => $parent, 'type_name' => $type_name)); |
|
488 | 488 | } |
489 | 489 | |
490 | 490 | // If 'group' row: update groups weights |
491 | 491 | // (possible newly created group has already been taken care of). |
492 | 492 | elseif (in_array($key, $form['#groups'])) { |
493 | - db_query("UPDATE {". fieldgroup_tablename() ."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'", |
|
493 | + db_query("UPDATE {". fieldgroup_tablename() ."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'", |
|
494 | 494 | $values['weight'], $type_name, $key); |
495 | 495 | } |
496 | - } |
|
496 | + } |
|
497 | 497 | |
498 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
498 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | function field_group_default_settings($group_type) { |
502 | - $settings = array( |
|
502 | + $settings = array( |
|
503 | 503 | 'form' => array('style' => 'fieldset', 'description' => ''), |
504 | 504 | 'display' => array('description' => '', 'label' => 'above'), |
505 | - ); |
|
506 | - module_load_include('inc', 'content', 'includes/content.admin'); |
|
507 | - foreach (array_keys(content_build_modes()) as $key) { |
|
505 | + ); |
|
506 | + module_load_include('inc', 'content', 'includes/content.admin'); |
|
507 | + foreach (array_keys(content_build_modes()) as $key) { |
|
508 | 508 | $settings['display'][$key]['format'] = 'fieldset'; |
509 | 509 | $settings['display'][$key]['exclude'] = 0; |
510 | - } |
|
511 | - // Allow other modules to add new default settings. |
|
512 | - $settings = array_merge($settings, module_invoke_all('fieldgroup_default_settings', $group_type)); |
|
513 | - return $settings; |
|
510 | + } |
|
511 | + // Allow other modules to add new default settings. |
|
512 | + $settings = array_merge($settings, module_invoke_all('fieldgroup_default_settings', $group_type)); |
|
513 | + return $settings; |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | function fieldgroup_display_overview_form_submit($form, &$form_state) { |
517 | - $form_values = $form_state['values']; |
|
518 | - $groups = fieldgroup_groups($form['#type_name']); |
|
519 | - foreach ($form_values as $key => $values) { |
|
517 | + $form_values = $form_state['values']; |
|
518 | + $groups = fieldgroup_groups($form['#type_name']); |
|
519 | + foreach ($form_values as $key => $values) { |
|
520 | 520 | if (in_array($key, $form['#groups'])) { |
521 | - $group = $groups[$key]; |
|
522 | - // We have some numeric keys here, so we can't use array_merge. |
|
523 | - $group['settings']['display'] = $values + $group['settings']['display']; |
|
524 | - fieldgroup_save_group($form['#type_name'], $group); |
|
521 | + $group = $groups[$key]; |
|
522 | + // We have some numeric keys here, so we can't use array_merge. |
|
523 | + $group['settings']['display'] = $values + $group['settings']['display']; |
|
524 | + fieldgroup_save_group($form['#type_name'], $group); |
|
525 | + } |
|
525 | 526 | } |
526 | - } |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | function fieldgroup_field_remove_form_submit($form, &$form_state) { |
530 | - $form_values = $form_state['values']; |
|
531 | - // TODO: |
|
532 | - // - when a (non last) field is removed from a group, a 'ghost row' remains in the fields overview |
|
533 | - // - when the last field is removed, the group disappears |
|
534 | - // seems to be fixed when emptying the cache. |
|
535 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
530 | + $form_values = $form_state['values']; |
|
531 | + // TODO: |
|
532 | + // - when a (non last) field is removed from a group, a 'ghost row' remains in the fields overview |
|
533 | + // - when the last field is removed, the group disappears |
|
534 | + // seems to be fixed when emptying the cache. |
|
535 | + db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
539 | 539 | * Implementation of hook_nodeapi(). |
540 | 540 | */ |
541 | 541 | function fieldgroup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
542 | - switch ($op) { |
|
542 | + switch ($op) { |
|
543 | 543 | case 'view': |
544 | 544 | // Prevent against invalid 'nodes' built by broken 3rd party code. |
545 | 545 | if (isset($node->type)) { |
546 | 546 | // Build the node content element needed to render each fieldgroup. |
547 | 547 | foreach (fieldgroup_groups($node->type) as $group) { |
548 | - fieldgroup_build_content($group, $node, $teaser, $page); |
|
548 | + fieldgroup_build_content($group, $node, $teaser, $page); |
|
549 | + } |
|
549 | 550 | } |
550 | - } |
|
551 | - break; |
|
552 | - } |
|
551 | + break; |
|
552 | + } |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -569,80 +569,80 @@ discard block |
||
569 | 569 | * @see fieldgroup_view_group() |
570 | 570 | */ |
571 | 571 | function fieldgroup_build_content($group, &$node, $teaser, $page) { |
572 | - // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
573 | - if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
572 | + // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
573 | + if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
574 | 574 | $context = $teaser ? 'teaser' : 'full'; |
575 | - } |
|
576 | - else { |
|
575 | + } |
|
576 | + else { |
|
577 | 577 | $context = $node->build_mode; |
578 | - } |
|
578 | + } |
|
579 | 579 | |
580 | - $group_name = $group['group_name']; |
|
580 | + $group_name = $group['group_name']; |
|
581 | 581 | |
582 | - // Do not include group labels when indexing content. |
|
583 | - if ($context == NODE_BUILD_SEARCH_INDEX) { |
|
582 | + // Do not include group labels when indexing content. |
|
583 | + if ($context == NODE_BUILD_SEARCH_INDEX) { |
|
584 | 584 | $group['settings']['display']['label'] = 'hidden'; |
585 | - } |
|
586 | - $label = $group['settings']['display']['label'] == 'above'; |
|
587 | - $element = array( |
|
585 | + } |
|
586 | + $label = $group['settings']['display']['label'] == 'above'; |
|
587 | + $element = array( |
|
588 | 588 | '#title' => $label ? check_plain(t($group['label'])) : '', |
589 | 589 | '#description' => $label ? content_filter_xss(t($group['settings']['display']['description'])) : '', |
590 | - ); |
|
591 | - $format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset'; |
|
590 | + ); |
|
591 | + $format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset'; |
|
592 | 592 | |
593 | - switch ($format) { |
|
593 | + switch ($format) { |
|
594 | 594 | case 'simple': |
595 | 595 | $element['#type'] = 'fieldgroup_simple'; |
596 | - $element['#group_name'] = $group_name; |
|
597 | - $element['#node'] = $node; |
|
598 | - break; |
|
596 | + $element['#group_name'] = $group_name; |
|
597 | + $element['#node'] = $node; |
|
598 | + break; |
|
599 | 599 | case 'hidden': |
600 | 600 | $element['#access'] = FALSE; |
601 | - break; |
|
601 | + break; |
|
602 | 602 | case 'fieldset_collapsed': |
603 | 603 | $element['#collapsed'] = TRUE; |
604 | 604 | case 'fieldset_collapsible': |
605 | 605 | $element['#collapsible'] = TRUE; |
606 | 606 | case 'fieldset': |
607 | 607 | $element['#type'] = 'fieldgroup_fieldset'; |
608 | - $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
|
609 | - break; |
|
610 | - } |
|
611 | - foreach ($group['fields'] as $field_name => $field) { |
|
608 | + $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
|
609 | + break; |
|
610 | + } |
|
611 | + foreach ($group['fields'] as $field_name => $field) { |
|
612 | 612 | if (isset($node->content[$field_name])) { |
613 | - $element[$field_name] = $node->content[$field_name]; |
|
613 | + $element[$field_name] = $node->content[$field_name]; |
|
614 | + } |
|
614 | 615 | } |
615 | - } |
|
616 | 616 | |
617 | - // Allow other modules to alter the group view. |
|
618 | - // Can't use module_invoke_all because we want |
|
619 | - // to be able to use a reference to $node and $element. |
|
620 | - foreach (module_implements('fieldgroup_view') as $module) { |
|
617 | + // Allow other modules to alter the group view. |
|
618 | + // Can't use module_invoke_all because we want |
|
619 | + // to be able to use a reference to $node and $element. |
|
620 | + foreach (module_implements('fieldgroup_view') as $module) { |
|
621 | 621 | $function = $module .'_fieldgroup_view'; |
622 | 622 | $function($node, $element, $group, $context); |
623 | - } |
|
623 | + } |
|
624 | 624 | |
625 | - // Unset the original field values now that we've moved them. |
|
626 | - foreach ($group['fields'] as $field_name => $field) { |
|
625 | + // Unset the original field values now that we've moved them. |
|
626 | + foreach ($group['fields'] as $field_name => $field) { |
|
627 | 627 | if (isset($node->content[$field_name])) { |
628 | - unset($node->content[$field_name]); |
|
628 | + unset($node->content[$field_name]); |
|
629 | + } |
|
629 | 630 | } |
630 | - } |
|
631 | 631 | |
632 | - // The wrapper lets us get the themed output for the group |
|
633 | - // to populate the $GROUP_NAME_rendered variable for node templates, |
|
634 | - // and hide it from the $content variable if needed. |
|
635 | - // See fieldgroup_preprocess_node(), theme_fieldgroup_wrapper(). |
|
636 | - $wrapper = array( |
|
632 | + // The wrapper lets us get the themed output for the group |
|
633 | + // to populate the $GROUP_NAME_rendered variable for node templates, |
|
634 | + // and hide it from the $content variable if needed. |
|
635 | + // See fieldgroup_preprocess_node(), theme_fieldgroup_wrapper(). |
|
636 | + $wrapper = array( |
|
637 | 637 | 'group' => $element, |
638 | 638 | '#weight' => $group['weight'], |
639 | 639 | '#post_render' => array('fieldgroup_wrapper_post_render'), |
640 | 640 | '#group_name' => $group_name, |
641 | 641 | '#type_name' => $node->type, |
642 | 642 | '#context' => $context, |
643 | - ); |
|
643 | + ); |
|
644 | 644 | |
645 | - $node->content[$group_name] = $wrapper; |
|
645 | + $node->content[$group_name] = $wrapper; |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | /** |
@@ -674,64 +674,64 @@ discard block |
||
674 | 674 | * @see content_view_field() |
675 | 675 | */ |
676 | 676 | function fieldgroup_view_group($group, &$node, $teaser = FALSE, $page = FALSE) { |
677 | - $group_name = $group['group_name']; |
|
678 | - $field_types = _content_field_types(); |
|
677 | + $group_name = $group['group_name']; |
|
678 | + $field_types = _content_field_types(); |
|
679 | 679 | |
680 | - // Clone the node to prevent from altering the original. |
|
681 | - $node_copy = drupal_clone($node); |
|
680 | + // Clone the node to prevent from altering the original. |
|
681 | + $node_copy = drupal_clone($node); |
|
682 | 682 | |
683 | - // Use 'full'/'teaser' if not specified otherwise. |
|
684 | - $node_copy->build_mode = isset($node_copy->build_mode) ? $node_copy->build_mode : NODE_BUILD_NORMAL; |
|
683 | + // Use 'full'/'teaser' if not specified otherwise. |
|
684 | + $node_copy->build_mode = isset($node_copy->build_mode) ? $node_copy->build_mode : NODE_BUILD_NORMAL; |
|
685 | 685 | |
686 | - // Build the content element for individual fields in the field group. |
|
687 | - if (!isset($node_copy->content)) { |
|
686 | + // Build the content element for individual fields in the field group. |
|
687 | + if (!isset($node_copy->content)) { |
|
688 | 688 | $node_copy->content = array(); |
689 | - } |
|
690 | - foreach (array_keys($group['fields']) as $field_name) { |
|
689 | + } |
|
690 | + foreach (array_keys($group['fields']) as $field_name) { |
|
691 | 691 | $field = content_fields($field_name, $node_copy->type); |
692 | 692 | |
693 | 693 | if (isset($node_copy->{$field_name})) { |
694 | - $items = $node_copy->{$field_name}; |
|
694 | + $items = $node_copy->{$field_name}; |
|
695 | 695 | |
696 | - // One-field equivalent to _content_field_invoke('sanitize'). |
|
697 | - $module = $field_types[$field['type']]['module']; |
|
698 | - $function = $module .'_field'; |
|
699 | - if (function_exists($function)) { |
|
696 | + // One-field equivalent to _content_field_invoke('sanitize'). |
|
697 | + $module = $field_types[$field['type']]['module']; |
|
698 | + $function = $module .'_field'; |
|
699 | + if (function_exists($function)) { |
|
700 | 700 | $function('sanitize', $node_copy, $field, $items, $teaser, $page); |
701 | 701 | $node_copy->{$field_name} = $items; |
702 | - } |
|
702 | + } |
|
703 | 703 | |
704 | - $field_view = content_field('view', $node_copy, $field, $items, $teaser, $page); |
|
705 | - // content_field('view') adds a wrapper to handle variables and 'excluded' |
|
706 | - // fields for node templates. We bypass it and get the actual field. |
|
707 | - $node_copy->content[$field_name] = $field_view[$field_name]; |
|
704 | + $field_view = content_field('view', $node_copy, $field, $items, $teaser, $page); |
|
705 | + // content_field('view') adds a wrapper to handle variables and 'excluded' |
|
706 | + // fields for node templates. We bypass it and get the actual field. |
|
707 | + $node_copy->content[$field_name] = $field_view[$field_name]; |
|
708 | + } |
|
708 | 709 | } |
709 | - } |
|
710 | 710 | |
711 | - // Build the content element of the field group itself. |
|
712 | - fieldgroup_build_content($group, $node_copy, $teaser, $page); |
|
711 | + // Build the content element of the field group itself. |
|
712 | + fieldgroup_build_content($group, $node_copy, $teaser, $page); |
|
713 | 713 | |
714 | - // fieldgroup_build_content() adds a wrapper to handle variables and 'excluded' |
|
715 | - // groups for node templates. We bypass it and render the actual field group. |
|
716 | - $output = drupal_render($node_copy->content[$group_name]['group']); |
|
714 | + // fieldgroup_build_content() adds a wrapper to handle variables and 'excluded' |
|
715 | + // groups for node templates. We bypass it and render the actual field group. |
|
716 | + $output = drupal_render($node_copy->content[$group_name]['group']); |
|
717 | 717 | |
718 | - return $output; |
|
718 | + return $output; |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | /** |
722 | 722 | * Hide specified fields from the $content variable in node templates. |
723 | 723 | */ |
724 | 724 | function fieldgroup_wrapper_post_render($content, $element) { |
725 | - $groups = fieldgroup_groups($element['#type_name']); |
|
726 | - $group = $groups[$element['#group_name']]; |
|
725 | + $groups = fieldgroup_groups($element['#type_name']); |
|
726 | + $group = $groups[$element['#group_name']]; |
|
727 | 727 | |
728 | - // The display settings are not in quite the same place in the |
|
729 | - // group and the field, so create the value the theme will expect. |
|
730 | - $group['display_settings'] = $group['settings']['display']; |
|
731 | - if (theme('content_exclude', $content, $group, $element['#context'])) { |
|
728 | + // The display settings are not in quite the same place in the |
|
729 | + // group and the field, so create the value the theme will expect. |
|
730 | + $group['display_settings'] = $group['settings']['display']; |
|
731 | + if (theme('content_exclude', $content, $group, $element['#context'])) { |
|
732 | 732 | return ''; |
733 | - } |
|
734 | - return $content; |
|
733 | + } |
|
734 | + return $content; |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | /* |
@@ -740,12 +740,12 @@ discard block |
||
740 | 740 | * @return The name of the group, or FALSE. |
741 | 741 | */ |
742 | 742 | function fieldgroup_get_group($content_type, $field_name) { |
743 | - foreach (fieldgroup_groups($content_type) as $group_name => $group) { |
|
743 | + foreach (fieldgroup_groups($content_type) as $group_name => $group) { |
|
744 | 744 | if (in_array($field_name, array_keys($group['fields']))) { |
745 | - return $group_name; |
|
745 | + return $group_name; |
|
746 | 746 | } |
747 | - } |
|
748 | - return FALSE; |
|
747 | + } |
|
748 | + return FALSE; |
|
749 | 749 | } |
750 | 750 | |
751 | 751 | /** |
@@ -753,37 +753,37 @@ discard block |
||
753 | 753 | * React to change in node types |
754 | 754 | */ |
755 | 755 | function fieldgroup_node_type($op, $info) { |
756 | - if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) { |
|
756 | + if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) { |
|
757 | 757 | // update the tables |
758 | 758 | db_query("UPDATE {". fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
759 | 759 | db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
760 | 760 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
761 | - } |
|
762 | - elseif ($op == 'delete') { |
|
761 | + } |
|
762 | + elseif ($op == 'delete') { |
|
763 | 763 | db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type); |
764 | 764 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s'", $info->type); |
765 | - } |
|
765 | + } |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | function fieldgroup_types() { |
769 | - $types = array('standard' => t('Standard group')); |
|
770 | - // Allow other modules to add new group_types. |
|
771 | - $types = array_merge($types, module_invoke_all('fieldgroup_types')); |
|
772 | - return $types; |
|
769 | + $types = array('standard' => t('Standard group')); |
|
770 | + // Allow other modules to add new group_types. |
|
771 | + $types = array_merge($types, module_invoke_all('fieldgroup_types')); |
|
772 | + return $types; |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | function fieldgroup_tablename($version = NULL) { |
776 | - if (is_null($version)) { |
|
776 | + if (is_null($version)) { |
|
777 | 777 | $version = variable_get('fieldgroup_schema_version', 0); |
778 | - } |
|
779 | - return $version < 6000 ? 'node_group' : 'content_group'; |
|
778 | + } |
|
779 | + return $version < 6000 ? 'node_group' : 'content_group'; |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | function fieldgroup_fields_tablename($version = NULL) { |
783 | - if (is_null($version)) { |
|
783 | + if (is_null($version)) { |
|
784 | 784 | $version = variable_get('fieldgroup_schema_version', 0); |
785 | - } |
|
786 | - return $version < 6000 ? 'node_group_fields' : 'content_group_fields'; |
|
785 | + } |
|
786 | + return $version < 6000 ? 'node_group_fields' : 'content_group_fields'; |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -796,51 +796,51 @@ discard block |
||
796 | 796 | * Saves the given group for this content-type |
797 | 797 | */ |
798 | 798 | function fieldgroup_save_group($type_name, $group) { |
799 | - $groups = fieldgroup_groups($type_name); |
|
799 | + $groups = fieldgroup_groups($type_name); |
|
800 | 800 | |
801 | - // Allow other modules to intervene when the group is saved. |
|
802 | - foreach (module_implements('fieldgroup_save_group') as $module) { |
|
801 | + // Allow other modules to intervene when the group is saved. |
|
802 | + foreach (module_implements('fieldgroup_save_group') as $module) { |
|
803 | 803 | $function = $module .'_fieldgroup_save_group'; |
804 | 804 | $function($group); |
805 | - } |
|
805 | + } |
|
806 | 806 | |
807 | - if (!isset($groups[$group['group_name']])) { |
|
807 | + if (!isset($groups[$group['group_name']])) { |
|
808 | 808 | // Accept group name from programmed submissions if valid. |
809 | 809 | db_query("INSERT INTO {". fieldgroup_tablename() ."} (group_type, type_name, group_name, label, settings, weight)". |
810 | - " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']); |
|
810 | + " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']); |
|
811 | 811 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
812 | 812 | return SAVED_NEW; |
813 | - } |
|
814 | - else { |
|
813 | + } |
|
814 | + else { |
|
815 | 815 | db_query("UPDATE {". fieldgroup_tablename() ."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ". |
816 | - "WHERE type_name = '%s' AND group_name = '%s'", |
|
817 | - $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); |
|
816 | + "WHERE type_name = '%s' AND group_name = '%s'", |
|
817 | + $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); |
|
818 | 818 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
819 | 819 | return SAVED_UPDATED; |
820 | - } |
|
820 | + } |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | function fieldgroup_update_fields($form_values) { |
824 | - $default = _fieldgroup_field_get_group($form_values['type_name'], $form_values['field_name']); |
|
824 | + $default = _fieldgroup_field_get_group($form_values['type_name'], $form_values['field_name']); |
|
825 | 825 | |
826 | - if ($default != $form_values['group']) { |
|
826 | + if ($default != $form_values['group']) { |
|
827 | 827 | if ($form_values['group'] && !$default) { |
828 | - db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); |
|
828 | + db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); |
|
829 | 829 | } |
830 | 830 | elseif ($form_values['group']) { |
831 | - db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); |
|
831 | + db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); |
|
832 | 832 | } |
833 | 833 | else { |
834 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
834 | + db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
835 | 835 | } |
836 | 836 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
837 | - } |
|
837 | + } |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | function fieldgroup_delete($content_type, $group_name) { |
841 | - db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
842 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
843 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
841 | + db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
842 | + db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
843 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
@@ -849,23 +849,23 @@ discard block |
||
849 | 849 | * Derived from core's theme_fieldset, with no output if the content is empty. |
850 | 850 | */ |
851 | 851 | function theme_fieldgroup_fieldset($element) { |
852 | - if (empty($element['#children']) && empty($element['#value'])) { |
|
852 | + if (empty($element['#children']) && empty($element['#value'])) { |
|
853 | 853 | return ''; |
854 | - } |
|
854 | + } |
|
855 | 855 | |
856 | - if ($element['#collapsible']) { |
|
856 | + if ($element['#collapsible']) { |
|
857 | 857 | drupal_add_js('misc/collapse.js'); |
858 | 858 | |
859 | 859 | if (!isset($element['#attributes']['class'])) { |
860 | - $element['#attributes']['class'] = ''; |
|
860 | + $element['#attributes']['class'] = ''; |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | $element['#attributes']['class'] .= ' collapsible'; |
864 | 864 | if ($element['#collapsed']) { |
865 | - $element['#attributes']['class'] .= ' collapsed'; |
|
865 | + $element['#attributes']['class'] .= ' collapsed'; |
|
866 | + } |
|
866 | 867 | } |
867 | - } |
|
868 | - return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n"; |
|
868 | + return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n"; |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | |
@@ -882,19 +882,19 @@ discard block |
||
882 | 882 | * @see fieldgroup-simple.tpl.php |
883 | 883 | */ |
884 | 884 | function template_preprocess_fieldgroup_simple(&$vars) { |
885 | - $element = $vars['element']; |
|
886 | - |
|
887 | - $vars['group_name'] = $element['#group_name']; |
|
888 | - $vars['group_name_css'] = strtr($element['#group_name'], '_', '-'); |
|
889 | - $vars['label'] = isset($element['#title']) ? $element['#title'] : '';; |
|
890 | - $vars['description'] = isset($element['#description']) ? $element['#description'] : '';; |
|
891 | - $vars['content'] = isset($element['#children']) ? $element['#children'] : ''; |
|
892 | - $vars['template_files'] = array( |
|
885 | + $element = $vars['element']; |
|
886 | + |
|
887 | + $vars['group_name'] = $element['#group_name']; |
|
888 | + $vars['group_name_css'] = strtr($element['#group_name'], '_', '-'); |
|
889 | + $vars['label'] = isset($element['#title']) ? $element['#title'] : '';; |
|
890 | + $vars['description'] = isset($element['#description']) ? $element['#description'] : '';; |
|
891 | + $vars['content'] = isset($element['#children']) ? $element['#children'] : ''; |
|
892 | + $vars['template_files'] = array( |
|
893 | 893 | 'fieldgroup-simple-', |
894 | 894 | 'fieldgroup-simple-'. $element['#group_name'], |
895 | 895 | 'fieldgroup-simple-'. $element['#node']->type, |
896 | 896 | 'fieldgroup-simple-'. $element['#group_name'] .'-'. $element['#node']->type, |
897 | - ); |
|
897 | + ); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -904,10 +904,10 @@ discard block |
||
904 | 904 | * containing the themed output for the whole group. |
905 | 905 | */ |
906 | 906 | function fieldgroup_preprocess_node(&$vars) { |
907 | - $node = $vars['node']; |
|
907 | + $node = $vars['node']; |
|
908 | 908 | |
909 | - foreach (fieldgroup_groups($node->type) as $group_name => $group) { |
|
909 | + foreach (fieldgroup_groups($node->type) as $group_name => $group) { |
|
910 | 910 | // '#chilren' might not be set if the group is empty. |
911 | 911 | $vars[$group_name .'_rendered'] = isset($node->content[$group_name]['#children']) ? $node->content[$group_name]['#children'] : ''; |
912 | - } |
|
912 | + } |
|
913 | 913 | } |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | */ |
94 | 94 | function fieldgroup_content_fieldapi($op, $field) { |
95 | 95 | switch ($op) { |
96 | - case 'delete instance': |
|
97 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
|
98 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
99 | - break; |
|
96 | + case 'delete instance': |
|
97 | + db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
|
98 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
99 | + break; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -540,15 +540,15 @@ discard block |
||
540 | 540 | */ |
541 | 541 | function fieldgroup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
542 | 542 | switch ($op) { |
543 | - case 'view': |
|
544 | - // Prevent against invalid 'nodes' built by broken 3rd party code. |
|
545 | - if (isset($node->type)) { |
|
546 | - // Build the node content element needed to render each fieldgroup. |
|
547 | - foreach (fieldgroup_groups($node->type) as $group) { |
|
548 | - fieldgroup_build_content($group, $node, $teaser, $page); |
|
549 | - } |
|
543 | + case 'view': |
|
544 | + // Prevent against invalid 'nodes' built by broken 3rd party code. |
|
545 | + if (isset($node->type)) { |
|
546 | + // Build the node content element needed to render each fieldgroup. |
|
547 | + foreach (fieldgroup_groups($node->type) as $group) { |
|
548 | + fieldgroup_build_content($group, $node, $teaser, $page); |
|
550 | 549 | } |
551 | - break; |
|
550 | + } |
|
551 | + break; |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
@@ -591,22 +591,22 @@ discard block |
||
591 | 591 | $format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset'; |
592 | 592 | |
593 | 593 | switch ($format) { |
594 | - case 'simple': |
|
595 | - $element['#type'] = 'fieldgroup_simple'; |
|
596 | - $element['#group_name'] = $group_name; |
|
597 | - $element['#node'] = $node; |
|
598 | - break; |
|
599 | - case 'hidden': |
|
600 | - $element['#access'] = FALSE; |
|
601 | - break; |
|
602 | - case 'fieldset_collapsed': |
|
603 | - $element['#collapsed'] = TRUE; |
|
604 | - case 'fieldset_collapsible': |
|
605 | - $element['#collapsible'] = TRUE; |
|
606 | - case 'fieldset': |
|
607 | - $element['#type'] = 'fieldgroup_fieldset'; |
|
608 | - $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
|
609 | - break; |
|
594 | + case 'simple': |
|
595 | + $element['#type'] = 'fieldgroup_simple'; |
|
596 | + $element['#group_name'] = $group_name; |
|
597 | + $element['#node'] = $node; |
|
598 | + break; |
|
599 | + case 'hidden': |
|
600 | + $element['#access'] = FALSE; |
|
601 | + break; |
|
602 | + case 'fieldset_collapsed': |
|
603 | + $element['#collapsed'] = TRUE; |
|
604 | + case 'fieldset_collapsible': |
|
605 | + $element['#collapsible'] = TRUE; |
|
606 | + case 'fieldset': |
|
607 | + $element['#type'] = 'fieldgroup_fieldset'; |
|
608 | + $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
|
609 | + break; |
|
610 | 610 | } |
611 | 611 | foreach ($group['fields'] as $field_name => $field) { |
612 | 612 | if (isset($node->content[$field_name])) { |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * Implementation of hook_init(). |
17 | 17 | */ |
18 | 18 | function fieldgroup_init() { |
19 | - drupal_add_css(drupal_get_path('module', 'fieldgroup') .'/fieldgroup.css'); |
|
19 | + drupal_add_css(drupal_get_path('module', 'fieldgroup').'/fieldgroup.css'); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | function fieldgroup_ctools_plugin_directory($module, $plugin) { |
26 | 26 | if ($module == 'ctools' && $plugin == 'content_types') { |
27 | - return 'panels/' . $plugin; |
|
27 | + return 'panels/'.$plugin; |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | $type_name = $type->type; |
42 | 42 | $content_type = content_types($type_name); |
43 | 43 | $type_url_str = $content_type['url_str']; |
44 | - $items['admin/content/node-type/'. $type_url_str .'/groups/%'] = array( |
|
44 | + $items['admin/content/node-type/'.$type_url_str.'/groups/%'] = array( |
|
45 | 45 | 'title' => 'Edit group', |
46 | 46 | 'page callback' => 'drupal_get_form', |
47 | 47 | 'page arguments' => array('fieldgroup_group_edit_form', $type_name, 5), |
48 | 48 | 'access arguments' => array('administer content types'), |
49 | 49 | 'type' => MENU_CALLBACK, |
50 | 50 | ); |
51 | - $items['admin/content/node-type/'. $type_url_str .'/groups/%/remove'] = array( |
|
51 | + $items['admin/content/node-type/'.$type_url_str.'/groups/%/remove'] = array( |
|
52 | 52 | 'title' => 'Edit group', |
53 | 53 | 'page callback' => 'drupal_get_form', |
54 | 54 | 'page arguments' => array('fieldgroup_remove_group', $type_name, 5), |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | function fieldgroup_content_fieldapi($op, $field) { |
95 | 95 | switch ($op) { |
96 | 96 | case 'delete instance': |
97 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
|
97 | + db_query("DELETE FROM {".fieldgroup_fields_tablename()."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
|
98 | 98 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
99 | 99 | break; |
100 | 100 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $form_values = $form_state['values']; |
183 | 183 | $content_type = $form['#content_type']; |
184 | 184 | fieldgroup_save_group($content_type['type'], $form_values); |
185 | - $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
185 | + $form_state['redirect'] = 'admin/content/node-type/'.$content_type['url_str'].'/fields'; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | function fieldgroup_remove_group(&$form_state, $type_name, $group_name) { |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | return confirm_form($form, |
203 | 203 | t('Are you sure you want to remove the group %label?', |
204 | 204 | array('%label' => t($group['label']))), |
205 | - 'admin/content/node-type/'. $content_type['url_str'] .'/fields', t('This action cannot be undone.'), |
|
205 | + 'admin/content/node-type/'.$content_type['url_str'].'/fields', t('This action cannot be undone.'), |
|
206 | 206 | t('Remove'), t('Cancel')); |
207 | 207 | } |
208 | 208 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $group_name = $form['#group_name']; |
213 | 213 | fieldgroup_delete($content_type['type'], $group_name); |
214 | 214 | drupal_set_message(t('The group %group_name has been removed.', array('%group_name' => $group_name))); |
215 | - $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
215 | + $form_state['redirect'] = 'admin/content/node-type/'.$content_type['url_str'].'/fields'; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -222,13 +222,13 @@ discard block |
||
222 | 222 | global $language; |
223 | 223 | static $groups, $groups_sorted; |
224 | 224 | if (!isset($groups) || $reset) { |
225 | - if ($cached = cache_get('fieldgroup_data:'. $language->language, content_cache_tablename())) { |
|
225 | + if ($cached = cache_get('fieldgroup_data:'.$language->language, content_cache_tablename())) { |
|
226 | 226 | $data = $cached->data; |
227 | 227 | $groups = $data['groups']; |
228 | 228 | $groups_sorted = $data['groups_sorted']; |
229 | 229 | } |
230 | 230 | else { |
231 | - $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name"); |
|
231 | + $result = db_query("SELECT * FROM {".fieldgroup_tablename()."} ORDER BY weight, group_name"); |
|
232 | 232 | $groups = array(); |
233 | 233 | $groups_sorted = array(); |
234 | 234 | while ($group = db_fetch_array($result)) { |
@@ -250,9 +250,9 @@ discard block |
||
250 | 250 | $groups_sorted[$group['type_name']][] = &$groups[$group['type_name']][$group['group_name']]; |
251 | 251 | } |
252 | 252 | //load fields |
253 | - $result = db_query("SELECT nfi.*, ng.group_name FROM {". fieldgroup_tablename() ."} ng ". |
|
254 | - "INNER JOIN {". fieldgroup_fields_tablename() ."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ". |
|
255 | - "INNER JOIN {". content_instance_tablename() ."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ". |
|
253 | + $result = db_query("SELECT nfi.*, ng.group_name FROM {".fieldgroup_tablename()."} ng ". |
|
254 | + "INNER JOIN {".fieldgroup_fields_tablename()."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ". |
|
255 | + "INNER JOIN {".content_instance_tablename()."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ". |
|
256 | 256 | "WHERE nfi.widget_active = 1 ORDER BY nfi.weight"); |
257 | 257 | while ($field = db_fetch_array($result)) { |
258 | 258 | // Allow external modules to translate field strings. |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | |
267 | 267 | $groups[$field['type_name']][$field['group_name']]['fields'][$field['field_name']] = $field; |
268 | 268 | } |
269 | - cache_set('fieldgroup_data:'. $language->language, array('groups' => $groups, 'groups_sorted' => $groups_sorted), content_cache_tablename()); |
|
269 | + cache_set('fieldgroup_data:'.$language->language, array('groups' => $groups, 'groups_sorted' => $groups_sorted), content_cache_tablename()); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | if (empty($content_type)) { |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | function _fieldgroup_groups_label($content_type) { |
283 | 283 | $groups = fieldgroup_groups($content_type); |
284 | 284 | |
285 | - $labels[''] = '<'. t('none') .'>'; |
|
285 | + $labels[''] = '<'.t('none').'>'; |
|
286 | 286 | foreach ($groups as $group_name => $group) { |
287 | 287 | $labels[$group_name] = t($group['label']); |
288 | 288 | } |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | } |
291 | 291 | |
292 | 292 | function _fieldgroup_field_get_group($content_type, $field_name) { |
293 | - return db_result(db_query("SELECT group_name FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name)); |
|
293 | + return db_result(db_query("SELECT group_name FROM {".fieldgroup_fields_tablename()."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name)); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | 297 | * Implementation of hook_form_alter() |
298 | 298 | */ |
299 | 299 | function fieldgroup_form_alter(&$form, $form_state, $form_id) { |
300 | - if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
300 | + if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'].'_node_form' == $form_id) { |
|
301 | 301 | foreach (fieldgroup_groups($form['type']['#value']) as $group_name => $group) { |
302 | 302 | $form[$group_name] = array( |
303 | 303 | '#type' => 'fieldset', |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | // Can't use module_invoke_all because we want |
335 | 335 | // to be able to use a reference to $form and $form_state. |
336 | 336 | foreach (module_implements('fieldgroup_form') as $module) { |
337 | - $function = $module .'_fieldgroup_form'; |
|
337 | + $function = $module.'_fieldgroup_form'; |
|
338 | 338 | $function($form, $form_state, $form_id, $group); |
339 | 339 | } |
340 | 340 | |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | |
390 | 390 | // Add the 'group_' prefix. |
391 | 391 | if (substr($group_name, 0, 6) != 'group_') { |
392 | - $group_name = 'group_'. $group_name; |
|
392 | + $group_name = 'group_'.$group_name; |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | // Invalid field name. |
@@ -422,10 +422,10 @@ discard block |
||
422 | 422 | foreach ($validation['errors'] as $type => $messages) { |
423 | 423 | foreach ($messages as $message) { |
424 | 424 | if ($type == 'label') { |
425 | - form_set_error('_add_new_group][label', t('Add new group:') .' '. $message); |
|
425 | + form_set_error('_add_new_group][label', t('Add new group:').' '.$message); |
|
426 | 426 | } |
427 | 427 | else { |
428 | - form_set_error('_add_new_group][group_name', t('Add new group:') .' '. $message); |
|
428 | + form_set_error('_add_new_group][group_name', t('Add new group:').' '.$message); |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | } |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | // If 'group' row: update groups weights |
491 | 491 | // (possible newly created group has already been taken care of). |
492 | 492 | elseif (in_array($key, $form['#groups'])) { |
493 | - db_query("UPDATE {". fieldgroup_tablename() ."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'", |
|
493 | + db_query("UPDATE {".fieldgroup_tablename()."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'", |
|
494 | 494 | $values['weight'], $type_name, $key); |
495 | 495 | } |
496 | 496 | } |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | // - when a (non last) field is removed from a group, a 'ghost row' remains in the fields overview |
533 | 533 | // - when the last field is removed, the group disappears |
534 | 534 | // seems to be fixed when emptying the cache. |
535 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
535 | + db_query("DELETE FROM {".fieldgroup_fields_tablename()."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | $element['#collapsible'] = TRUE; |
606 | 606 | case 'fieldset': |
607 | 607 | $element['#type'] = 'fieldgroup_fieldset'; |
608 | - $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
|
608 | + $element['#attributes'] = array('class' => 'fieldgroup '.strtr($group['group_name'], '_', '-')); |
|
609 | 609 | break; |
610 | 610 | } |
611 | 611 | foreach ($group['fields'] as $field_name => $field) { |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | // Can't use module_invoke_all because we want |
619 | 619 | // to be able to use a reference to $node and $element. |
620 | 620 | foreach (module_implements('fieldgroup_view') as $module) { |
621 | - $function = $module .'_fieldgroup_view'; |
|
621 | + $function = $module.'_fieldgroup_view'; |
|
622 | 622 | $function($node, $element, $group, $context); |
623 | 623 | } |
624 | 624 | |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | |
696 | 696 | // One-field equivalent to _content_field_invoke('sanitize'). |
697 | 697 | $module = $field_types[$field['type']]['module']; |
698 | - $function = $module .'_field'; |
|
698 | + $function = $module.'_field'; |
|
699 | 699 | if (function_exists($function)) { |
700 | 700 | $function('sanitize', $node_copy, $field, $items, $teaser, $page); |
701 | 701 | $node_copy->{$field_name} = $items; |
@@ -755,13 +755,13 @@ discard block |
||
755 | 755 | function fieldgroup_node_type($op, $info) { |
756 | 756 | if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) { |
757 | 757 | // update the tables |
758 | - db_query("UPDATE {". fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
|
759 | - db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
|
758 | + db_query("UPDATE {".fieldgroup_tablename()."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
|
759 | + db_query("UPDATE {".fieldgroup_fields_tablename()."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
|
760 | 760 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
761 | 761 | } |
762 | 762 | elseif ($op == 'delete') { |
763 | - db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type); |
|
764 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s'", $info->type); |
|
763 | + db_query("DELETE FROM {".fieldgroup_tablename()."} WHERE type_name = '%s'", $info->type); |
|
764 | + db_query("DELETE FROM {".fieldgroup_fields_tablename()."} WHERE type_name = '%s'", $info->type); |
|
765 | 765 | } |
766 | 766 | } |
767 | 767 | |
@@ -800,19 +800,19 @@ discard block |
||
800 | 800 | |
801 | 801 | // Allow other modules to intervene when the group is saved. |
802 | 802 | foreach (module_implements('fieldgroup_save_group') as $module) { |
803 | - $function = $module .'_fieldgroup_save_group'; |
|
803 | + $function = $module.'_fieldgroup_save_group'; |
|
804 | 804 | $function($group); |
805 | 805 | } |
806 | 806 | |
807 | 807 | if (!isset($groups[$group['group_name']])) { |
808 | 808 | // Accept group name from programmed submissions if valid. |
809 | - db_query("INSERT INTO {". fieldgroup_tablename() ."} (group_type, type_name, group_name, label, settings, weight)". |
|
809 | + db_query("INSERT INTO {".fieldgroup_tablename()."} (group_type, type_name, group_name, label, settings, weight)". |
|
810 | 810 | " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']); |
811 | 811 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
812 | 812 | return SAVED_NEW; |
813 | 813 | } |
814 | 814 | else { |
815 | - db_query("UPDATE {". fieldgroup_tablename() ."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ". |
|
815 | + db_query("UPDATE {".fieldgroup_tablename()."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ". |
|
816 | 816 | "WHERE type_name = '%s' AND group_name = '%s'", |
817 | 817 | $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); |
818 | 818 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
@@ -825,21 +825,21 @@ discard block |
||
825 | 825 | |
826 | 826 | if ($default != $form_values['group']) { |
827 | 827 | if ($form_values['group'] && !$default) { |
828 | - db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); |
|
828 | + db_query("INSERT INTO {".fieldgroup_fields_tablename()."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); |
|
829 | 829 | } |
830 | 830 | elseif ($form_values['group']) { |
831 | - db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); |
|
831 | + db_query("UPDATE {".fieldgroup_fields_tablename()."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); |
|
832 | 832 | } |
833 | 833 | else { |
834 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
834 | + db_query("DELETE FROM {".fieldgroup_fields_tablename()."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
835 | 835 | } |
836 | 836 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | 840 | function fieldgroup_delete($content_type, $group_name) { |
841 | - db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
842 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
841 | + db_query("DELETE FROM {".fieldgroup_tablename()."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
842 | + db_query("DELETE FROM {".fieldgroup_fields_tablename()."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
843 | 843 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
844 | 844 | } |
845 | 845 | |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | $element['#attributes']['class'] .= ' collapsed'; |
866 | 866 | } |
867 | 867 | } |
868 | - return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n"; |
|
868 | + return '<fieldset'.drupal_attributes($element['#attributes']).'>'.($element['#title'] ? '<legend>'.$element['#title'].'</legend>' : '').(isset($element['#description']) && $element['#description'] ? '<div class="description">'.$element['#description'].'</div>' : '').(!empty($element['#children']) ? $element['#children'] : '').(isset($element['#value']) ? $element['#value'] : '')."</fieldset>\n"; |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | |
@@ -886,14 +886,14 @@ discard block |
||
886 | 886 | |
887 | 887 | $vars['group_name'] = $element['#group_name']; |
888 | 888 | $vars['group_name_css'] = strtr($element['#group_name'], '_', '-'); |
889 | - $vars['label'] = isset($element['#title']) ? $element['#title'] : '';; |
|
890 | - $vars['description'] = isset($element['#description']) ? $element['#description'] : '';; |
|
889 | + $vars['label'] = isset($element['#title']) ? $element['#title'] : ''; ; |
|
890 | + $vars['description'] = isset($element['#description']) ? $element['#description'] : ''; ; |
|
891 | 891 | $vars['content'] = isset($element['#children']) ? $element['#children'] : ''; |
892 | 892 | $vars['template_files'] = array( |
893 | 893 | 'fieldgroup-simple-', |
894 | - 'fieldgroup-simple-'. $element['#group_name'], |
|
895 | - 'fieldgroup-simple-'. $element['#node']->type, |
|
896 | - 'fieldgroup-simple-'. $element['#group_name'] .'-'. $element['#node']->type, |
|
894 | + 'fieldgroup-simple-'.$element['#group_name'], |
|
895 | + 'fieldgroup-simple-'.$element['#node']->type, |
|
896 | + 'fieldgroup-simple-'.$element['#group_name'].'-'.$element['#node']->type, |
|
897 | 897 | ); |
898 | 898 | } |
899 | 899 | |
@@ -908,6 +908,6 @@ discard block |
||
908 | 908 | |
909 | 909 | foreach (fieldgroup_groups($node->type) as $group_name => $group) { |
910 | 910 | // '#chilren' might not be set if the group is empty. |
911 | - $vars[$group_name .'_rendered'] = isset($node->content[$group_name]['#children']) ? $node->content[$group_name]['#children'] : ''; |
|
911 | + $vars[$group_name.'_rendered'] = isset($node->content[$group_name]['#children']) ? $node->content[$group_name]['#children'] : ''; |
|
912 | 912 | } |
913 | 913 | } |
@@ -226,8 +226,7 @@ discard block |
||
226 | 226 | $data = $cached->data; |
227 | 227 | $groups = $data['groups']; |
228 | 228 | $groups_sorted = $data['groups_sorted']; |
229 | - } |
|
230 | - else { |
|
229 | + } else { |
|
231 | 230 | $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name"); |
232 | 231 | $groups = array(); |
233 | 232 | $groups_sorted = array(); |
@@ -271,8 +270,7 @@ discard block |
||
271 | 270 | } |
272 | 271 | if (empty($content_type)) { |
273 | 272 | return $groups; |
274 | - } |
|
275 | - elseif (empty($groups) || empty($groups[$content_type])) { |
|
273 | + } elseif (empty($groups) || empty($groups[$content_type])) { |
|
276 | 274 | return array(); |
277 | 275 | } |
278 | 276 | return $sorted ? $groups_sorted[$content_type] : $groups[$content_type]; |
@@ -349,18 +347,15 @@ discard block |
||
349 | 347 | '#type' => 'value', |
350 | 348 | '#value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']), |
351 | 349 | ); |
352 | - } |
|
353 | - elseif ($form_id == 'content_field_overview_form') { |
|
350 | + } elseif ($form_id == 'content_field_overview_form') { |
|
354 | 351 | $form['#validate'][] = 'fieldgroup_field_overview_form_validate'; |
355 | 352 | $form['#submit'][] = 'fieldgroup_field_overview_form_submit'; |
356 | - } |
|
357 | - elseif ($form_id == 'content_display_overview_form' && !empty($form['#groups'])) { |
|
353 | + } elseif ($form_id == 'content_display_overview_form' && !empty($form['#groups'])) { |
|
358 | 354 | $form['#submit'][] = 'fieldgroup_display_overview_form_submit'; |
359 | 355 | if (!isset($form['submit'])) { |
360 | 356 | $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 10); |
361 | 357 | } |
362 | - } |
|
363 | - elseif ($form_id == 'content_field_remove_form') { |
|
358 | + } elseif ($form_id == 'content_field_remove_form') { |
|
364 | 359 | $form['#submit'][] = 'fieldgroup_field_remove_form_submit'; |
365 | 360 | } |
366 | 361 | } |
@@ -423,8 +418,7 @@ discard block |
||
423 | 418 | foreach ($messages as $message) { |
424 | 419 | if ($type == 'label') { |
425 | 420 | form_set_error('_add_new_group][label', t('Add new group:') .' '. $message); |
426 | - } |
|
427 | - else { |
|
421 | + } else { |
|
428 | 422 | form_set_error('_add_new_group][group_name', t('Add new group:') .' '. $message); |
429 | 423 | } |
430 | 424 | } |
@@ -432,8 +426,7 @@ discard block |
||
432 | 426 | } |
433 | 427 | $group_name = $validation['group_name']; |
434 | 428 | form_set_value($form['_add_new_group']['group_name'], $group_name, $form_state); |
435 | - } |
|
436 | - else { |
|
429 | + } else { |
|
437 | 430 | // Fail validation if attempt to nest fields under a new group without the |
438 | 431 | // proper information. Not raising an error would cause the nested fields |
439 | 432 | // to get weights the user doesn't expect. |
@@ -474,8 +467,7 @@ discard block |
||
474 | 467 | // in $form_state['fields_added'] for us. |
475 | 468 | if (isset($form_state['fields_added'][$key])) { |
476 | 469 | $key = $form_state['fields_added'][$key]; |
477 | - } |
|
478 | - else { |
|
470 | + } else { |
|
479 | 471 | // No field was actually created : skip to next row. |
480 | 472 | continue; |
481 | 473 | } |
@@ -572,8 +564,7 @@ discard block |
||
572 | 564 | // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
573 | 565 | if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
574 | 566 | $context = $teaser ? 'teaser' : 'full'; |
575 | - } |
|
576 | - else { |
|
567 | + } else { |
|
577 | 568 | $context = $node->build_mode; |
578 | 569 | } |
579 | 570 | |
@@ -758,8 +749,7 @@ discard block |
||
758 | 749 | db_query("UPDATE {". fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
759 | 750 | db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
760 | 751 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
761 | - } |
|
762 | - elseif ($op == 'delete') { |
|
752 | + } elseif ($op == 'delete') { |
|
763 | 753 | db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type); |
764 | 754 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s'", $info->type); |
765 | 755 | } |
@@ -810,8 +800,7 @@ discard block |
||
810 | 800 | " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']); |
811 | 801 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
812 | 802 | return SAVED_NEW; |
813 | - } |
|
814 | - else { |
|
803 | + } else { |
|
815 | 804 | db_query("UPDATE {". fieldgroup_tablename() ."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ". |
816 | 805 | "WHERE type_name = '%s' AND group_name = '%s'", |
817 | 806 | $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); |
@@ -826,11 +815,9 @@ discard block |
||
826 | 815 | if ($default != $form_values['group']) { |
827 | 816 | if ($form_values['group'] && !$default) { |
828 | 817 | db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); |
829 | - } |
|
830 | - elseif ($form_values['group']) { |
|
818 | + } elseif ($form_values['group']) { |
|
831 | 819 | db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); |
832 | - } |
|
833 | - else { |
|
820 | + } else { |
|
834 | 821 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
835 | 822 | } |
836 | 823 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | return array( |
68 | 68 | 'fieldgroup_simple' => array( |
69 | 69 | 'template' => 'fieldgroup-simple', |
70 | - 'arguments' => array('element' => NULL), |
|
70 | + 'arguments' => array('element' => null), |
|
71 | 71 | ), |
72 | 72 | 'fieldgroup_fieldset' => array( |
73 | - 'arguments' => array('element' => NULL), |
|
73 | + 'arguments' => array('element' => null), |
|
74 | 74 | ), |
75 | 75 | 'fieldgroup_display_overview_form' => array( |
76 | - 'arguments' => array('form' => NULL), |
|
76 | + 'arguments' => array('form' => null), |
|
77 | 77 | ), |
78 | 78 | ); |
79 | 79 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | function fieldgroup_elements() { |
85 | 85 | return array( |
86 | 86 | 'fieldgroup_simple' => array(), |
87 | - 'fieldgroup_fieldset' => array('#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL,), |
|
87 | + 'fieldgroup_fieldset' => array('#collapsible' => false, '#collapsed' => false, '#value' => null,), |
|
88 | 88 | ); |
89 | 89 | } |
90 | 90 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | switch ($op) { |
96 | 96 | case 'delete instance': |
97 | 97 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
98 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
98 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
99 | 99 | break; |
100 | 100 | } |
101 | 101 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | '#type' => 'textfield', |
114 | 114 | '#title' => t('Label'), |
115 | 115 | '#default_value' => $group['label'], |
116 | - '#required' => TRUE, |
|
116 | + '#required' => true, |
|
117 | 117 | ); |
118 | 118 | |
119 | 119 | // Set a default value for group type early in the form so it |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | $group_type = !empty($group['group_type']) ? $group['group_type'] : 'standard'; |
122 | 122 | $form['group_type'] = array('#type' => 'hidden', '#default_value' => $group_type); |
123 | 123 | |
124 | - $form['settings']['#tree'] = TRUE; |
|
124 | + $form['settings']['#tree'] = true; |
|
125 | 125 | $form['settings']['form'] = array( |
126 | 126 | '#type' => 'fieldset', |
127 | 127 | '#title' => t('Form settings'), |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | '#default_value' => $group['settings']['form']['description'], |
144 | 144 | '#rows' => 5, |
145 | 145 | '#description' => t('Instructions to present to the user on the editing form.'), |
146 | - '#required' => FALSE, |
|
146 | + '#required' => false, |
|
147 | 147 | ); |
148 | 148 | $form['settings']['display'] = array( |
149 | 149 | '#type' => 'fieldset', |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | '#default_value' => $group['settings']['display']['description'], |
157 | 157 | '#rows' => 5, |
158 | 158 | '#description' => t('A description of the group.'), |
159 | - '#required' => FALSE, |
|
159 | + '#required' => false, |
|
160 | 160 | ); |
161 | 161 | |
162 | 162 | foreach (array_keys(content_build_modes()) as $key) { |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | /** |
219 | 219 | * Returns all groups for a content type |
220 | 220 | */ |
221 | -function fieldgroup_groups($content_type = '', $sorted = FALSE, $reset = FALSE) { |
|
221 | +function fieldgroup_groups($content_type = '', $sorted = false, $reset = false) { |
|
222 | 222 | global $language; |
223 | 223 | static $groups, $groups_sorted; |
224 | 224 | if (!isset($groups) || $reset) { |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | '#attributes' => array('class' => strtr($group['group_name'], '_', '-')), |
310 | 310 | ); |
311 | 311 | |
312 | - $has_accessible_field = FALSE; |
|
312 | + $has_accessible_field = false; |
|
313 | 313 | foreach ($group['fields'] as $field_name => $field) { |
314 | 314 | if (isset($form[$field_name])) { |
315 | 315 | $form[$group_name][$field_name] = $form[$field_name]; |
316 | 316 | // Track whether this group has any accessible fields within it. |
317 | - if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== FALSE) { |
|
318 | - $has_accessible_field = TRUE; |
|
317 | + if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== false) { |
|
318 | + $has_accessible_field = true; |
|
319 | 319 | } |
320 | 320 | unset($form[$field_name]); |
321 | 321 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | if (!$has_accessible_field) { |
329 | 329 | // Hide the fieldgroup, because the fields are inaccessible. |
330 | - $form[$group_name]['#access'] = FALSE; |
|
330 | + $form[$group_name]['#access'] = false; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | // Allow other modules to alter the form. |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | } |
496 | 496 | } |
497 | 497 | |
498 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
498 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | function field_group_default_settings($group_type) { |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | /** |
539 | 539 | * Implementation of hook_nodeapi(). |
540 | 540 | */ |
541 | -function fieldgroup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
|
541 | +function fieldgroup_nodeapi(&$node, $op, $teaser = null, $page = null) { |
|
542 | 542 | switch ($op) { |
543 | 543 | case 'view': |
544 | 544 | // Prevent against invalid 'nodes' built by broken 3rd party code. |
@@ -597,12 +597,12 @@ discard block |
||
597 | 597 | $element['#node'] = $node; |
598 | 598 | break; |
599 | 599 | case 'hidden': |
600 | - $element['#access'] = FALSE; |
|
600 | + $element['#access'] = false; |
|
601 | 601 | break; |
602 | 602 | case 'fieldset_collapsed': |
603 | - $element['#collapsed'] = TRUE; |
|
603 | + $element['#collapsed'] = true; |
|
604 | 604 | case 'fieldset_collapsible': |
605 | - $element['#collapsible'] = TRUE; |
|
605 | + $element['#collapsible'] = true; |
|
606 | 606 | case 'fieldset': |
607 | 607 | $element['#type'] = 'fieldgroup_fieldset'; |
608 | 608 | $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | * |
674 | 674 | * @see content_view_field() |
675 | 675 | */ |
676 | -function fieldgroup_view_group($group, &$node, $teaser = FALSE, $page = FALSE) { |
|
676 | +function fieldgroup_view_group($group, &$node, $teaser = false, $page = false) { |
|
677 | 677 | $group_name = $group['group_name']; |
678 | 678 | $field_types = _content_field_types(); |
679 | 679 | |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | return $group_name; |
746 | 746 | } |
747 | 747 | } |
748 | - return FALSE; |
|
748 | + return false; |
|
749 | 749 | } |
750 | 750 | |
751 | 751 | /** |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | // update the tables |
758 | 758 | db_query("UPDATE {". fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
759 | 759 | db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
760 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
760 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
761 | 761 | } |
762 | 762 | elseif ($op == 'delete') { |
763 | 763 | db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type); |
@@ -772,14 +772,14 @@ discard block |
||
772 | 772 | return $types; |
773 | 773 | } |
774 | 774 | |
775 | -function fieldgroup_tablename($version = NULL) { |
|
775 | +function fieldgroup_tablename($version = null) { |
|
776 | 776 | if (is_null($version)) { |
777 | 777 | $version = variable_get('fieldgroup_schema_version', 0); |
778 | 778 | } |
779 | 779 | return $version < 6000 ? 'node_group' : 'content_group'; |
780 | 780 | } |
781 | 781 | |
782 | -function fieldgroup_fields_tablename($version = NULL) { |
|
782 | +function fieldgroup_fields_tablename($version = null) { |
|
783 | 783 | if (is_null($version)) { |
784 | 784 | $version = variable_get('fieldgroup_schema_version', 0); |
785 | 785 | } |
@@ -808,14 +808,14 @@ discard block |
||
808 | 808 | // Accept group name from programmed submissions if valid. |
809 | 809 | db_query("INSERT INTO {". fieldgroup_tablename() ."} (group_type, type_name, group_name, label, settings, weight)". |
810 | 810 | " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']); |
811 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
811 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
812 | 812 | return SAVED_NEW; |
813 | 813 | } |
814 | 814 | else { |
815 | 815 | db_query("UPDATE {". fieldgroup_tablename() ."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ". |
816 | 816 | "WHERE type_name = '%s' AND group_name = '%s'", |
817 | 817 | $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); |
818 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
818 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
819 | 819 | return SAVED_UPDATED; |
820 | 820 | } |
821 | 821 | } |
@@ -833,14 +833,14 @@ discard block |
||
833 | 833 | else { |
834 | 834 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
835 | 835 | } |
836 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
836 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | 840 | function fieldgroup_delete($content_type, $group_name) { |
841 | 841 | db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
842 | 842 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
843 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
843 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
@@ -10,37 +10,37 @@ discard block |
||
10 | 10 | * Implementation of hook_rules_action_info(). |
11 | 11 | */ |
12 | 12 | function nodereference_rules_action_info() { |
13 | - $info = array(); |
|
14 | - $info['nodereference_rules_action_load'] = array( |
|
13 | + $info = array(); |
|
14 | + $info['nodereference_rules_action_load'] = array( |
|
15 | 15 | 'label' => t('Load a referenced node'), |
16 | 16 | 'arguments' => array( |
17 | - 'node' => array( |
|
17 | + 'node' => array( |
|
18 | 18 | 'type' => 'node', |
19 | 19 | 'label' => t('Content containing the node reference field'), |
20 | - ), |
|
20 | + ), |
|
21 | 21 | ), |
22 | 22 | 'new variables' => array( |
23 | - 'referenced_node' => array( |
|
23 | + 'referenced_node' => array( |
|
24 | 24 | 'type' => 'node', |
25 | 25 | 'label' => t('Referenced content'), |
26 | - ), |
|
26 | + ), |
|
27 | 27 | ), |
28 | 28 | 'module' => 'CCK', |
29 | 29 | 'help' => t('Note that if the field has multiple values, only the first content node will be loaded.'), |
30 | - ); |
|
31 | - return $info; |
|
30 | + ); |
|
31 | + return $info; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | function nodereference_rules_action_load($node, $settings) { |
35 | - if ($nid = $node->{$settings['field']}[0]['nid']) { |
|
35 | + if ($nid = $node->{$settings['field']}[0]['nid']) { |
|
36 | 36 | return array('referenced_node' => node_load(array('nid' => $nid))); |
37 | - } |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | function nodereference_rules_action_load_form($settings, &$form) { |
41 | - $settings += array('field' => ''); |
|
42 | - $options = content_rules_get_field_names_by_type('nodereference'); |
|
43 | - $form['settings']['field'] = array( |
|
41 | + $settings += array('field' => ''); |
|
42 | + $options = content_rules_get_field_names_by_type('nodereference'); |
|
43 | + $form['settings']['field'] = array( |
|
44 | 44 | '#type' => 'select', |
45 | 45 | '#title' => t('Field'), |
46 | 46 | '#default_value' => $settings['field'], |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | '#required' => TRUE, |
49 | 49 | '#disabled' => empty($options), |
50 | 50 | '#description' => empty($options) ? t('There are no nodereference fields defined.') : '', |
51 | - ); |
|
51 | + ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -56,5 +56,5 @@ discard block |
||
56 | 56 | * "workflow_ng_action_load_referenced_node" to the equivalent rules action. |
57 | 57 | */ |
58 | 58 | function workflow_ng_action_load_referenced_node_upgrade(&$element) { |
59 | - $element['#name'] = 'nodereference_rules_action_load'; |
|
59 | + $element['#name'] = 'nodereference_rules_action_load'; |
|
60 | 60 | } |
@@ -45,7 +45,7 @@ |
||
45 | 45 | '#title' => t('Field'), |
46 | 46 | '#default_value' => $settings['field'], |
47 | 47 | '#options' => $options, |
48 | - '#required' => TRUE, |
|
48 | + '#required' => true, |
|
49 | 49 | '#disabled' => empty($options), |
50 | 50 | '#description' => empty($options) ? t('There are no nodereference fields defined.') : '', |
51 | 51 | ); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * Implementation of hook_ctools_relationships(). |
11 | 11 | */ |
12 | 12 | function nodereference_node_from_noderef_ctools_relationships() { |
13 | - return array( |
|
13 | + return array( |
|
14 | 14 | 'title' => t('Node from reference'), |
15 | 15 | 'keyword' => 'nodereference', |
16 | 16 | 'description' => t('Adds a node from a node reference in a node context; if multiple nodes are referenced, this will get the first referenced node only.'), |
@@ -18,59 +18,59 @@ discard block |
||
18 | 18 | 'context' => 'nodereference_node_from_noderef_context', |
19 | 19 | 'settings form' => 'nodereference_node_from_noderef_settings_form', |
20 | 20 | 'settings form validate' => 'nodereference_node_from_noderef_settings_form_validate', |
21 | - ); |
|
21 | + ); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Return a new ctools context based on an existing context. |
26 | 26 | */ |
27 | 27 | function nodereference_node_from_noderef_context($context, $conf) { |
28 | - $field = content_fields($conf['field_name']); |
|
28 | + $field = content_fields($conf['field_name']); |
|
29 | 29 | |
30 | - // If unset it wants a generic, unfilled context, which is just NULL. |
|
31 | - if (empty($context->data)) { |
|
30 | + // If unset it wants a generic, unfilled context, which is just NULL. |
|
31 | + if (empty($context->data)) { |
|
32 | 32 | $new_context = ctools_context_create_empty('node', NULL); |
33 | - } |
|
34 | - else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) { |
|
33 | + } |
|
34 | + else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) { |
|
35 | 35 | if ($node = node_load($nid)) { |
36 | - $new_context = ctools_context_create('node', $node); |
|
36 | + $new_context = ctools_context_create('node', $node); |
|
37 | + } |
|
37 | 38 | } |
38 | - } |
|
39 | 39 | |
40 | - if (!empty($new_context)) { |
|
40 | + if (!empty($new_context)) { |
|
41 | 41 | // Have nodereference relationships limit CCK field availability as well. |
42 | 42 | $restrictions = array_keys(array_filter($field['referenceable_types'])); |
43 | 43 | if ($restrictions) { |
44 | - if (isset($new_context->restrictions['type'])) { |
|
44 | + if (isset($new_context->restrictions['type'])) { |
|
45 | 45 | $new_context->restrictions['type'] = array_unique(array_merge($new_context->restrictions['type'], $restrictions)); |
46 | - } |
|
47 | - else { |
|
46 | + } |
|
47 | + else { |
|
48 | 48 | $new_context->restrictions['type'] = $restrictions; |
49 | - } |
|
49 | + } |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | return $new_context; |
53 | - } |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Settings form for the ctools relationship. |
58 | 58 | */ |
59 | 59 | function nodereference_node_from_noderef_settings_form($conf) { |
60 | - $options = array(); |
|
61 | - foreach (content_fields() as $field) { |
|
60 | + $options = array(); |
|
61 | + foreach (content_fields() as $field) { |
|
62 | 62 | if ($field['type'] == 'nodereference') { |
63 | - $options[$field['field_name']] = t($field['widget']['label']); |
|
63 | + $options[$field['field_name']] = t($field['widget']['label']); |
|
64 | + } |
|
64 | 65 | } |
65 | - } |
|
66 | - $form['field_name'] = array( |
|
66 | + $form['field_name'] = array( |
|
67 | 67 | '#title' => t('Node reference field'), |
68 | 68 | '#type' => 'select', |
69 | 69 | '#options' => $options, |
70 | 70 | '#default_value' => isset($conf['field_name']) ? $conf['field_name'] : '', |
71 | 71 | '#prefix' => '<div class="clear-block">', |
72 | 72 | '#suffix' => '</div>', |
73 | - ); |
|
73 | + ); |
|
74 | 74 | |
75 | - return $form; |
|
75 | + return $form; |
|
76 | 76 | } |
@@ -30,8 +30,7 @@ discard block |
||
30 | 30 | // If unset it wants a generic, unfilled context, which is just NULL. |
31 | 31 | if (empty($context->data)) { |
32 | 32 | $new_context = ctools_context_create_empty('node', NULL); |
33 | - } |
|
34 | - else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) { |
|
33 | + } else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) { |
|
35 | 34 | if ($node = node_load($nid)) { |
36 | 35 | $new_context = ctools_context_create('node', $node); |
37 | 36 | } |
@@ -43,8 +42,7 @@ discard block |
||
43 | 42 | if ($restrictions) { |
44 | 43 | if (isset($new_context->restrictions['type'])) { |
45 | 44 | $new_context->restrictions['type'] = array_unique(array_merge($new_context->restrictions['type'], $restrictions)); |
46 | - } |
|
47 | - else { |
|
45 | + } else { |
|
48 | 46 | $new_context->restrictions['type'] = $restrictions; |
49 | 47 | } |
50 | 48 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | // If unset it wants a generic, unfilled context, which is just NULL. |
31 | 31 | if (empty($context->data)) { |
32 | - $new_context = ctools_context_create_empty('node', NULL); |
|
32 | + $new_context = ctools_context_create_empty('node', null); |
|
33 | 33 | } |
34 | 34 | else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) { |
35 | 35 | if ($node = node_load($nid)) { |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * Implementation of hook_theme(). |
11 | 11 | */ |
12 | 12 | function number_theme() { |
13 | - return array( |
|
13 | + return array( |
|
14 | 14 | 'number' => array('arguments' => array('element' => NULL)), |
15 | 15 | 'number_formatter_default' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
16 | 16 | 'number_formatter_us_0' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
@@ -23,156 +23,156 @@ discard block |
||
23 | 23 | 'number_formatter_fr_1' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
24 | 24 | 'number_formatter_fr_2' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
25 | 25 | 'number_formatter_unformatted' => array('arguments' => array('element' => NULL)), |
26 | - ); |
|
26 | + ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Implementation of hook_field_info(). |
31 | 31 | */ |
32 | 32 | function number_field_info() { |
33 | - return array( |
|
33 | + return array( |
|
34 | 34 | 'number_integer' => array( |
35 | - 'label' => t('Integer'), |
|
36 | - 'description' => t('Store a number in the database as an integer.'), |
|
35 | + 'label' => t('Integer'), |
|
36 | + 'description' => t('Store a number in the database as an integer.'), |
|
37 | 37 | // 'content_icon' => 'icon_content_number.png', |
38 | 38 | ), |
39 | 39 | 'number_decimal' => array( |
40 | - 'label' => t('Decimal'), |
|
41 | - 'description' => t('Store a number in the database in a fixed decimal format.'), |
|
40 | + 'label' => t('Decimal'), |
|
41 | + 'description' => t('Store a number in the database in a fixed decimal format.'), |
|
42 | 42 | // 'content_icon' => 'icon_content_number.png', |
43 | 43 | ), |
44 | 44 | 'number_float' => array( |
45 | - 'label' => t('Float'), |
|
46 | - 'description' => t('Store a number in the database in a floating point format.'), |
|
45 | + 'label' => t('Float'), |
|
46 | + 'description' => t('Store a number in the database in a floating point format.'), |
|
47 | 47 | // 'content_icon' => 'icon_content_number.png', |
48 | 48 | ), |
49 | - ); |
|
49 | + ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Implementation of hook_field_settings(). |
54 | 54 | */ |
55 | 55 | function number_field_settings($op, $field) { |
56 | - switch ($op) { |
|
56 | + switch ($op) { |
|
57 | 57 | case 'form': |
58 | 58 | $form = array(); |
59 | - $form['min'] = array( |
|
59 | + $form['min'] = array( |
|
60 | 60 | '#type' => 'textfield', |
61 | 61 | '#title' => t('Minimum'), |
62 | 62 | '#element_validate' => array('_element_validate_number'), |
63 | 63 | '#default_value' => is_numeric($field['min']) ? $field['min'] : '', |
64 | - ); |
|
65 | - $form['max'] = array( |
|
64 | + ); |
|
65 | + $form['max'] = array( |
|
66 | 66 | '#type' => 'textfield', |
67 | 67 | '#title' => t('Maximum'), |
68 | 68 | '#element_validate' => array('_element_validate_number'), |
69 | 69 | '#default_value' => is_numeric($field['max']) ? $field['max'] : '', |
70 | - ); |
|
71 | - if ($field['type'] == 'number_decimal') { |
|
70 | + ); |
|
71 | + if ($field['type'] == 'number_decimal') { |
|
72 | 72 | $form['precision'] = array( |
73 | - '#type' => 'select', |
|
74 | - '#options' => drupal_map_assoc(range(10, 32)), |
|
75 | - '#title' => t('Precision'), |
|
76 | - '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), |
|
77 | - '#default_value' => is_numeric($field['precision']) ? $field['precision'] : 10, |
|
73 | + '#type' => 'select', |
|
74 | + '#options' => drupal_map_assoc(range(10, 32)), |
|
75 | + '#title' => t('Precision'), |
|
76 | + '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), |
|
77 | + '#default_value' => is_numeric($field['precision']) ? $field['precision'] : 10, |
|
78 | 78 | ); |
79 | 79 | $form['scale'] = array( |
80 | - '#type' => 'select', |
|
81 | - '#options' => drupal_map_assoc(range(0, 10)), |
|
82 | - '#title' => t('Scale'), |
|
83 | - '#description' => t('The number of digits to the right of the decimal.'), |
|
84 | - '#default_value' => is_numeric($field['scale']) ? $field['scale'] : 2, |
|
80 | + '#type' => 'select', |
|
81 | + '#options' => drupal_map_assoc(range(0, 10)), |
|
82 | + '#title' => t('Scale'), |
|
83 | + '#description' => t('The number of digits to the right of the decimal.'), |
|
84 | + '#default_value' => is_numeric($field['scale']) ? $field['scale'] : 2, |
|
85 | 85 | ); |
86 | 86 | $form['decimal'] = array( |
87 | - '#type' => 'select', |
|
88 | - '#options' => array('.' => 'decimal point', ',' => 'comma', ' ' => 'space'), |
|
89 | - '#title' => t('Decimal marker'), |
|
90 | - '#description' => t('The character users will input to mark the decimal point in forms.'), |
|
91 | - '#default_value' => !empty($field['decimal']) ? $field['decimal'] : '.', |
|
87 | + '#type' => 'select', |
|
88 | + '#options' => array('.' => 'decimal point', ',' => 'comma', ' ' => 'space'), |
|
89 | + '#title' => t('Decimal marker'), |
|
90 | + '#description' => t('The character users will input to mark the decimal point in forms.'), |
|
91 | + '#default_value' => !empty($field['decimal']) ? $field['decimal'] : '.', |
|
92 | 92 | ); |
93 | - } |
|
94 | - $form['append']['prefix'] = array( |
|
93 | + } |
|
94 | + $form['append']['prefix'] = array( |
|
95 | 95 | '#type' => 'textfield', |
96 | 96 | '#title' => t('Prefix'), |
97 | 97 | '#size' => 60, |
98 | 98 | '#default_value' => !empty($field['prefix']) ? $field['prefix'] : '', |
99 | 99 | '#description' => t('Define a string that should be prefixed to the value, like $ or €. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
100 | - ); |
|
101 | - $form['append']['suffix'] = array( |
|
100 | + ); |
|
101 | + $form['append']['suffix'] = array( |
|
102 | 102 | '#type' => 'textfield', |
103 | 103 | '#title' => t('Suffix'), |
104 | 104 | '#size' => 60, |
105 | 105 | '#default_value' => !empty($field['suffix']) ? $field['suffix'] : '', |
106 | 106 | '#description' => t('Define a string that should suffixed to the value, like m², m/s², kb/s. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
107 | - ); |
|
108 | - $form['allowed_values_fieldset'] = array( |
|
107 | + ); |
|
108 | + $form['allowed_values_fieldset'] = array( |
|
109 | 109 | '#type' => 'fieldset', |
110 | 110 | '#title' => t('Allowed values'), |
111 | 111 | '#collapsible' => TRUE, |
112 | 112 | '#collapsed' => TRUE, |
113 | - ); |
|
114 | - $form['allowed_values_fieldset']['allowed_values'] = array( |
|
113 | + ); |
|
114 | + $form['allowed_values_fieldset']['allowed_values'] = array( |
|
115 | 115 | '#type' => 'textarea', |
116 | 116 | '#title' => t('Allowed values list'), |
117 | 117 | '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
118 | 118 | '#required' => FALSE, |
119 | 119 | '#rows' => 10, |
120 | 120 | '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
121 | - ); |
|
122 | - $form['allowed_values_fieldset']['advanced_options'] = array( |
|
121 | + ); |
|
122 | + $form['allowed_values_fieldset']['advanced_options'] = array( |
|
123 | 123 | '#type' => 'fieldset', |
124 | 124 | '#title' => t('PHP code'), |
125 | 125 | '#collapsible' => TRUE, |
126 | 126 | '#collapsed' => empty($field['allowed_values_php']), |
127 | - ); |
|
128 | - if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
127 | + ); |
|
128 | + if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
129 | 129 | $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array( |
130 | - '#type' => 'textarea', |
|
131 | - '#title' => t('Code'), |
|
132 | - '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
133 | - '#rows' => 6, |
|
134 | - '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
130 | + '#type' => 'textarea', |
|
131 | + '#title' => t('Code'), |
|
132 | + '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
133 | + '#rows' => 6, |
|
134 | + '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
135 | 135 | ); |
136 | - } |
|
137 | - else { |
|
136 | + } |
|
137 | + else { |
|
138 | 138 | $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
139 | - '#type' => 'item', |
|
140 | - '#title' => t('Code'), |
|
141 | - '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
142 | - '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
139 | + '#type' => 'item', |
|
140 | + '#title' => t('Code'), |
|
141 | + '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
142 | + '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
143 | 143 | ); |
144 | - } |
|
145 | - return $form; |
|
144 | + } |
|
145 | + return $form; |
|
146 | 146 | |
147 | 147 | case 'save': |
148 | 148 | $values = array('prefix', 'suffix', 'min', 'max', 'allowed_values', 'allowed_values_php'); |
149 | - if ($field['type'] == 'number_decimal') { |
|
149 | + if ($field['type'] == 'number_decimal') { |
|
150 | 150 | $values = array_merge($values, array('precision', 'scale', 'decimal')); |
151 | - } |
|
152 | - return $values; |
|
151 | + } |
|
152 | + return $values; |
|
153 | 153 | |
154 | 154 | case 'database columns': |
155 | 155 | if ($field['type'] == 'number_integer') { |
156 | 156 | return array( |
157 | - 'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE), |
|
157 | + 'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE), |
|
158 | 158 | ); |
159 | - } |
|
160 | - if ($field['type'] == 'number_float') { |
|
159 | + } |
|
160 | + if ($field['type'] == 'number_float') { |
|
161 | 161 | return array( |
162 | - 'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE), |
|
162 | + 'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE), |
|
163 | 163 | ); |
164 | - } |
|
165 | - if ($field['type'] == 'number_decimal') { |
|
164 | + } |
|
165 | + if ($field['type'] == 'number_decimal') { |
|
166 | 166 | $precision = isset($field['precision']) ? $field['precision'] : 10; |
167 | 167 | $scale = isset($field['scale']) ? $field['scale'] : 2; |
168 | 168 | return array( |
169 | - 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE), |
|
169 | + 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE), |
|
170 | 170 | ); |
171 | - } |
|
171 | + } |
|
172 | 172 | |
173 | 173 | case 'views data': |
174 | 174 | $allowed_values = content_allowed_values($field); |
175 | - if (count($allowed_values)) { |
|
175 | + if (count($allowed_values)) { |
|
176 | 176 | $data = content_views_field_views_data($field); |
177 | 177 | $db_info = content_database_info($field); |
178 | 178 | $table_alias = content_views_tablename($field); |
@@ -188,79 +188,79 @@ discard block |
||
188 | 188 | $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
189 | 189 | $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE; |
190 | 190 | return $data; |
191 | - } |
|
192 | - break; |
|
193 | - } |
|
191 | + } |
|
192 | + break; |
|
193 | + } |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | function _number_widget_settings_min_validate($element, &$form_state) { |
197 | - $value = $form_state['values']['min']; |
|
198 | - if ($value && !is_numeric($value)) { |
|
197 | + $value = $form_state['values']['min']; |
|
198 | + if ($value && !is_numeric($value)) { |
|
199 | 199 | form_set_error('min', t('"Minimum" must be a number.')); |
200 | - } |
|
200 | + } |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | function _number_widget_settings_max_validate($element, &$form_state) { |
204 | - $value = $form_state['values']['max']; |
|
205 | - if ($value && !is_numeric($value)) { |
|
204 | + $value = $form_state['values']['max']; |
|
205 | + if ($value && !is_numeric($value)) { |
|
206 | 206 | form_set_error('max', t('"Maximum" must be a number.')); |
207 | - } |
|
207 | + } |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * Implementation of hook_field(). |
212 | 212 | */ |
213 | 213 | function number_field($op, &$node, $field, &$items, $teaser, $page) { |
214 | - switch ($op) { |
|
214 | + switch ($op) { |
|
215 | 215 | case 'validate': |
216 | 216 | $allowed_values = content_allowed_values($field); |
217 | - if (is_array($items)) { |
|
217 | + if (is_array($items)) { |
|
218 | 218 | foreach ($items as $delta => $item) { |
219 | - $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
220 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
221 | - if ($item['value'] != '') { |
|
219 | + $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
220 | + if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
221 | + if ($item['value'] != '') { |
|
222 | 222 | if (is_numeric($field['min']) && $item['value'] < $field['min']) { |
223 | - form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min']))); |
|
223 | + form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min']))); |
|
224 | 224 | } |
225 | 225 | if (is_numeric($field['max']) && $item['value'] > $field['max']) { |
226 | - form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max']))); |
|
226 | + form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max']))); |
|
227 | 227 | } |
228 | 228 | if (count($allowed_values)) { |
229 | - // We cannot use array_key_exists() because allowed values are |
|
230 | - // stored as strings, and we need to compare numeric equality. |
|
231 | - $valid = FALSE; |
|
232 | - foreach ($allowed_values as $kay => $value) { |
|
229 | + // We cannot use array_key_exists() because allowed values are |
|
230 | + // stored as strings, and we need to compare numeric equality. |
|
231 | + $valid = FALSE; |
|
232 | + foreach ($allowed_values as $kay => $value) { |
|
233 | 233 | if ((float) $item['value'] == (float) $kay) { |
234 | - $valid = TRUE; |
|
235 | - break; |
|
234 | + $valid = TRUE; |
|
235 | + break; |
|
236 | 236 | } |
237 | - } |
|
238 | - if (!$valid) { |
|
237 | + } |
|
238 | + if (!$valid) { |
|
239 | 239 | form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label'])))); |
240 | - } |
|
240 | + } |
|
241 | + } |
|
241 | 242 | } |
242 | - } |
|
243 | 243 | } |
244 | - } |
|
245 | - return $items; |
|
246 | - } |
|
244 | + } |
|
245 | + return $items; |
|
246 | + } |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
250 | 250 | * Implementation of hook_content_is_empty(). |
251 | 251 | */ |
252 | 252 | function number_content_is_empty($item, $field) { |
253 | - if (empty($item['value']) && (string)$item['value'] !== '0') { |
|
253 | + if (empty($item['value']) && (string)$item['value'] !== '0') { |
|
254 | 254 | return TRUE; |
255 | - } |
|
256 | - return FALSE; |
|
255 | + } |
|
256 | + return FALSE; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | 260 | * Implementation of hook_field_formatter_info(). |
261 | 261 | */ |
262 | 262 | function number_field_formatter_info() { |
263 | - return array( |
|
263 | + return array( |
|
264 | 264 | 'default' => array('label' => '9999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
265 | 265 | 'us_0' => array('label' => '9,999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
266 | 266 | 'us_1' => array('label' => '9,999.9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
@@ -272,72 +272,72 @@ discard block |
||
272 | 272 | 'fr_1' => array('label' => '9 999, 9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
273 | 273 | 'fr_2' => array('label' => '9 999, 99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
274 | 274 | 'unformatted' => array('label' => t('unformatted'), 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
275 | - ); |
|
275 | + ); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
279 | 279 | * Proxy theme function for 'unformatted' number field formatter. |
280 | 280 | */ |
281 | 281 | function theme_number_formatter_unformatted($element) { |
282 | - return $element['#item']['value']; |
|
282 | + return $element['#item']['value']; |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | 286 | * Proxy theme function for number field formatters. |
287 | 287 | */ |
288 | 288 | function theme_number_formatter_generic($element) { |
289 | - $field = content_fields($element['#field_name'], $element['#type_name']); |
|
290 | - $value = $element['#item']['value']; |
|
289 | + $field = content_fields($element['#field_name'], $element['#type_name']); |
|
290 | + $value = $element['#item']['value']; |
|
291 | 291 | |
292 | - if (($allowed_values = content_allowed_values($field))) { |
|
292 | + if (($allowed_values = content_allowed_values($field))) { |
|
293 | 293 | if (isset($allowed_values[$value]) && $allowed_values[$value] != $value) { |
294 | - return $allowed_values[$value]; |
|
294 | + return $allowed_values[$value]; |
|
295 | + } |
|
295 | 296 | } |
296 | - } |
|
297 | 297 | |
298 | - if (empty($value) && $value !== '0') { |
|
298 | + if (empty($value) && $value !== '0') { |
|
299 | 299 | return ''; |
300 | - } |
|
300 | + } |
|
301 | 301 | |
302 | - switch ($element['#formatter']) { |
|
302 | + switch ($element['#formatter']) { |
|
303 | 303 | case 'us_0': |
304 | 304 | $output = number_format($value, 0, '.', ','); |
305 | - break; |
|
305 | + break; |
|
306 | 306 | case 'us_1': |
307 | 307 | $output = number_format($value, 1, '.', ','); |
308 | - break; |
|
308 | + break; |
|
309 | 309 | case 'us_2': |
310 | 310 | $output = number_format($value, 2, '.', ','); |
311 | - break; |
|
311 | + break; |
|
312 | 312 | case 'be_0': |
313 | 313 | $output = number_format($value, 0, ',', '.'); |
314 | - break; |
|
314 | + break; |
|
315 | 315 | case 'be_1': |
316 | 316 | $output = number_format($value, 1, ',', '.'); |
317 | - break; |
|
317 | + break; |
|
318 | 318 | case 'be_2': |
319 | 319 | $output = number_format($value, 2, ',', '.'); |
320 | - break; |
|
320 | + break; |
|
321 | 321 | case 'fr_0': |
322 | 322 | $output = number_format($value, 0, ', ', ' '); |
323 | - break; |
|
323 | + break; |
|
324 | 324 | case 'fr_1': |
325 | 325 | $output = number_format($value, 1, ', ', ' '); |
326 | - break; |
|
326 | + break; |
|
327 | 327 | case 'fr_2': |
328 | 328 | $output = number_format($value, 2, ', ', ' '); |
329 | - break; |
|
329 | + break; |
|
330 | 330 | default: |
331 | 331 | $output = $value; |
332 | - break; |
|
333 | - } |
|
332 | + break; |
|
333 | + } |
|
334 | 334 | |
335 | - $prefixes = isset($field['prefix']) ? array_map('content_filter_xss', explode('|', $field['prefix'])) : array(''); |
|
336 | - $suffixes = isset($field['suffix']) ? array_map('content_filter_xss', explode('|', $field['suffix'])) : array(''); |
|
337 | - $prefix = (count($prefixes) > 1) ? format_plural($value, $prefixes[0], $prefixes[1]) : $prefixes[0]; |
|
338 | - $suffix = (count($suffixes) > 1) ? format_plural($value, $suffixes[0], $suffixes[1]) : $suffixes[0]; |
|
335 | + $prefixes = isset($field['prefix']) ? array_map('content_filter_xss', explode('|', $field['prefix'])) : array(''); |
|
336 | + $suffixes = isset($field['suffix']) ? array_map('content_filter_xss', explode('|', $field['suffix'])) : array(''); |
|
337 | + $prefix = (count($prefixes) > 1) ? format_plural($value, $prefixes[0], $prefixes[1]) : $prefixes[0]; |
|
338 | + $suffix = (count($suffixes) > 1) ? format_plural($value, $suffixes[0], $suffixes[1]) : $suffixes[0]; |
|
339 | 339 | |
340 | - return $prefix . $output . $suffix; |
|
340 | + return $prefix . $output . $suffix; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -352,16 +352,16 @@ discard block |
||
352 | 352 | * differently. |
353 | 353 | */ |
354 | 354 | function number_widget_info() { |
355 | - return array( |
|
355 | + return array( |
|
356 | 356 | 'number' => array( |
357 | - 'label' => t('Text field'), |
|
358 | - 'field types' => array('number_integer', 'number_decimal', 'number_float'), |
|
359 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
360 | - 'callbacks' => array( |
|
357 | + 'label' => t('Text field'), |
|
358 | + 'field types' => array('number_integer', 'number_decimal', 'number_float'), |
|
359 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
360 | + 'callbacks' => array( |
|
361 | 361 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
362 | - ), |
|
362 | + ), |
|
363 | 363 | ), |
364 | - ); |
|
364 | + ); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | /** |
@@ -377,13 +377,13 @@ discard block |
||
377 | 377 | * the validator can use. The regex can be overridden if necessary. |
378 | 378 | */ |
379 | 379 | function number_elements() { |
380 | - return array( |
|
380 | + return array( |
|
381 | 381 | 'number' => array( |
382 | - '#input' => TRUE, |
|
383 | - '#columns' => array('value'), '#delta' => 0, |
|
384 | - '#process' => array('number_process'), |
|
382 | + '#input' => TRUE, |
|
383 | + '#columns' => array('value'), '#delta' => 0, |
|
384 | + '#process' => array('number_process'), |
|
385 | 385 | ), |
386 | - ); |
|
386 | + ); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -418,11 +418,11 @@ discard block |
||
418 | 418 | * the form item for a single element for this field |
419 | 419 | */ |
420 | 420 | function number_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
421 | - $element = array( |
|
421 | + $element = array( |
|
422 | 422 | '#type' => $field['widget']['type'], |
423 | 423 | '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL, |
424 | - ); |
|
425 | - return $element; |
|
424 | + ); |
|
425 | + return $element; |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -434,13 +434,13 @@ discard block |
||
434 | 434 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
435 | 435 | */ |
436 | 436 | function number_process($element, $edit, $form_state, $form) { |
437 | - $field_name = $element['#field_name']; |
|
438 | - $field = $form['#field_info'][$field_name]; |
|
439 | - $field_key = $element['#columns'][0]; |
|
437 | + $field_name = $element['#field_name']; |
|
438 | + $field = $form['#field_info'][$field_name]; |
|
439 | + $field_key = $element['#columns'][0]; |
|
440 | 440 | |
441 | - $value = isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : ''; |
|
442 | - $value = isset($field['decimal']) ? str_replace('.', $field['decimal'], $value) : $value; |
|
443 | - $element[$field_key] = array( |
|
441 | + $value = isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : ''; |
|
442 | + $value = isset($field['decimal']) ? str_replace('.', $field['decimal'], $value) : $value; |
|
443 | + $element[$field_key] = array( |
|
444 | 444 | '#type' => 'textfield', |
445 | 445 | '#default_value' => $value, |
446 | 446 | // Need to allow a slightly larger size that the field length to allow |
@@ -457,117 +457,117 @@ discard block |
||
457 | 457 | '#type_name' => $element['#type_name'], |
458 | 458 | '#delta' => $element['#delta'], |
459 | 459 | '#columns' => $element['#columns'], |
460 | - ); |
|
460 | + ); |
|
461 | 461 | |
462 | - $prefixes = array(); |
|
463 | - $suffixes = array(); |
|
462 | + $prefixes = array(); |
|
463 | + $suffixes = array(); |
|
464 | 464 | |
465 | - // Make sure we don't wipe out element validation added elsewhere. |
|
466 | - if (empty($element['#element_validate'])) { |
|
465 | + // Make sure we don't wipe out element validation added elsewhere. |
|
466 | + if (empty($element['#element_validate'])) { |
|
467 | 467 | $element['#element_validate'] = array(); |
468 | - } |
|
469 | - if (!empty($field['prefix'])) { |
|
468 | + } |
|
469 | + if (!empty($field['prefix'])) { |
|
470 | 470 | $prefixes = explode('|', $field['prefix']); |
471 | 471 | $element[$field_key]['#field_prefix'] = content_filter_xss(array_pop($prefixes)); |
472 | - } |
|
473 | - if (!empty($field['suffix'])) { |
|
472 | + } |
|
473 | + if (!empty($field['suffix'])) { |
|
474 | 474 | $suffixes = explode('|', $field['suffix']); |
475 | 475 | $element[$field_key]['#field_suffix'] = content_filter_xss(array_pop($suffixes)); |
476 | - } |
|
477 | - switch ($field['type']) { |
|
476 | + } |
|
477 | + switch ($field['type']) { |
|
478 | 478 | case 'number_float': |
479 | 479 | $element['#element_validate'][] = 'number_float_validate'; |
480 | - break; |
|
480 | + break; |
|
481 | 481 | case 'number_integer': |
482 | 482 | $element['#element_validate'][] = 'number_integer_validate'; |
483 | - break; |
|
483 | + break; |
|
484 | 484 | case 'number_decimal': |
485 | 485 | $element['#element_validate'][] = 'number_decimal_validate'; |
486 | - $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.'; |
|
487 | - $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10; |
|
488 | - $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2; |
|
489 | - break; |
|
490 | - } |
|
491 | - |
|
492 | - // Used so that hook_field('validate') knows where to flag an error. |
|
493 | - $element['_error_element'] = array( |
|
486 | + $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.'; |
|
487 | + $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10; |
|
488 | + $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2; |
|
489 | + break; |
|
490 | + } |
|
491 | + |
|
492 | + // Used so that hook_field('validate') knows where to flag an error. |
|
493 | + $element['_error_element'] = array( |
|
494 | 494 | '#type' => 'value', |
495 | 495 | '#value' => implode('][', array_merge($element['#parents'], array($field_key))), |
496 | - ); |
|
496 | + ); |
|
497 | 497 | |
498 | - return $element; |
|
498 | + return $element; |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
502 | 502 | * FAPI validation of an individual float element. |
503 | 503 | */ |
504 | 504 | function number_float_validate($element, &$form_state) { |
505 | - $field_name = $element['#field_name']; |
|
506 | - $type_name = $element['#type_name']; |
|
507 | - $field = content_fields($field_name, $type_name); |
|
508 | - $field_key = $element['#columns'][0]; |
|
509 | - $value = $element['#value'][$field_key]; |
|
505 | + $field_name = $element['#field_name']; |
|
506 | + $type_name = $element['#type_name']; |
|
507 | + $field = content_fields($field_name, $type_name); |
|
508 | + $field_key = $element['#columns'][0]; |
|
509 | + $value = $element['#value'][$field_key]; |
|
510 | 510 | |
511 | - if (($element[$field_key]['#required'] || !empty($value))) { |
|
511 | + if (($element[$field_key]['#required'] || !empty($value))) { |
|
512 | 512 | $start = $value; |
513 | 513 | $value = preg_replace('@[^-0-9\.]@', '', $value); |
514 | 514 | if ($start != $value) { |
515 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
516 | - form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
|
515 | + $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
516 | + form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
|
517 | 517 | } |
518 | 518 | else { |
519 | - form_set_value($element[$field_key], $value, $form_state); |
|
519 | + form_set_value($element[$field_key], $value, $form_state); |
|
520 | + } |
|
520 | 521 | } |
521 | - } |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
525 | 525 | * FAPI validation of an individual integer element. |
526 | 526 | */ |
527 | 527 | function number_integer_validate($element, &$form_state) { |
528 | - $field_name = $element['#field_name']; |
|
529 | - $type_name = $element['#type_name']; |
|
530 | - $field = content_fields($field_name, $type_name); |
|
531 | - $field_key = $element['#columns'][0]; |
|
532 | - $value = $element['#value'][$field_key]; |
|
528 | + $field_name = $element['#field_name']; |
|
529 | + $type_name = $element['#type_name']; |
|
530 | + $field = content_fields($field_name, $type_name); |
|
531 | + $field_key = $element['#columns'][0]; |
|
532 | + $value = $element['#value'][$field_key]; |
|
533 | 533 | |
534 | - if (($element[$field_key]['#required'] || !empty($value))) { |
|
534 | + if (($element[$field_key]['#required'] || !empty($value))) { |
|
535 | 535 | $start = $value; |
536 | 536 | $value = preg_replace('@[^-0-9]@', '', $value); |
537 | 537 | if ($start != $value) { |
538 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
539 | - form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
|
538 | + $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
539 | + form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
|
540 | 540 | } |
541 | 541 | else { |
542 | - form_set_value($element[$field_key], $value, $form_state); |
|
542 | + form_set_value($element[$field_key], $value, $form_state); |
|
543 | + } |
|
543 | 544 | } |
544 | - } |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
548 | 548 | * FAPI validation of an individual decimal element. |
549 | 549 | */ |
550 | 550 | function number_decimal_validate($element, &$form_state) { |
551 | - $field_name = $element['#field_name']; |
|
552 | - $type_name = $element['#type_name']; |
|
553 | - $field = content_fields($field_name, $type_name); |
|
554 | - $field_key = $element['#columns'][0]; |
|
555 | - $value = $element['#value'][$field_key]; |
|
551 | + $field_name = $element['#field_name']; |
|
552 | + $type_name = $element['#type_name']; |
|
553 | + $field = content_fields($field_name, $type_name); |
|
554 | + $field_key = $element['#columns'][0]; |
|
555 | + $value = $element['#value'][$field_key]; |
|
556 | 556 | |
557 | - if (($element[$field_key]['#required'] || !empty($value))) { |
|
557 | + if (($element[$field_key]['#required'] || !empty($value))) { |
|
558 | 558 | $decimal = $element['#decimal'] ? $element['#decimal'] : '.'; |
559 | 559 | $start = $value; |
560 | 560 | $value = preg_replace('@[^-0-9\\'. $decimal .']@', '', $value); |
561 | 561 | if ($start != $value) { |
562 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
563 | - form_set_error($error_field, t('Only numbers and the decimal character (%decimal) are allowed in %field.', array('%decimal' => $element['#decimal'], '%field' => t($field['widget']['label'])))); |
|
562 | + $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
563 | + form_set_error($error_field, t('Only numbers and the decimal character (%decimal) are allowed in %field.', array('%decimal' => $element['#decimal'], '%field' => t($field['widget']['label'])))); |
|
564 | 564 | } |
565 | 565 | else { |
566 | - $value = str_replace($element['#decimal'], '.', $value); |
|
567 | - $value = round($value, $element['#scale']); |
|
568 | - form_set_value($element[$field_key], $value, $form_state); |
|
566 | + $value = str_replace($element['#decimal'], '.', $value); |
|
567 | + $value = round($value, $element['#scale']); |
|
568 | + form_set_value($element[$field_key], $value, $form_state); |
|
569 | + } |
|
569 | 570 | } |
570 | - } |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -581,5 +581,5 @@ discard block |
||
581 | 581 | * $element['#delta] is the position of this element in the group |
582 | 582 | */ |
583 | 583 | function theme_number($element) { |
584 | - return $element['#children']; |
|
584 | + return $element['#children']; |
|
585 | 585 | } |
586 | 586 | \ No newline at end of file |
@@ -54,142 +54,142 @@ discard block |
||
54 | 54 | */ |
55 | 55 | function number_field_settings($op, $field) { |
56 | 56 | switch ($op) { |
57 | - case 'form': |
|
58 | - $form = array(); |
|
59 | - $form['min'] = array( |
|
60 | - '#type' => 'textfield', |
|
61 | - '#title' => t('Minimum'), |
|
62 | - '#element_validate' => array('_element_validate_number'), |
|
63 | - '#default_value' => is_numeric($field['min']) ? $field['min'] : '', |
|
57 | + case 'form': |
|
58 | + $form = array(); |
|
59 | + $form['min'] = array( |
|
60 | + '#type' => 'textfield', |
|
61 | + '#title' => t('Minimum'), |
|
62 | + '#element_validate' => array('_element_validate_number'), |
|
63 | + '#default_value' => is_numeric($field['min']) ? $field['min'] : '', |
|
64 | + ); |
|
65 | + $form['max'] = array( |
|
66 | + '#type' => 'textfield', |
|
67 | + '#title' => t('Maximum'), |
|
68 | + '#element_validate' => array('_element_validate_number'), |
|
69 | + '#default_value' => is_numeric($field['max']) ? $field['max'] : '', |
|
70 | + ); |
|
71 | + if ($field['type'] == 'number_decimal') { |
|
72 | + $form['precision'] = array( |
|
73 | + '#type' => 'select', |
|
74 | + '#options' => drupal_map_assoc(range(10, 32)), |
|
75 | + '#title' => t('Precision'), |
|
76 | + '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), |
|
77 | + '#default_value' => is_numeric($field['precision']) ? $field['precision'] : 10, |
|
64 | 78 | ); |
65 | - $form['max'] = array( |
|
66 | - '#type' => 'textfield', |
|
67 | - '#title' => t('Maximum'), |
|
68 | - '#element_validate' => array('_element_validate_number'), |
|
69 | - '#default_value' => is_numeric($field['max']) ? $field['max'] : '', |
|
79 | + $form['scale'] = array( |
|
80 | + '#type' => 'select', |
|
81 | + '#options' => drupal_map_assoc(range(0, 10)), |
|
82 | + '#title' => t('Scale'), |
|
83 | + '#description' => t('The number of digits to the right of the decimal.'), |
|
84 | + '#default_value' => is_numeric($field['scale']) ? $field['scale'] : 2, |
|
70 | 85 | ); |
71 | - if ($field['type'] == 'number_decimal') { |
|
72 | - $form['precision'] = array( |
|
73 | - '#type' => 'select', |
|
74 | - '#options' => drupal_map_assoc(range(10, 32)), |
|
75 | - '#title' => t('Precision'), |
|
76 | - '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), |
|
77 | - '#default_value' => is_numeric($field['precision']) ? $field['precision'] : 10, |
|
78 | - ); |
|
79 | - $form['scale'] = array( |
|
80 | - '#type' => 'select', |
|
81 | - '#options' => drupal_map_assoc(range(0, 10)), |
|
82 | - '#title' => t('Scale'), |
|
83 | - '#description' => t('The number of digits to the right of the decimal.'), |
|
84 | - '#default_value' => is_numeric($field['scale']) ? $field['scale'] : 2, |
|
85 | - ); |
|
86 | - $form['decimal'] = array( |
|
87 | - '#type' => 'select', |
|
88 | - '#options' => array('.' => 'decimal point', ',' => 'comma', ' ' => 'space'), |
|
89 | - '#title' => t('Decimal marker'), |
|
90 | - '#description' => t('The character users will input to mark the decimal point in forms.'), |
|
91 | - '#default_value' => !empty($field['decimal']) ? $field['decimal'] : '.', |
|
92 | - ); |
|
93 | - } |
|
94 | - $form['append']['prefix'] = array( |
|
95 | - '#type' => 'textfield', |
|
96 | - '#title' => t('Prefix'), |
|
97 | - '#size' => 60, |
|
98 | - '#default_value' => !empty($field['prefix']) ? $field['prefix'] : '', |
|
99 | - '#description' => t('Define a string that should be prefixed to the value, like $ or €. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
|
100 | - ); |
|
101 | - $form['append']['suffix'] = array( |
|
102 | - '#type' => 'textfield', |
|
103 | - '#title' => t('Suffix'), |
|
104 | - '#size' => 60, |
|
105 | - '#default_value' => !empty($field['suffix']) ? $field['suffix'] : '', |
|
106 | - '#description' => t('Define a string that should suffixed to the value, like m², m/s², kb/s. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
|
86 | + $form['decimal'] = array( |
|
87 | + '#type' => 'select', |
|
88 | + '#options' => array('.' => 'decimal point', ',' => 'comma', ' ' => 'space'), |
|
89 | + '#title' => t('Decimal marker'), |
|
90 | + '#description' => t('The character users will input to mark the decimal point in forms.'), |
|
91 | + '#default_value' => !empty($field['decimal']) ? $field['decimal'] : '.', |
|
107 | 92 | ); |
108 | - $form['allowed_values_fieldset'] = array( |
|
109 | - '#type' => 'fieldset', |
|
110 | - '#title' => t('Allowed values'), |
|
111 | - '#collapsible' => TRUE, |
|
112 | - '#collapsed' => TRUE, |
|
113 | - ); |
|
114 | - $form['allowed_values_fieldset']['allowed_values'] = array( |
|
93 | + } |
|
94 | + $form['append']['prefix'] = array( |
|
95 | + '#type' => 'textfield', |
|
96 | + '#title' => t('Prefix'), |
|
97 | + '#size' => 60, |
|
98 | + '#default_value' => !empty($field['prefix']) ? $field['prefix'] : '', |
|
99 | + '#description' => t('Define a string that should be prefixed to the value, like $ or €. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
|
100 | + ); |
|
101 | + $form['append']['suffix'] = array( |
|
102 | + '#type' => 'textfield', |
|
103 | + '#title' => t('Suffix'), |
|
104 | + '#size' => 60, |
|
105 | + '#default_value' => !empty($field['suffix']) ? $field['suffix'] : '', |
|
106 | + '#description' => t('Define a string that should suffixed to the value, like m², m/s², kb/s. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
|
107 | + ); |
|
108 | + $form['allowed_values_fieldset'] = array( |
|
109 | + '#type' => 'fieldset', |
|
110 | + '#title' => t('Allowed values'), |
|
111 | + '#collapsible' => TRUE, |
|
112 | + '#collapsed' => TRUE, |
|
113 | + ); |
|
114 | + $form['allowed_values_fieldset']['allowed_values'] = array( |
|
115 | + '#type' => 'textarea', |
|
116 | + '#title' => t('Allowed values list'), |
|
117 | + '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
|
118 | + '#required' => FALSE, |
|
119 | + '#rows' => 10, |
|
120 | + '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
|
121 | + ); |
|
122 | + $form['allowed_values_fieldset']['advanced_options'] = array( |
|
123 | + '#type' => 'fieldset', |
|
124 | + '#title' => t('PHP code'), |
|
125 | + '#collapsible' => TRUE, |
|
126 | + '#collapsed' => empty($field['allowed_values_php']), |
|
127 | + ); |
|
128 | + if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
129 | + $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array( |
|
115 | 130 | '#type' => 'textarea', |
116 | - '#title' => t('Allowed values list'), |
|
117 | - '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
|
118 | - '#required' => FALSE, |
|
119 | - '#rows' => 10, |
|
120 | - '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
|
131 | + '#title' => t('Code'), |
|
132 | + '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
133 | + '#rows' => 6, |
|
134 | + '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
121 | 135 | ); |
122 | - $form['allowed_values_fieldset']['advanced_options'] = array( |
|
123 | - '#type' => 'fieldset', |
|
124 | - '#title' => t('PHP code'), |
|
125 | - '#collapsible' => TRUE, |
|
126 | - '#collapsed' => empty($field['allowed_values_php']), |
|
136 | + } |
|
137 | + else { |
|
138 | + $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
|
139 | + '#type' => 'item', |
|
140 | + '#title' => t('Code'), |
|
141 | + '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
142 | + '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
127 | 143 | ); |
128 | - if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
129 | - $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array( |
|
130 | - '#type' => 'textarea', |
|
131 | - '#title' => t('Code'), |
|
132 | - '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
133 | - '#rows' => 6, |
|
134 | - '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
135 | - ); |
|
136 | - } |
|
137 | - else { |
|
138 | - $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
|
139 | - '#type' => 'item', |
|
140 | - '#title' => t('Code'), |
|
141 | - '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
142 | - '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
143 | - ); |
|
144 | - } |
|
145 | - return $form; |
|
144 | + } |
|
145 | + return $form; |
|
146 | 146 | |
147 | - case 'save': |
|
148 | - $values = array('prefix', 'suffix', 'min', 'max', 'allowed_values', 'allowed_values_php'); |
|
149 | - if ($field['type'] == 'number_decimal') { |
|
150 | - $values = array_merge($values, array('precision', 'scale', 'decimal')); |
|
151 | - } |
|
152 | - return $values; |
|
147 | + case 'save': |
|
148 | + $values = array('prefix', 'suffix', 'min', 'max', 'allowed_values', 'allowed_values_php'); |
|
149 | + if ($field['type'] == 'number_decimal') { |
|
150 | + $values = array_merge($values, array('precision', 'scale', 'decimal')); |
|
151 | + } |
|
152 | + return $values; |
|
153 | 153 | |
154 | - case 'database columns': |
|
155 | - if ($field['type'] == 'number_integer') { |
|
156 | - return array( |
|
157 | - 'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE), |
|
158 | - ); |
|
159 | - } |
|
160 | - if ($field['type'] == 'number_float') { |
|
161 | - return array( |
|
162 | - 'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE), |
|
163 | - ); |
|
164 | - } |
|
165 | - if ($field['type'] == 'number_decimal') { |
|
166 | - $precision = isset($field['precision']) ? $field['precision'] : 10; |
|
167 | - $scale = isset($field['scale']) ? $field['scale'] : 2; |
|
168 | - return array( |
|
169 | - 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE), |
|
170 | - ); |
|
171 | - } |
|
154 | + case 'database columns': |
|
155 | + if ($field['type'] == 'number_integer') { |
|
156 | + return array( |
|
157 | + 'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE), |
|
158 | + ); |
|
159 | + } |
|
160 | + if ($field['type'] == 'number_float') { |
|
161 | + return array( |
|
162 | + 'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE), |
|
163 | + ); |
|
164 | + } |
|
165 | + if ($field['type'] == 'number_decimal') { |
|
166 | + $precision = isset($field['precision']) ? $field['precision'] : 10; |
|
167 | + $scale = isset($field['scale']) ? $field['scale'] : 2; |
|
168 | + return array( |
|
169 | + 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE), |
|
170 | + ); |
|
171 | + } |
|
172 | 172 | |
173 | - case 'views data': |
|
174 | - $allowed_values = content_allowed_values($field); |
|
175 | - if (count($allowed_values)) { |
|
176 | - $data = content_views_field_views_data($field); |
|
177 | - $db_info = content_database_info($field); |
|
178 | - $table_alias = content_views_tablename($field); |
|
179 | - |
|
180 | - // Filter: Add a 'many to one' filter. |
|
181 | - $copy = $data[$table_alias][$field['field_name'] .'_value']; |
|
182 | - $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
|
183 | - $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
184 | - $copy['filter']['numeric'] = TRUE; |
|
185 | - unset($copy['field'], $copy['argument'], $copy['sort']); |
|
186 | - $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
|
187 | - // Argument: swap the handler to the 'many to one' operator |
|
188 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
189 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE; |
|
190 | - return $data; |
|
191 | - } |
|
192 | - break; |
|
173 | + case 'views data': |
|
174 | + $allowed_values = content_allowed_values($field); |
|
175 | + if (count($allowed_values)) { |
|
176 | + $data = content_views_field_views_data($field); |
|
177 | + $db_info = content_database_info($field); |
|
178 | + $table_alias = content_views_tablename($field); |
|
179 | + |
|
180 | + // Filter: Add a 'many to one' filter. |
|
181 | + $copy = $data[$table_alias][$field['field_name'] .'_value']; |
|
182 | + $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
|
183 | + $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
184 | + $copy['filter']['numeric'] = TRUE; |
|
185 | + unset($copy['field'], $copy['argument'], $copy['sort']); |
|
186 | + $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
|
187 | + // Argument: swap the handler to the 'many to one' operator |
|
188 | + $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
189 | + $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE; |
|
190 | + return $data; |
|
191 | + } |
|
192 | + break; |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
@@ -212,37 +212,37 @@ discard block |
||
212 | 212 | */ |
213 | 213 | function number_field($op, &$node, $field, &$items, $teaser, $page) { |
214 | 214 | switch ($op) { |
215 | - case 'validate': |
|
216 | - $allowed_values = content_allowed_values($field); |
|
217 | - if (is_array($items)) { |
|
218 | - foreach ($items as $delta => $item) { |
|
219 | - $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
220 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
221 | - if ($item['value'] != '') { |
|
222 | - if (is_numeric($field['min']) && $item['value'] < $field['min']) { |
|
223 | - form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min']))); |
|
224 | - } |
|
225 | - if (is_numeric($field['max']) && $item['value'] > $field['max']) { |
|
226 | - form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max']))); |
|
227 | - } |
|
228 | - if (count($allowed_values)) { |
|
229 | - // We cannot use array_key_exists() because allowed values are |
|
230 | - // stored as strings, and we need to compare numeric equality. |
|
231 | - $valid = FALSE; |
|
232 | - foreach ($allowed_values as $kay => $value) { |
|
233 | - if ((float) $item['value'] == (float) $kay) { |
|
234 | - $valid = TRUE; |
|
235 | - break; |
|
236 | - } |
|
237 | - } |
|
238 | - if (!$valid) { |
|
239 | - form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label'])))); |
|
215 | + case 'validate': |
|
216 | + $allowed_values = content_allowed_values($field); |
|
217 | + if (is_array($items)) { |
|
218 | + foreach ($items as $delta => $item) { |
|
219 | + $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
220 | + if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
221 | + if ($item['value'] != '') { |
|
222 | + if (is_numeric($field['min']) && $item['value'] < $field['min']) { |
|
223 | + form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min']))); |
|
224 | + } |
|
225 | + if (is_numeric($field['max']) && $item['value'] > $field['max']) { |
|
226 | + form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max']))); |
|
227 | + } |
|
228 | + if (count($allowed_values)) { |
|
229 | + // We cannot use array_key_exists() because allowed values are |
|
230 | + // stored as strings, and we need to compare numeric equality. |
|
231 | + $valid = FALSE; |
|
232 | + foreach ($allowed_values as $kay => $value) { |
|
233 | + if ((float) $item['value'] == (float) $kay) { |
|
234 | + $valid = TRUE; |
|
235 | + break; |
|
240 | 236 | } |
241 | 237 | } |
238 | + if (!$valid) { |
|
239 | + form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label'])))); |
|
240 | + } |
|
242 | 241 | } |
243 | 242 | } |
244 | 243 | } |
245 | - return $items; |
|
244 | + } |
|
245 | + return $items; |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
@@ -300,36 +300,36 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | switch ($element['#formatter']) { |
303 | - case 'us_0': |
|
304 | - $output = number_format($value, 0, '.', ','); |
|
305 | - break; |
|
306 | - case 'us_1': |
|
307 | - $output = number_format($value, 1, '.', ','); |
|
308 | - break; |
|
309 | - case 'us_2': |
|
310 | - $output = number_format($value, 2, '.', ','); |
|
311 | - break; |
|
312 | - case 'be_0': |
|
313 | - $output = number_format($value, 0, ',', '.'); |
|
314 | - break; |
|
315 | - case 'be_1': |
|
316 | - $output = number_format($value, 1, ',', '.'); |
|
317 | - break; |
|
318 | - case 'be_2': |
|
319 | - $output = number_format($value, 2, ',', '.'); |
|
320 | - break; |
|
321 | - case 'fr_0': |
|
322 | - $output = number_format($value, 0, ', ', ' '); |
|
323 | - break; |
|
324 | - case 'fr_1': |
|
325 | - $output = number_format($value, 1, ', ', ' '); |
|
326 | - break; |
|
327 | - case 'fr_2': |
|
328 | - $output = number_format($value, 2, ', ', ' '); |
|
329 | - break; |
|
330 | - default: |
|
331 | - $output = $value; |
|
332 | - break; |
|
303 | + case 'us_0': |
|
304 | + $output = number_format($value, 0, '.', ','); |
|
305 | + break; |
|
306 | + case 'us_1': |
|
307 | + $output = number_format($value, 1, '.', ','); |
|
308 | + break; |
|
309 | + case 'us_2': |
|
310 | + $output = number_format($value, 2, '.', ','); |
|
311 | + break; |
|
312 | + case 'be_0': |
|
313 | + $output = number_format($value, 0, ',', '.'); |
|
314 | + break; |
|
315 | + case 'be_1': |
|
316 | + $output = number_format($value, 1, ',', '.'); |
|
317 | + break; |
|
318 | + case 'be_2': |
|
319 | + $output = number_format($value, 2, ',', '.'); |
|
320 | + break; |
|
321 | + case 'fr_0': |
|
322 | + $output = number_format($value, 0, ', ', ' '); |
|
323 | + break; |
|
324 | + case 'fr_1': |
|
325 | + $output = number_format($value, 1, ', ', ' '); |
|
326 | + break; |
|
327 | + case 'fr_2': |
|
328 | + $output = number_format($value, 2, ', ', ' '); |
|
329 | + break; |
|
330 | + default: |
|
331 | + $output = $value; |
|
332 | + break; |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | $prefixes = isset($field['prefix']) ? array_map('content_filter_xss', explode('|', $field['prefix'])) : array(''); |
@@ -475,18 +475,18 @@ discard block |
||
475 | 475 | $element[$field_key]['#field_suffix'] = content_filter_xss(array_pop($suffixes)); |
476 | 476 | } |
477 | 477 | switch ($field['type']) { |
478 | - case 'number_float': |
|
479 | - $element['#element_validate'][] = 'number_float_validate'; |
|
480 | - break; |
|
481 | - case 'number_integer': |
|
482 | - $element['#element_validate'][] = 'number_integer_validate'; |
|
483 | - break; |
|
484 | - case 'number_decimal': |
|
485 | - $element['#element_validate'][] = 'number_decimal_validate'; |
|
486 | - $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.'; |
|
487 | - $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10; |
|
488 | - $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2; |
|
489 | - break; |
|
478 | + case 'number_float': |
|
479 | + $element['#element_validate'][] = 'number_float_validate'; |
|
480 | + break; |
|
481 | + case 'number_integer': |
|
482 | + $element['#element_validate'][] = 'number_integer_validate'; |
|
483 | + break; |
|
484 | + case 'number_decimal': |
|
485 | + $element['#element_validate'][] = 'number_decimal_validate'; |
|
486 | + $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.'; |
|
487 | + $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10; |
|
488 | + $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2; |
|
489 | + break; |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | // Used so that hook_field('validate') knows where to flag an error. |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
139 | 139 | '#type' => 'item', |
140 | 140 | '#title' => t('Code'), |
141 | - '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
141 | + '#value' => !empty($field['allowed_values_php']) ? '<code>'.check_plain($field['allowed_values_php']).'</code>' : t('<none>'), |
|
142 | 142 | '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
143 | 143 | ); |
144 | 144 | } |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | $table_alias = content_views_tablename($field); |
179 | 179 | |
180 | 180 | // Filter: Add a 'many to one' filter. |
181 | - $copy = $data[$table_alias][$field['field_name'] .'_value']; |
|
181 | + $copy = $data[$table_alias][$field['field_name'].'_value']; |
|
182 | 182 | $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
183 | 183 | $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
184 | 184 | $copy['filter']['numeric'] = TRUE; |
185 | 185 | unset($copy['field'], $copy['argument'], $copy['sort']); |
186 | - $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
|
186 | + $data[$table_alias][$field['field_name'].'_value_many_to_one'] = $copy; |
|
187 | 187 | // Argument: swap the handler to the 'many to one' operator |
188 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
189 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE; |
|
188 | + $data[$table_alias][$field['field_name'].'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
189 | + $data[$table_alias][$field['field_name'].'_value']['argument']['numeric'] = TRUE; |
|
190 | 190 | return $data; |
191 | 191 | } |
192 | 192 | break; |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | // stored as strings, and we need to compare numeric equality. |
231 | 231 | $valid = FALSE; |
232 | 232 | foreach ($allowed_values as $kay => $value) { |
233 | - if ((float) $item['value'] == (float) $kay) { |
|
233 | + if ((float)$item['value'] == (float)$kay) { |
|
234 | 234 | $valid = TRUE; |
235 | 235 | break; |
236 | 236 | } |
@@ -261,16 +261,16 @@ discard block |
||
261 | 261 | */ |
262 | 262 | function number_field_formatter_info() { |
263 | 263 | return array( |
264 | - 'default' => array('label' => '9999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
265 | - 'us_0' => array('label' => '9,999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
266 | - 'us_1' => array('label' => '9,999.9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
267 | - 'us_2' => array('label' => '9,999.99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
268 | - 'be_0' => array('label' => '9.999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
269 | - 'be_1' => array('label' => '9.999,9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
270 | - 'be_2' => array('label' => '9.999,99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
271 | - 'fr_0' => array('label' => '9 999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
272 | - 'fr_1' => array('label' => '9 999, 9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
273 | - 'fr_2' => array('label' => '9 999, 99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
264 | + 'default' => array('label' => '9999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
265 | + 'us_0' => array('label' => '9,999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
266 | + 'us_1' => array('label' => '9,999.9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
267 | + 'us_2' => array('label' => '9,999.99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
268 | + 'be_0' => array('label' => '9.999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
269 | + 'be_1' => array('label' => '9.999,9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
270 | + 'be_2' => array('label' => '9.999,99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
271 | + 'fr_0' => array('label' => '9 999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
272 | + 'fr_1' => array('label' => '9 999, 9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
273 | + 'fr_2' => array('label' => '9 999, 99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
274 | 274 | 'unformatted' => array('label' => t('unformatted'), 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
275 | 275 | ); |
276 | 276 | } |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $prefix = (count($prefixes) > 1) ? format_plural($value, $prefixes[0], $prefixes[1]) : $prefixes[0]; |
338 | 338 | $suffix = (count($suffixes) > 1) ? format_plural($value, $suffixes[0], $suffixes[1]) : $suffixes[0]; |
339 | 339 | |
340 | - return $prefix . $output . $suffix; |
|
340 | + return $prefix.$output.$suffix; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | $start = $value; |
513 | 513 | $value = preg_replace('@[^-0-9\.]@', '', $value); |
514 | 514 | if ($start != $value) { |
515 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
515 | + $error_field = implode('][', $element['#parents']).']['.$field_key; |
|
516 | 516 | form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
517 | 517 | } |
518 | 518 | else { |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | $start = $value; |
536 | 536 | $value = preg_replace('@[^-0-9]@', '', $value); |
537 | 537 | if ($start != $value) { |
538 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
538 | + $error_field = implode('][', $element['#parents']).']['.$field_key; |
|
539 | 539 | form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
540 | 540 | } |
541 | 541 | else { |
@@ -557,9 +557,9 @@ discard block |
||
557 | 557 | if (($element[$field_key]['#required'] || !empty($value))) { |
558 | 558 | $decimal = $element['#decimal'] ? $element['#decimal'] : '.'; |
559 | 559 | $start = $value; |
560 | - $value = preg_replace('@[^-0-9\\'. $decimal .']@', '', $value); |
|
560 | + $value = preg_replace('@[^-0-9\\'.$decimal.']@', '', $value); |
|
561 | 561 | if ($start != $value) { |
562 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
562 | + $error_field = implode('][', $element['#parents']).']['.$field_key; |
|
563 | 563 | form_set_error($error_field, t('Only numbers and the decimal character (%decimal) are allowed in %field.', array('%decimal' => $element['#decimal'], '%field' => t($field['widget']['label'])))); |
564 | 564 | } |
565 | 565 | else { |
@@ -133,8 +133,7 @@ discard block |
||
133 | 133 | '#rows' => 6, |
134 | 134 | '#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.'), |
135 | 135 | ); |
136 | - } |
|
137 | - else { |
|
136 | + } else { |
|
138 | 137 | $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
139 | 138 | '#type' => 'item', |
140 | 139 | '#title' => t('Code'), |
@@ -514,8 +513,7 @@ discard block |
||
514 | 513 | if ($start != $value) { |
515 | 514 | $error_field = implode('][', $element['#parents']) .']['. $field_key; |
516 | 515 | form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
517 | - } |
|
518 | - else { |
|
516 | + } else { |
|
519 | 517 | form_set_value($element[$field_key], $value, $form_state); |
520 | 518 | } |
521 | 519 | } |
@@ -537,8 +535,7 @@ discard block |
||
537 | 535 | if ($start != $value) { |
538 | 536 | $error_field = implode('][', $element['#parents']) .']['. $field_key; |
539 | 537 | form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
540 | - } |
|
541 | - else { |
|
538 | + } else { |
|
542 | 539 | form_set_value($element[$field_key], $value, $form_state); |
543 | 540 | } |
544 | 541 | } |
@@ -561,8 +558,7 @@ discard block |
||
561 | 558 | if ($start != $value) { |
562 | 559 | $error_field = implode('][', $element['#parents']) .']['. $field_key; |
563 | 560 | form_set_error($error_field, t('Only numbers and the decimal character (%decimal) are allowed in %field.', array('%decimal' => $element['#decimal'], '%field' => t($field['widget']['label'])))); |
564 | - } |
|
565 | - else { |
|
561 | + } else { |
|
566 | 562 | $value = str_replace($element['#decimal'], '.', $value); |
567 | 563 | $value = round($value, $element['#scale']); |
568 | 564 | form_set_value($element[$field_key], $value, $form_state); |
@@ -11,18 +11,18 @@ discard block |
||
11 | 11 | */ |
12 | 12 | function number_theme() { |
13 | 13 | return array( |
14 | - 'number' => array('arguments' => array('element' => NULL)), |
|
15 | - 'number_formatter_default' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
16 | - 'number_formatter_us_0' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
17 | - 'number_formatter_us_1' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
18 | - 'number_formatter_us_2' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
19 | - 'number_formatter_be_0' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
20 | - 'number_formatter_be_1' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
21 | - 'number_formatter_be_2' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
22 | - 'number_formatter_fr_0' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
23 | - 'number_formatter_fr_1' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
24 | - 'number_formatter_fr_2' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
25 | - 'number_formatter_unformatted' => array('arguments' => array('element' => NULL)), |
|
14 | + 'number' => array('arguments' => array('element' => null)), |
|
15 | + 'number_formatter_default' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
16 | + 'number_formatter_us_0' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
17 | + 'number_formatter_us_1' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
18 | + 'number_formatter_us_2' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
19 | + 'number_formatter_be_0' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
20 | + 'number_formatter_be_1' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
21 | + 'number_formatter_be_2' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
22 | + 'number_formatter_fr_0' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
23 | + 'number_formatter_fr_1' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
24 | + 'number_formatter_fr_2' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
25 | + 'number_formatter_unformatted' => array('arguments' => array('element' => null)), |
|
26 | 26 | ); |
27 | 27 | } |
28 | 28 | |
@@ -108,21 +108,21 @@ discard block |
||
108 | 108 | $form['allowed_values_fieldset'] = array( |
109 | 109 | '#type' => 'fieldset', |
110 | 110 | '#title' => t('Allowed values'), |
111 | - '#collapsible' => TRUE, |
|
112 | - '#collapsed' => TRUE, |
|
111 | + '#collapsible' => true, |
|
112 | + '#collapsed' => true, |
|
113 | 113 | ); |
114 | 114 | $form['allowed_values_fieldset']['allowed_values'] = array( |
115 | 115 | '#type' => 'textarea', |
116 | 116 | '#title' => t('Allowed values list'), |
117 | 117 | '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
118 | - '#required' => FALSE, |
|
118 | + '#required' => false, |
|
119 | 119 | '#rows' => 10, |
120 | 120 | '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
121 | 121 | ); |
122 | 122 | $form['allowed_values_fieldset']['advanced_options'] = array( |
123 | 123 | '#type' => 'fieldset', |
124 | 124 | '#title' => t('PHP code'), |
125 | - '#collapsible' => TRUE, |
|
125 | + '#collapsible' => true, |
|
126 | 126 | '#collapsed' => empty($field['allowed_values_php']), |
127 | 127 | ); |
128 | 128 | if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
@@ -154,19 +154,19 @@ discard block |
||
154 | 154 | case 'database columns': |
155 | 155 | if ($field['type'] == 'number_integer') { |
156 | 156 | return array( |
157 | - 'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE), |
|
157 | + 'value' => array('type' => 'int', 'not null' => false, 'sortable' => true), |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | if ($field['type'] == 'number_float') { |
161 | 161 | return array( |
162 | - 'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE), |
|
162 | + 'value' => array('type' => 'float', 'not null' => false, 'sortable' => true), |
|
163 | 163 | ); |
164 | 164 | } |
165 | 165 | if ($field['type'] == 'number_decimal') { |
166 | 166 | $precision = isset($field['precision']) ? $field['precision'] : 10; |
167 | 167 | $scale = isset($field['scale']) ? $field['scale'] : 2; |
168 | 168 | return array( |
169 | - 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE), |
|
169 | + 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => false, 'sortable' => true), |
|
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | $copy = $data[$table_alias][$field['field_name'] .'_value']; |
182 | 182 | $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
183 | 183 | $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
184 | - $copy['filter']['numeric'] = TRUE; |
|
184 | + $copy['filter']['numeric'] = true; |
|
185 | 185 | unset($copy['field'], $copy['argument'], $copy['sort']); |
186 | 186 | $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
187 | 187 | // Argument: swap the handler to the 'many to one' operator |
188 | 188 | $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
189 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE; |
|
189 | + $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = true; |
|
190 | 190 | return $data; |
191 | 191 | } |
192 | 192 | break; |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | if (count($allowed_values)) { |
229 | 229 | // We cannot use array_key_exists() because allowed values are |
230 | 230 | // stored as strings, and we need to compare numeric equality. |
231 | - $valid = FALSE; |
|
231 | + $valid = false; |
|
232 | 232 | foreach ($allowed_values as $kay => $value) { |
233 | 233 | if ((float) $item['value'] == (float) $kay) { |
234 | - $valid = TRUE; |
|
234 | + $valid = true; |
|
235 | 235 | break; |
236 | 236 | } |
237 | 237 | } |
@@ -251,9 +251,9 @@ discard block |
||
251 | 251 | */ |
252 | 252 | function number_content_is_empty($item, $field) { |
253 | 253 | if (empty($item['value']) && (string)$item['value'] !== '0') { |
254 | - return TRUE; |
|
254 | + return true; |
|
255 | 255 | } |
256 | - return FALSE; |
|
256 | + return false; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | function number_elements() { |
380 | 380 | return array( |
381 | 381 | 'number' => array( |
382 | - '#input' => TRUE, |
|
382 | + '#input' => true, |
|
383 | 383 | '#columns' => array('value'), '#delta' => 0, |
384 | 384 | '#process' => array('number_process'), |
385 | 385 | ), |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | function number_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
421 | 421 | $element = array( |
422 | 422 | '#type' => $field['widget']['type'], |
423 | - '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL, |
|
423 | + '#default_value' => isset($items[$delta]) ? $items[$delta] : null, |
|
424 | 424 | ); |
425 | 425 | return $element; |
426 | 426 | } |