@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | * chosen widget. |
10 | 10 | */ |
11 | 11 | function content_form(&$form, &$form_state) { |
12 | - $type = content_types($form['type']['#value']); |
|
13 | - foreach ($type['fields'] as $field_name => $field) { |
|
12 | + $type = content_types($form['type']['#value']); |
|
13 | + foreach ($type['fields'] as $field_name => $field) { |
|
14 | 14 | $form['#field_info'][$field['field_name']] = $field; |
15 | 15 | $form += (array) content_field_form($form, $form_state, $field); |
16 | - } |
|
17 | - return $form; |
|
16 | + } |
|
17 | + return $form; |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -36,18 +36,18 @@ discard block |
||
36 | 36 | * function will return the entire $field form element. |
37 | 37 | */ |
38 | 38 | function content_field_form(&$form, &$form_state, $field, $get_delta = NULL) { |
39 | - $form['#cache'] = FALSE; |
|
40 | - $node = $form['#node']; |
|
41 | - $addition = array(); |
|
42 | - $form_element = array(); |
|
43 | - $field_name = $field['field_name']; |
|
44 | - |
|
45 | - $items = array(); |
|
46 | - |
|
47 | - // TODO: is the "if (function_exists($function)) {" needed ? |
|
48 | - // defining the $function here makes it unclear where it is actually called |
|
49 | - $function = $field['widget']['module'] .'_widget'; |
|
50 | - if (function_exists($function)) { |
|
39 | + $form['#cache'] = FALSE; |
|
40 | + $node = $form['#node']; |
|
41 | + $addition = array(); |
|
42 | + $form_element = array(); |
|
43 | + $field_name = $field['field_name']; |
|
44 | + |
|
45 | + $items = array(); |
|
46 | + |
|
47 | + // TODO: is the "if (function_exists($function)) {" needed ? |
|
48 | + // defining the $function here makes it unclear where it is actually called |
|
49 | + $function = $field['widget']['module'] .'_widget'; |
|
50 | + if (function_exists($function)) { |
|
51 | 51 | // Prepare the values to be filled in the widget. |
52 | 52 | // We look in the following places: |
53 | 53 | // - Form submitted values |
@@ -55,88 +55,88 @@ discard block |
||
55 | 55 | // creating a new node translation) |
56 | 56 | // - Default values set for the field (when creating a new node). |
57 | 57 | if (!empty($form_state['values'][$field['field_name']])) { |
58 | - $items = $form_state['values'][$field['field_name']]; |
|
59 | - // If there was an AHAH add more button in this field, don't save it. |
|
60 | - unset($items[$field['field_name'] .'_add_more']); |
|
58 | + $items = $form_state['values'][$field['field_name']]; |
|
59 | + // If there was an AHAH add more button in this field, don't save it. |
|
60 | + unset($items[$field['field_name'] .'_add_more']); |
|
61 | 61 | } |
62 | 62 | elseif (!empty($node->$field['field_name'])) { |
63 | - $items = $node->$field['field_name']; |
|
63 | + $items = $node->$field['field_name']; |
|
64 | 64 | } |
65 | 65 | elseif (empty($node->nid)) { |
66 | - if (content_callback('widget', 'default value', $field) != CONTENT_CALLBACK_NONE) { |
|
66 | + if (content_callback('widget', 'default value', $field) != CONTENT_CALLBACK_NONE) { |
|
67 | 67 | // If a module wants to insert custom default values here, |
68 | 68 | // it should provide a hook_default_value() function to call, |
69 | 69 | // otherwise the content module's content_default_value() function |
70 | 70 | // will be used. |
71 | 71 | $callback = content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_CUSTOM ? $field['widget']['module'] .'_default_value' : 'content_default_value'; |
72 | 72 | if (function_exists($callback)) { |
73 | - $items = $callback($form, $form_state, $field, 0); |
|
73 | + $items = $callback($form, $form_state, $field, 0); |
|
74 | + } |
|
74 | 75 | } |
75 | - } |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // See if access to this form element is restricted, |
79 | 79 | // if so, skip widget processing and just set the value. |
80 | 80 | $access = content_access('edit', $field, NULL, $node); |
81 | 81 | if (!$access) { |
82 | - $addition[$field_name] = array( |
|
82 | + $addition[$field_name] = array( |
|
83 | 83 | '#access' => $access, |
84 | 84 | '#type' => 'value', |
85 | 85 | '#value' => $items, |
86 | - ); |
|
87 | - return $addition; |
|
86 | + ); |
|
87 | + return $addition; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | // If content module handles multiple values for this form element, |
91 | 91 | // and not selecting an individual $delta, process the multiple value form. |
92 | 92 | if (!isset($get_delta) && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
93 | - $form_element = content_multiple_value_form($form, $form_state, $field, $items); |
|
93 | + $form_element = content_multiple_value_form($form, $form_state, $field, $items); |
|
94 | 94 | } |
95 | 95 | // If the widget is handling multiple values (e.g optionwidgets), |
96 | 96 | // or selecting an individual element, just get a single form |
97 | 97 | // element and make it the $delta value. |
98 | 98 | else { |
99 | - $delta = isset($get_delta) ? $get_delta : 0; |
|
100 | - if ($element = $function($form, $form_state, $field, $items, $delta)) { |
|
99 | + $delta = isset($get_delta) ? $get_delta : 0; |
|
100 | + if ($element = $function($form, $form_state, $field, $items, $delta)) { |
|
101 | 101 | $title = check_plain(t($field['widget']['label'])); |
102 | 102 | $description = content_filter_xss(t($field['widget']['description'])); |
103 | 103 | $defaults = array( |
104 | - '#required' => $get_delta > 0 ? FALSE : $field['required'], |
|
105 | - '#columns' => array_keys($field['columns']), |
|
106 | - '#title' => $title, |
|
107 | - '#description' => $description, |
|
108 | - '#delta' => $delta, |
|
109 | - '#field_name' => $field['field_name'], |
|
110 | - '#type_name' => $field['type_name'], |
|
104 | + '#required' => $get_delta > 0 ? FALSE : $field['required'], |
|
105 | + '#columns' => array_keys($field['columns']), |
|
106 | + '#title' => $title, |
|
107 | + '#description' => $description, |
|
108 | + '#delta' => $delta, |
|
109 | + '#field_name' => $field['field_name'], |
|
110 | + '#type_name' => $field['type_name'], |
|
111 | 111 | ); |
112 | 112 | // If we're processing a specific delta value for a field where the |
113 | 113 | // content module handles multiples, set the delta in the result. |
114 | 114 | // For fields that handle their own processing, we can't make assumptions |
115 | 115 | // about how the field is structured, just merge in the returned value. |
116 | 116 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
117 | - $form_element[$delta] = array_merge($element, $defaults); |
|
117 | + $form_element[$delta] = array_merge($element, $defaults); |
|
118 | 118 | } |
119 | 119 | else { |
120 | - $form_element = array_merge($element, $defaults); |
|
120 | + $form_element = array_merge($element, $defaults); |
|
121 | + } |
|
121 | 122 | } |
122 | - } |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // Field name is needed at top level as well as the individual elements |
126 | 126 | // so the multiple values or other field level theme or processing can find it. |
127 | 127 | if ($form_element) { |
128 | - $defaults = array( |
|
128 | + $defaults = array( |
|
129 | 129 | '#field_name' => $field['field_name'], |
130 | 130 | '#tree' => TRUE, |
131 | 131 | '#weight' => $field['widget']['weight'], |
132 | 132 | '#access' => $access, |
133 | 133 | // TODO: what's the need for #count ? does not seem to be used anywhere ? |
134 | 134 | '#count' => count($form_element), |
135 | - ); |
|
136 | - $addition[$field['field_name']] = array_merge($form_element, $defaults); |
|
135 | + ); |
|
136 | + $addition[$field['field_name']] = array_merge($form_element, $defaults); |
|
137 | + } |
|
137 | 138 | } |
138 | - } |
|
139 | - return $addition; |
|
139 | + return $addition; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -148,42 +148,42 @@ discard block |
||
148 | 148 | * - drag-n-drop value reordering |
149 | 149 | */ |
150 | 150 | function content_multiple_value_form(&$form, &$form_state, $field, $items) { |
151 | - $field_name = $field['field_name']; |
|
151 | + $field_name = $field['field_name']; |
|
152 | 152 | |
153 | - switch ($field['multiple']) { |
|
153 | + switch ($field['multiple']) { |
|
154 | 154 | case 0: |
155 | 155 | $max = 0; |
156 | - break; |
|
156 | + break; |
|
157 | 157 | case 1: |
158 | 158 | $filled_items = content_set_empty($field, $items); |
159 | - $current_item_count = isset($form_state['item_count'][$field_name]) |
|
159 | + $current_item_count = isset($form_state['item_count'][$field_name]) |
|
160 | 160 | ? $form_state['item_count'][$field_name] |
161 | 161 | : count($items); |
162 | - // We always want at least one empty icon for the user to fill in. |
|
163 | - $max = ($current_item_count > count($filled_items)) |
|
162 | + // We always want at least one empty icon for the user to fill in. |
|
163 | + $max = ($current_item_count > count($filled_items)) |
|
164 | 164 | ? $current_item_count - 1 |
165 | 165 | : $current_item_count; |
166 | 166 | |
167 | - break; |
|
167 | + break; |
|
168 | 168 | default: |
169 | 169 | $max = $field['multiple'] - 1; |
170 | - break; |
|
171 | - } |
|
170 | + break; |
|
171 | + } |
|
172 | 172 | |
173 | - $title = check_plain(t($field['widget']['label'])); |
|
174 | - $description = content_filter_xss(t($field['widget']['description'])); |
|
173 | + $title = check_plain(t($field['widget']['label'])); |
|
174 | + $description = content_filter_xss(t($field['widget']['description'])); |
|
175 | 175 | |
176 | - $form_element = array( |
|
176 | + $form_element = array( |
|
177 | 177 | '#theme' => 'content_multiple_values', |
178 | 178 | '#title' => $title, |
179 | 179 | '#required' => $field['required'], |
180 | 180 | '#description' => $description, |
181 | - ); |
|
182 | - $function = $field['widget']['module'] .'_widget'; |
|
181 | + ); |
|
182 | + $function = $field['widget']['module'] .'_widget'; |
|
183 | 183 | |
184 | - for ($delta = 0; $delta <= $max; $delta++) { |
|
184 | + for ($delta = 0; $delta <= $max; $delta++) { |
|
185 | 185 | if ($element = $function($form, $form_state, $field, $items, $delta)) { |
186 | - $defaults = array( |
|
186 | + $defaults = array( |
|
187 | 187 | '#title' => ($field['multiple'] >= 1) ? '' : $title, |
188 | 188 | '#description' => ($field['multiple'] >= 1) ? '' : $description, |
189 | 189 | '#required' => $delta == 0 && $field['required'], |
@@ -192,51 +192,51 @@ discard block |
||
192 | 192 | '#columns' => array_keys($field['columns']), |
193 | 193 | '#field_name' => $field_name, |
194 | 194 | '#type_name' => $field['type_name'], |
195 | - ); |
|
195 | + ); |
|
196 | 196 | |
197 | - // Add an input field for the delta (drag-n-drop reordering), which will |
|
198 | - // be hidden by tabledrag js behavior. |
|
199 | - if ($field['multiple'] >= 1) { |
|
197 | + // Add an input field for the delta (drag-n-drop reordering), which will |
|
198 | + // be hidden by tabledrag js behavior. |
|
199 | + if ($field['multiple'] >= 1) { |
|
200 | 200 | // We name the element '_weight' to avoid clashing with column names |
201 | 201 | // defined by field modules. |
202 | 202 | $element['_weight'] = array( |
203 | - '#type' => 'weight', |
|
204 | - '#delta' => $max, // this 'delta' is the 'weight' element's property |
|
205 | - '#default_value' => isset($items[$delta]['_weight']) ? $items[$delta]['_weight'] : $delta, |
|
206 | - '#weight' => 100, |
|
203 | + '#type' => 'weight', |
|
204 | + '#delta' => $max, // this 'delta' is the 'weight' element's property |
|
205 | + '#default_value' => isset($items[$delta]['_weight']) ? $items[$delta]['_weight'] : $delta, |
|
206 | + '#weight' => 100, |
|
207 | 207 | ); |
208 | - } |
|
208 | + } |
|
209 | 209 | |
210 | - $form_element[$delta] = array_merge($element, $defaults); |
|
210 | + $form_element[$delta] = array_merge($element, $defaults); |
|
211 | + } |
|
211 | 212 | } |
212 | - } |
|
213 | 213 | |
214 | - // Add AHAH add more button, if not working with a programmed form. |
|
215 | - if ($field['multiple'] == 1 && empty($form['#programmed'])) { |
|
214 | + // Add AHAH add more button, if not working with a programmed form. |
|
215 | + if ($field['multiple'] == 1 && empty($form['#programmed'])) { |
|
216 | 216 | // Make sure the form is cached so ahah can work. |
217 | 217 | $form['#cache'] = TRUE; |
218 | 218 | $content_type = content_types($field['type_name']); |
219 | 219 | $field_name_css = str_replace('_', '-', $field_name); |
220 | 220 | |
221 | 221 | $form_element[$field_name .'_add_more'] = array( |
222 | - '#type' => 'submit', |
|
223 | - '#name' => $field_name .'_add_more', |
|
224 | - '#value' => t('Add another item'), |
|
225 | - '#weight' => $field['widget']['weight'] + $max + 1, |
|
226 | - // Submit callback for disabled JavaScript. drupal_get_form() might get |
|
227 | - // the form from the cache, so we can't rely on content_form_alter() |
|
228 | - // including this file. Therefore, call a proxy function to do this. |
|
229 | - '#submit' => array('content_add_more_submit_proxy'), |
|
230 | - '#ahah' => array( |
|
222 | + '#type' => 'submit', |
|
223 | + '#name' => $field_name .'_add_more', |
|
224 | + '#value' => t('Add another item'), |
|
225 | + '#weight' => $field['widget']['weight'] + $max + 1, |
|
226 | + // Submit callback for disabled JavaScript. drupal_get_form() might get |
|
227 | + // the form from the cache, so we can't rely on content_form_alter() |
|
228 | + // including this file. Therefore, call a proxy function to do this. |
|
229 | + '#submit' => array('content_add_more_submit_proxy'), |
|
230 | + '#ahah' => array( |
|
231 | 231 | 'path' => 'content/js_add_more/'. $content_type['url_str'] .'/'. $field_name, |
232 | 232 | 'wrapper' => $field_name_css .'-items', |
233 | 233 | 'method' => 'replace', |
234 | 234 | 'effect' => 'fade', |
235 | - ), |
|
236 | - // When JS is disabled, the content_add_more_submit handler will find |
|
237 | - // the relevant field using these entries. |
|
238 | - '#field_name' => $field_name, |
|
239 | - '#type_name' => $field['type_name'], |
|
235 | + ), |
|
236 | + // When JS is disabled, the content_add_more_submit handler will find |
|
237 | + // the relevant field using these entries. |
|
238 | + '#field_name' => $field_name, |
|
239 | + '#type_name' => $field['type_name'], |
|
240 | 240 | ); |
241 | 241 | |
242 | 242 | // Add wrappers for the fields and 'more' button. |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | $form_element['#suffix'] = '</div>'; |
245 | 245 | $form_element[$field_name .'_add_more']['#prefix'] = '<div class="content-add-more clear-block">'; |
246 | 246 | $form_element[$field_name .'_add_more']['#suffix'] = '</div>'; |
247 | - } |
|
248 | - return $form_element; |
|
247 | + } |
|
248 | + return $form_element; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -254,127 +254,127 @@ discard block |
||
254 | 254 | * entire form is rebuilt during the page reload. |
255 | 255 | */ |
256 | 256 | function content_add_more_submit($form, &$form_state) { |
257 | - // Set the form to rebuild and run submit handlers. |
|
258 | - node_form_submit_build_node($form, $form_state); |
|
259 | - $field_name = $form_state['clicked_button']['#field_name']; |
|
260 | - $type_name = $form_state['clicked_button']['#type_name']; |
|
257 | + // Set the form to rebuild and run submit handlers. |
|
258 | + node_form_submit_build_node($form, $form_state); |
|
259 | + $field_name = $form_state['clicked_button']['#field_name']; |
|
260 | + $type_name = $form_state['clicked_button']['#type_name']; |
|
261 | 261 | |
262 | - // Make the changes we want to the form state. |
|
263 | - if ($form_state['values'][$field_name][$field_name .'_add_more']) { |
|
262 | + // Make the changes we want to the form state. |
|
263 | + if ($form_state['values'][$field_name][$field_name .'_add_more']) { |
|
264 | 264 | $form_state['item_count'][$field_name] = count($form_state['values'][$field_name]); |
265 | - } |
|
265 | + } |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
269 | 269 | * Menu callback for AHAH addition of new empty widgets. |
270 | 270 | */ |
271 | 271 | function content_add_more_js($type_name_url, $field_name) { |
272 | - $type = content_types($type_name_url); |
|
273 | - $field = content_fields($field_name, $type['type']); |
|
272 | + $type = content_types($type_name_url); |
|
273 | + $field = content_fields($field_name, $type['type']); |
|
274 | 274 | |
275 | - if (($field['multiple'] != 1) || empty($_POST['form_build_id'])) { |
|
275 | + if (($field['multiple'] != 1) || empty($_POST['form_build_id'])) { |
|
276 | 276 | // Invalid request. |
277 | 277 | drupal_json(array('data' => '')); |
278 | 278 | exit; |
279 | - } |
|
279 | + } |
|
280 | 280 | |
281 | - // Retrieve the cached form. |
|
282 | - $form_state = array('submitted' => FALSE); |
|
283 | - $form_build_id = $_POST['form_build_id']; |
|
284 | - $form = form_get_cache($form_build_id, $form_state); |
|
285 | - if (!$form) { |
|
281 | + // Retrieve the cached form. |
|
282 | + $form_state = array('submitted' => FALSE); |
|
283 | + $form_build_id = $_POST['form_build_id']; |
|
284 | + $form = form_get_cache($form_build_id, $form_state); |
|
285 | + if (!$form) { |
|
286 | 286 | // Invalid form_build_id. |
287 | 287 | drupal_json(array('data' => '')); |
288 | 288 | exit; |
289 | - } |
|
290 | - |
|
291 | - // We don't simply return a new empty widget to append to existing ones, because |
|
292 | - // - ahah.js won't simply let us add a new row to a table |
|
293 | - // - attaching the 'draggable' behavior won't be easy |
|
294 | - // So we resort to rebuilding the whole table of widgets including the existing ones, |
|
295 | - // which makes us jump through a few hoops. |
|
296 | - |
|
297 | - // The form that we get from the cache is unbuilt. We need to build it so that |
|
298 | - // _value callbacks can be executed and $form_state['values'] populated. |
|
299 | - // We only want to affect $form_state['values'], not the $form itself |
|
300 | - // (built forms aren't supposed to enter the cache) nor the rest of $form_data, |
|
301 | - // so we use copies of $form and $form_data. |
|
302 | - $form_copy = $form; |
|
303 | - $form_state_copy = $form_state; |
|
304 | - $form_copy['#post'] = array(); |
|
305 | - form_builder($_POST['form_id'], $form_copy, $form_state_copy); |
|
306 | - // Just grab the data we need. |
|
307 | - $form_state['values'] = $form_state_copy['values']; |
|
308 | - // Reset cached ids, so that they don't affect the actual form we output. |
|
309 | - form_clean_id(NULL, TRUE); |
|
310 | - |
|
311 | - // Sort the $form_state['values'] we just built *and* the incoming $_POST data |
|
312 | - // according to d-n-d reordering. |
|
313 | - unset($form_state['values'][$field_name][$field['field_name'] .'_add_more']); |
|
314 | - foreach ($_POST[$field_name] as $delta => $item) { |
|
289 | + } |
|
290 | + |
|
291 | + // We don't simply return a new empty widget to append to existing ones, because |
|
292 | + // - ahah.js won't simply let us add a new row to a table |
|
293 | + // - attaching the 'draggable' behavior won't be easy |
|
294 | + // So we resort to rebuilding the whole table of widgets including the existing ones, |
|
295 | + // which makes us jump through a few hoops. |
|
296 | + |
|
297 | + // The form that we get from the cache is unbuilt. We need to build it so that |
|
298 | + // _value callbacks can be executed and $form_state['values'] populated. |
|
299 | + // We only want to affect $form_state['values'], not the $form itself |
|
300 | + // (built forms aren't supposed to enter the cache) nor the rest of $form_data, |
|
301 | + // so we use copies of $form and $form_data. |
|
302 | + $form_copy = $form; |
|
303 | + $form_state_copy = $form_state; |
|
304 | + $form_copy['#post'] = array(); |
|
305 | + form_builder($_POST['form_id'], $form_copy, $form_state_copy); |
|
306 | + // Just grab the data we need. |
|
307 | + $form_state['values'] = $form_state_copy['values']; |
|
308 | + // Reset cached ids, so that they don't affect the actual form we output. |
|
309 | + form_clean_id(NULL, TRUE); |
|
310 | + |
|
311 | + // Sort the $form_state['values'] we just built *and* the incoming $_POST data |
|
312 | + // according to d-n-d reordering. |
|
313 | + unset($form_state['values'][$field_name][$field['field_name'] .'_add_more']); |
|
314 | + foreach ($_POST[$field_name] as $delta => $item) { |
|
315 | 315 | $form_state['values'][$field_name][$delta]['_weight'] = $item['_weight']; |
316 | - } |
|
317 | - $form_state['values'][$field_name] = _content_sort_items($field, $form_state['values'][$field_name]); |
|
318 | - $_POST[$field_name] = _content_sort_items($field, $_POST[$field_name]); |
|
319 | - |
|
320 | - // Build our new form element for the whole field, asking for one more element. |
|
321 | - $form_state['item_count'] = array($field_name => count($_POST[$field_name]) + 1); |
|
322 | - $form_element = content_field_form($form, $form_state, $field); |
|
323 | - // Let other modules alter it. |
|
324 | - // We pass an empty array as hook_form_alter's usual 'form_state' parameter, |
|
325 | - // instead of $form_state (for reasons we may never remember). |
|
326 | - // However, this argument is still expected to be passed by-reference |
|
327 | - // (and PHP5.3 will throw an error if it isn't.) This leads to: |
|
328 | - $data = &$form_element; |
|
329 | - $empty_form_state = array(); |
|
330 | - $data['__drupal_alter_by_ref'] = array(&$empty_form_state); |
|
331 | - drupal_alter('form', $data, 'content_add_more_js'); |
|
332 | - |
|
333 | - // Add the new element at the right place in the (original, unbuilt) form. |
|
334 | - if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type['type'], $field_name))) { |
|
316 | + } |
|
317 | + $form_state['values'][$field_name] = _content_sort_items($field, $form_state['values'][$field_name]); |
|
318 | + $_POST[$field_name] = _content_sort_items($field, $_POST[$field_name]); |
|
319 | + |
|
320 | + // Build our new form element for the whole field, asking for one more element. |
|
321 | + $form_state['item_count'] = array($field_name => count($_POST[$field_name]) + 1); |
|
322 | + $form_element = content_field_form($form, $form_state, $field); |
|
323 | + // Let other modules alter it. |
|
324 | + // We pass an empty array as hook_form_alter's usual 'form_state' parameter, |
|
325 | + // instead of $form_state (for reasons we may never remember). |
|
326 | + // However, this argument is still expected to be passed by-reference |
|
327 | + // (and PHP5.3 will throw an error if it isn't.) This leads to: |
|
328 | + $data = &$form_element; |
|
329 | + $empty_form_state = array(); |
|
330 | + $data['__drupal_alter_by_ref'] = array(&$empty_form_state); |
|
331 | + drupal_alter('form', $data, 'content_add_more_js'); |
|
332 | + |
|
333 | + // Add the new element at the right place in the (original, unbuilt) form. |
|
334 | + if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type['type'], $field_name))) { |
|
335 | 335 | $form[$group_name][$field_name] = $form_element[$field_name]; |
336 | - } |
|
337 | - else { |
|
336 | + } |
|
337 | + else { |
|
338 | 338 | $form[$field_name] = $form_element[$field_name]; |
339 | - } |
|
340 | - |
|
341 | - // Save the new definition of the form. |
|
342 | - $form_state['values'] = array(); |
|
343 | - form_set_cache($form_build_id, $form, $form_state); |
|
344 | - |
|
345 | - // Build the new form against the incoming $_POST values so that we can |
|
346 | - // render the new element. |
|
347 | - $delta = max(array_keys($_POST[$field_name])) + 1; |
|
348 | - $_POST[$field_name][$delta]['_weight'] = $delta; |
|
349 | - $form_state = array('submitted' => FALSE); |
|
350 | - $form += array( |
|
339 | + } |
|
340 | + |
|
341 | + // Save the new definition of the form. |
|
342 | + $form_state['values'] = array(); |
|
343 | + form_set_cache($form_build_id, $form, $form_state); |
|
344 | + |
|
345 | + // Build the new form against the incoming $_POST values so that we can |
|
346 | + // render the new element. |
|
347 | + $delta = max(array_keys($_POST[$field_name])) + 1; |
|
348 | + $_POST[$field_name][$delta]['_weight'] = $delta; |
|
349 | + $form_state = array('submitted' => FALSE); |
|
350 | + $form += array( |
|
351 | 351 | '#post' => $_POST, |
352 | 352 | '#programmed' => FALSE, |
353 | - ); |
|
354 | - $form = form_builder($_POST['form_id'], $form, $form_state); |
|
355 | - |
|
356 | - // Render the new output. |
|
357 | - $field_form = (!empty($group_name)) ? $form[$group_name][$field_name] : $form[$field_name]; |
|
358 | - // We add a div around the new content to receive the ahah effect. |
|
359 | - $field_form[$delta]['#prefix'] = '<div class="ahah-new-content">'. (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : ''); |
|
360 | - $field_form[$delta]['#suffix'] = (isset($field_form[$delta]['#suffix']) ? $field_form[$delta]['#suffix'] : '') .'</div>'; |
|
361 | - // Prevent duplicate wrapper. |
|
362 | - unset($field_form['#prefix'], $field_form['#suffix']); |
|
363 | - |
|
364 | - // If a newly inserted widget contains AHAH behaviors, they normally won't |
|
365 | - // work because AHAH doesn't know about those - it just attaches to the exact |
|
366 | - // form elements that were initially specified in the Drupal.settings object. |
|
367 | - // The new ones didn't exist then, so we need to update Drupal.settings |
|
368 | - // by ourselves in order to let AHAH know about those new form elements. |
|
369 | - $javascript = drupal_add_js(NULL, NULL); |
|
370 | - $output_js = isset($javascript['setting']) ? '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');</script>' : ''; |
|
371 | - |
|
372 | - $output = theme('status_messages') . drupal_render($field_form) . $output_js; |
|
373 | - |
|
374 | - // Using drupal_json() breaks filefield's file upload, because the jQuery |
|
375 | - // Form plugin handles file uploads in a way that is not compatible with |
|
376 | - // 'text/javascript' response type. |
|
377 | - $GLOBALS['devel_shutdown'] = FALSE; |
|
378 | - print drupal_to_js(array('status' => TRUE, 'data' => $output)); |
|
379 | - exit; |
|
353 | + ); |
|
354 | + $form = form_builder($_POST['form_id'], $form, $form_state); |
|
355 | + |
|
356 | + // Render the new output. |
|
357 | + $field_form = (!empty($group_name)) ? $form[$group_name][$field_name] : $form[$field_name]; |
|
358 | + // We add a div around the new content to receive the ahah effect. |
|
359 | + $field_form[$delta]['#prefix'] = '<div class="ahah-new-content">'. (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : ''); |
|
360 | + $field_form[$delta]['#suffix'] = (isset($field_form[$delta]['#suffix']) ? $field_form[$delta]['#suffix'] : '') .'</div>'; |
|
361 | + // Prevent duplicate wrapper. |
|
362 | + unset($field_form['#prefix'], $field_form['#suffix']); |
|
363 | + |
|
364 | + // If a newly inserted widget contains AHAH behaviors, they normally won't |
|
365 | + // work because AHAH doesn't know about those - it just attaches to the exact |
|
366 | + // form elements that were initially specified in the Drupal.settings object. |
|
367 | + // The new ones didn't exist then, so we need to update Drupal.settings |
|
368 | + // by ourselves in order to let AHAH know about those new form elements. |
|
369 | + $javascript = drupal_add_js(NULL, NULL); |
|
370 | + $output_js = isset($javascript['setting']) ? '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');</script>' : ''; |
|
371 | + |
|
372 | + $output = theme('status_messages') . drupal_render($field_form) . $output_js; |
|
373 | + |
|
374 | + // Using drupal_json() breaks filefield's file upload, because the jQuery |
|
375 | + // Form plugin handles file uploads in a way that is not compatible with |
|
376 | + // 'text/javascript' response type. |
|
377 | + $GLOBALS['devel_shutdown'] = FALSE; |
|
378 | + print drupal_to_js(array('status' => TRUE, 'data' => $output)); |
|
379 | + exit; |
|
380 | 380 | } |
@@ -19,48 +19,48 @@ discard block |
||
19 | 19 | * information in each of its CCK fields. |
20 | 20 | **/ |
21 | 21 | function content_generate_fields(&$node, $field) { |
22 | - $type_name = $node->type; |
|
23 | - $type = content_types($type_name); |
|
24 | - $field_types = _content_field_types(); |
|
22 | + $type_name = $node->type; |
|
23 | + $type = content_types($type_name); |
|
24 | + $field_types = _content_field_types(); |
|
25 | 25 | |
26 | - if (!empty($type['fields'])) { |
|
26 | + if (!empty($type['fields'])) { |
|
27 | 27 | foreach ($type['fields'] as $field) { |
28 | - $node_field = array(); |
|
29 | - // If module handles own multiples, then only call its hook once. |
|
30 | - if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
|
28 | + $node_field = array(); |
|
29 | + // If module handles own multiples, then only call its hook once. |
|
30 | + if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
|
31 | 31 | $max = 0; |
32 | - } |
|
33 | - else { |
|
32 | + } |
|
33 | + else { |
|
34 | 34 | switch ($field['multiple']) { |
35 | - case 0: |
|
35 | + case 0: |
|
36 | 36 | $max = 0; |
37 | 37 | break; |
38 | - case 1: |
|
38 | + case 1: |
|
39 | 39 | $max = rand(0, 3); //just an arbitrary number for 'unlimited' |
40 | 40 | break; |
41 | - default: |
|
41 | + default: |
|
42 | 42 | $max = $field['multiple']; |
43 | 43 | break; |
44 | 44 | } |
45 | - } |
|
46 | - for ($i = 0; $i <= $max; $i++) { |
|
45 | + } |
|
46 | + for ($i = 0; $i <= $max; $i++) { |
|
47 | 47 | $module = $field_types[$field['type']]['module']; |
48 | 48 | $function = $module .'_content_generate'; |
49 | 49 | if (function_exists($function)) { |
50 | - $result = $function($node, $field); // $items, $teaser, $page |
|
51 | - if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
|
50 | + $result = $function($node, $field); // $items, $teaser, $page |
|
51 | + if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
|
52 | 52 | // Fields that handle their own multiples will add their own deltas. |
53 | 53 | $node_field = $result; |
54 | - } |
|
55 | - else { |
|
54 | + } |
|
55 | + else { |
|
56 | 56 | // When multiples are handled by the content module, add a delta for each result. |
57 | 57 | $node_field[$i] = $result; |
58 | - } |
|
58 | + } |
|
59 | 59 | } |
60 | - } |
|
61 | - $node->{$field['field_name']} = $node_field; |
|
60 | + } |
|
61 | + $node->{$field['field_name']} = $node_field; |
|
62 | + } |
|
62 | 63 | } |
63 | - } |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -70,149 +70,149 @@ discard block |
||
70 | 70 | * a random number of times and compile the results into a node array. |
71 | 71 | */ |
72 | 72 | function content_devel_multiple($function, $node, $field) { |
73 | - $node_field = array(); |
|
74 | - if (function_exists($function)) { |
|
73 | + $node_field = array(); |
|
74 | + if (function_exists($function)) { |
|
75 | 75 | switch ($field['multiple']) { |
76 | - case 0: |
|
76 | + case 0: |
|
77 | 77 | $max = 0; |
78 | 78 | break; |
79 | - case 1: |
|
79 | + case 1: |
|
80 | 80 | $max = rand(0, 3); //just an arbitrary number for 'unlimited' |
81 | 81 | break; |
82 | - default: |
|
82 | + default: |
|
83 | 83 | $max = $field['multiple']; |
84 | 84 | break; |
85 | 85 | } |
86 | 86 | for ($i = 0; $i <= $max; $i++) { |
87 | - $node_field[$i] = $function($node, $field); |
|
87 | + $node_field[$i] = $function($node, $field); |
|
88 | + } |
|
88 | 89 | } |
89 | - } |
|
90 | - return $node_field; |
|
90 | + return $node_field; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | if (module_exists('text')) { |
94 | - function text_content_generate($node, $field) { |
|
94 | + function text_content_generate($node, $field) { |
|
95 | 95 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
96 | - return content_devel_multiple('_text_content_generate', $node, $field); |
|
96 | + return content_devel_multiple('_text_content_generate', $node, $field); |
|
97 | 97 | } |
98 | 98 | else { |
99 | - return _text_content_generate($node, $field); |
|
99 | + return _text_content_generate($node, $field); |
|
100 | + } |
|
100 | 101 | } |
101 | - } |
|
102 | 102 | |
103 | - function _text_content_generate($node, $field) { |
|
103 | + function _text_content_generate($node, $field) { |
|
104 | 104 | $node_field = array(); |
105 | 105 | if ($field['widget']['type'] == 'text_textarea') { |
106 | - $format = $field['text_processing'] ? rand(0, 3) : 0; |
|
107 | - $node_field['value'] = devel_create_content($format); |
|
108 | - $node_field['format'] = $format; |
|
106 | + $format = $field['text_processing'] ? rand(0, 3) : 0; |
|
107 | + $node_field['value'] = devel_create_content($format); |
|
108 | + $node_field['format'] = $format; |
|
109 | 109 | } |
110 | 110 | else { |
111 | - $allowed_values = content_allowed_values($field); |
|
112 | - if (!empty($allowed_values)) { |
|
111 | + $allowed_values = content_allowed_values($field); |
|
112 | + if (!empty($allowed_values)) { |
|
113 | 113 | // Just pick one of the specified allowed values. |
114 | 114 | $node_field['value'] = array_rand($allowed_values); |
115 | - } |
|
116 | - else { |
|
115 | + } |
|
116 | + else { |
|
117 | 117 | // Generate a value that respects max_length. |
118 | 118 | if (empty($field['max_length'])) { |
119 | - $field['max_length'] = 12; |
|
119 | + $field['max_length'] = 12; |
|
120 | 120 | } |
121 | 121 | $node_field['value'] = user_password($field['max_length']); |
122 | - } |
|
122 | + } |
|
123 | 123 | } |
124 | 124 | return $node_field; |
125 | - } |
|
125 | + } |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | if (module_exists('number')) { |
129 | - function number_content_generate($node, $field) { |
|
129 | + function number_content_generate($node, $field) { |
|
130 | 130 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
131 | - return content_devel_multiple('_number_content_generate', $node, $field); |
|
131 | + return content_devel_multiple('_number_content_generate', $node, $field); |
|
132 | 132 | } |
133 | 133 | else { |
134 | - return _number_content_generate($node, $field); |
|
134 | + return _number_content_generate($node, $field); |
|
135 | + } |
|
135 | 136 | } |
136 | - } |
|
137 | 137 | |
138 | - function _number_content_generate($node, $field) { |
|
138 | + function _number_content_generate($node, $field) { |
|
139 | 139 | $node_field = array(); |
140 | 140 | $allowed_values = content_allowed_values($field); |
141 | 141 | if (!empty($allowed_values)) { |
142 | - // Just pick one of the specified allowed values. |
|
143 | - $node_field['value'] = array_rand($allowed_values); |
|
142 | + // Just pick one of the specified allowed values. |
|
143 | + $node_field['value'] = array_rand($allowed_values); |
|
144 | 144 | } |
145 | 145 | else { |
146 | - $min = is_numeric($field['min']) ? $field['min'] : 0; |
|
147 | - switch ($field['type']) { |
|
146 | + $min = is_numeric($field['min']) ? $field['min'] : 0; |
|
147 | + switch ($field['type']) { |
|
148 | 148 | case 'number_integer': |
149 | 149 | $max = is_numeric($field['max']) ? $field['max'] : 10000; |
150 | - $decimal = 0; |
|
151 | - $scale = 0; |
|
152 | - break; |
|
150 | + $decimal = 0; |
|
151 | + $scale = 0; |
|
152 | + break; |
|
153 | 153 | |
154 | 154 | case 'number_decimal': |
155 | 155 | $precision = is_numeric($field['precision']) ? $field['precision'] : 10; |
156 | - $scale = is_numeric($field['scale']) ? $field['scale'] : 2; |
|
157 | - $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
158 | - $decimal = rand(0, (10 * $scale)) / 100; |
|
159 | - break; |
|
156 | + $scale = is_numeric($field['scale']) ? $field['scale'] : 2; |
|
157 | + $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
158 | + $decimal = rand(0, (10 * $scale)) / 100; |
|
159 | + break; |
|
160 | 160 | |
161 | 161 | case 'number_float': |
162 | 162 | $precision = rand(10, 32); |
163 | - $scale = rand(0, 2); |
|
164 | - $decimal = rand(0, (10 * $scale)) / 100; |
|
165 | - $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
166 | - break; |
|
167 | - } |
|
168 | - $node_field['value'] = round((rand($min, $max) + $decimal), $scale); |
|
163 | + $scale = rand(0, 2); |
|
164 | + $decimal = rand(0, (10 * $scale)) / 100; |
|
165 | + $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
166 | + break; |
|
167 | + } |
|
168 | + $node_field['value'] = round((rand($min, $max) + $decimal), $scale); |
|
169 | 169 | } |
170 | 170 | return $node_field; |
171 | - } |
|
171 | + } |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | if (module_exists('nodereference')) { |
175 | - function nodereference_content_generate($node, $field) { |
|
175 | + function nodereference_content_generate($node, $field) { |
|
176 | 176 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
177 | - return content_devel_multiple('_nodereference_content_generate', $node, $field); |
|
177 | + return content_devel_multiple('_nodereference_content_generate', $node, $field); |
|
178 | 178 | } |
179 | 179 | else { |
180 | - return _nodereference_content_generate($node, $field); |
|
180 | + return _nodereference_content_generate($node, $field); |
|
181 | + } |
|
181 | 182 | } |
182 | - } |
|
183 | 183 | |
184 | - function _nodereference_content_generate($node, $field) { |
|
184 | + function _nodereference_content_generate($node, $field) { |
|
185 | 185 | $node_field = array(); |
186 | 186 | $allowed_values = nodereference_allowed_values($field); |
187 | 187 | unset($allowed_values[0]); |
188 | 188 | if (!empty($allowed_values)) { |
189 | - // Just pick one of the specified allowed values. |
|
190 | - $node_field['nid'] = array_rand($allowed_values); |
|
189 | + // Just pick one of the specified allowed values. |
|
190 | + $node_field['nid'] = array_rand($allowed_values); |
|
191 | 191 | } |
192 | 192 | return $node_field; |
193 | - } |
|
193 | + } |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | if (module_exists('userreference')) { |
197 | - function userreference_content_generate($node, $field) { |
|
197 | + function userreference_content_generate($node, $field) { |
|
198 | 198 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
199 | - return content_devel_multiple('_userreference_content_generate', $node, $field); |
|
199 | + return content_devel_multiple('_userreference_content_generate', $node, $field); |
|
200 | 200 | } |
201 | 201 | else { |
202 | - return _userreference_content_generate($node, $field); |
|
202 | + return _userreference_content_generate($node, $field); |
|
203 | + } |
|
203 | 204 | } |
204 | - } |
|
205 | 205 | |
206 | - function _userreference_content_generate($node, $field) { |
|
206 | + function _userreference_content_generate($node, $field) { |
|
207 | 207 | $node_field = array(); |
208 | 208 | $allowed_values = userreference_allowed_values($field); |
209 | 209 | if (isset($allowed_values['none'])) { |
210 | - unset($allowed_values['none']); |
|
210 | + unset($allowed_values['none']); |
|
211 | 211 | } |
212 | 212 | if (!empty($allowed_values)) { |
213 | - // Just pick one of the specified allowed values. |
|
214 | - $node_field['uid'] = array_rand($allowed_values); |
|
213 | + // Just pick one of the specified allowed values. |
|
214 | + $node_field['uid'] = array_rand($allowed_values); |
|
215 | 215 | } |
216 | 216 | return $node_field; |
217 | - } |
|
217 | + } |
|
218 | 218 | } |
219 | 219 | \ No newline at end of file |
@@ -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 | } |
@@ -10,34 +10,34 @@ discard block |
||
10 | 10 | * Implementation of hook_rules_action_info(). |
11 | 11 | */ |
12 | 12 | function content_rules_action_info() { |
13 | - $info = array(); |
|
14 | - $info['content_rules_action_populate_field'] = array( |
|
13 | + $info = array(); |
|
14 | + $info['content_rules_action_populate_field'] = array( |
|
15 | 15 | 'label' => t('Populate a field'), |
16 | 16 | 'arguments' => array( |
17 | - 'node' => array( |
|
17 | + 'node' => array( |
|
18 | 18 | 'type' => 'node', |
19 | 19 | 'label' => t('Content'), |
20 | - ), |
|
20 | + ), |
|
21 | 21 | ), |
22 | 22 | 'eval input' => array('code'), |
23 | 23 | 'help' => t('You should make sure that the used field exists in the given content type.'), |
24 | 24 | 'module' => 'CCK', |
25 | - ); |
|
26 | - return $info; |
|
25 | + ); |
|
26 | + return $info; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Action: populate a field. |
31 | 31 | */ |
32 | 32 | function content_rules_action_populate_field($node, $settings, $element, &$state) { |
33 | - // Get information about the field. |
|
34 | - $field = content_fields($settings['field_name'], $node->type); |
|
35 | - $value = _content_rules_get_field_value($settings, $state); |
|
33 | + // Get information about the field. |
|
34 | + $field = content_fields($settings['field_name'], $node->type); |
|
35 | + $value = _content_rules_get_field_value($settings, $state); |
|
36 | 36 | |
37 | - if (!empty($field) && is_array($value)) { |
|
37 | + if (!empty($field) && is_array($value)) { |
|
38 | 38 | $node->$settings['field_name'] = $value; |
39 | 39 | return array('node' => $node); |
40 | - } |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | * This is a multistep form! |
47 | 47 | */ |
48 | 48 | function content_rules_action_populate_field_form($settings, &$form, &$form_state) { |
49 | - $settings += array('field_name' => '', 'code' => '', 'value' => NULL); |
|
50 | - if (empty($settings['field_name'])) { |
|
49 | + $settings += array('field_name' => '', 'code' => '', 'value' => NULL); |
|
50 | + if (empty($settings['field_name'])) { |
|
51 | 51 | $form['settings']['field_name'] = array( |
52 | - '#type' => 'select', |
|
53 | - '#title' => t('Field'), |
|
54 | - '#options' => content_rules_get_field_names_by_type(), |
|
55 | - '#default_value' => $settings['field_name'], |
|
56 | - '#description' => t('Select the machine-name of the field.'), |
|
57 | - '#required' => TRUE, |
|
52 | + '#type' => 'select', |
|
53 | + '#title' => t('Field'), |
|
54 | + '#options' => content_rules_get_field_names_by_type(), |
|
55 | + '#default_value' => $settings['field_name'], |
|
56 | + '#description' => t('Select the machine-name of the field.'), |
|
57 | + '#required' => TRUE, |
|
58 | 58 | ); |
59 | 59 | // Hide some form elements in the first step. |
60 | 60 | $form['negate']['#access'] = FALSE; |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | // Replace the usual submit handlers with a own handler. |
65 | 65 | $form['submit']['#submit'] = array('content_rules_action_populate_field_form_step_submit'); |
66 | 66 | $form['submit']['#value'] = t('Continue'); |
67 | - } |
|
68 | - else { |
|
67 | + } |
|
68 | + else { |
|
69 | 69 | // Show the fields form here. |
70 | 70 | module_load_include('inc', 'content', 'includes/content.node_form'); |
71 | 71 | $field = content_fields($settings['field_name']); |
@@ -78,111 +78,111 @@ discard block |
||
78 | 78 | |
79 | 79 | unset($form['#cache']); |
80 | 80 | |
81 | - // Advanced: PHP code. |
|
81 | + // Advanced: PHP code. |
|
82 | 82 | $form['advanced_options'] = array( |
83 | - '#type' => 'fieldset', |
|
84 | - '#title' => t('Advanced: Specify the fields value with PHP code'), |
|
85 | - '#collapsible' => TRUE, |
|
86 | - '#collapsed' => empty($settings['code']), |
|
87 | - '#weight' => 5, |
|
83 | + '#type' => 'fieldset', |
|
84 | + '#title' => t('Advanced: Specify the fields value with PHP code'), |
|
85 | + '#collapsible' => TRUE, |
|
86 | + '#collapsed' => empty($settings['code']), |
|
87 | + '#weight' => 5, |
|
88 | 88 | ); |
89 | 89 | |
90 | 90 | $db_info = content_database_info($field); |
91 | 91 | $columns = array_keys($db_info['columns']); |
92 | 92 | foreach ($columns as $key => $column) { |
93 | - $columns[$key] = t("'@column' => value for @column", array('@column' => $column)); |
|
93 | + $columns[$key] = t("'@column' => value for @column", array('@column' => $column)); |
|
94 | 94 | } |
95 | 95 | $sample = t("return array(\n 0 => array(@columns),\n // You'll usually want to stop here. Provide more values\n // if you want your 'default value' to be multi-valued:\n 1 => array(@columns),\n 2 => ...\n);", array('@columns' => implode(', ', $columns))); |
96 | 96 | |
97 | 97 | $form['advanced_options']['code'] = array( |
98 | - '#type' => 'textarea', |
|
99 | - '#title' => t('Code'), |
|
100 | - '#default_value' => $settings['code'], |
|
101 | - '#rows' => 6, |
|
102 | - '#description' => t('Advanced usage only: PHP code that returns the value to set. Should not include <?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>Using <a href="@link_devel">devel.module\'s</a> \'devel load\' tab on a content page might help you figure out the expected format.', array( |
|
98 | + '#type' => 'textarea', |
|
99 | + '#title' => t('Code'), |
|
100 | + '#default_value' => $settings['code'], |
|
101 | + '#rows' => 6, |
|
102 | + '#description' => t('Advanced usage only: PHP code that returns the value to set. Should not include <?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>Using <a href="@link_devel">devel.module\'s</a> \'devel load\' tab on a content page might help you figure out the expected format.', array( |
|
103 | 103 | '!sample' => $sample, |
104 | 104 | '@link_devel' => 'http://www.drupal.org/project/devel', |
105 | - )), |
|
105 | + )), |
|
106 | 106 | ); |
107 | 107 | |
108 | 108 | // Add this file to be included when the form is built by rules |
109 | 109 | // as it's needed by CCKs add more button. |
110 | 110 | // See rules_after_build_include_files(). |
111 | 111 | $form['#includes'][] = './'. drupal_get_path('module', 'node') .'/node.pages.inc'; |
112 | - } |
|
112 | + } |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | function content_rules_action_populate_field_form_step_submit($form, &$form_state) { |
116 | - $form_state['element']['#settings']['field_name'] = $form_state['values']['settings']['field_name']; |
|
116 | + $form_state['element']['#settings']['field_name'] = $form_state['values']['settings']['field_name']; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
120 | 120 | * Validate the chosen value or php code. |
121 | 121 | */ |
122 | 122 | function content_rules_action_populate_field_validate($form, &$form_state) { |
123 | - if (!isset($form_state['element']['#settings']['field_name'])) { |
|
123 | + if (!isset($form_state['element']['#settings']['field_name'])) { |
|
124 | 124 | //Just validate the last step. |
125 | 125 | return; |
126 | - } |
|
126 | + } |
|
127 | 127 | |
128 | - if (isset($form_state['values']['code']) && ($php = $form_state['values']['code'])) { |
|
128 | + if (isset($form_state['values']['code']) && ($php = $form_state['values']['code'])) { |
|
129 | 129 | if (strpos($php, 'return') === FALSE) { |
130 | - form_set_error('code', t('You have to return the default value in the expected format.')); |
|
130 | + form_set_error('code', t('You have to return the default value in the expected format.')); |
|
131 | 131 | } |
132 | - } |
|
133 | - else { |
|
132 | + } |
|
133 | + else { |
|
134 | 134 | // Validate the field. |
135 | 135 | $settings = $form_state['element']['#settings']; |
136 | 136 | $field = content_fields($settings['field_name']); |
137 | 137 | $field_types = _content_field_types(); |
138 | 138 | $function = $field_types[$field['type']]['module'] .'_field'; |
139 | 139 | if (function_exists($function)) { |
140 | - $form['#node'] = (object)array('type' => '', $settings['field_name'] => $form_state['values'][$settings['field_name']]); |
|
141 | - $items = isset($form['#node']->$field['field_name']) ? $form['#node']->$field['field_name'] : array(); |
|
140 | + $form['#node'] = (object)array('type' => '', $settings['field_name'] => $form_state['values'][$settings['field_name']]); |
|
141 | + $items = isset($form['#node']->$field['field_name']) ? $form['#node']->$field['field_name'] : array(); |
|
142 | 142 | |
143 | - //Make sure AHAH 'add more' button isn't sent to the fields |
|
144 | - // for processing. |
|
145 | - unset($items[$field['field_name'] .'_add_more']); |
|
143 | + //Make sure AHAH 'add more' button isn't sent to the fields |
|
144 | + // for processing. |
|
145 | + unset($items[$field['field_name'] .'_add_more']); |
|
146 | 146 | |
147 | - $function('validate', $form['#node'], $field, $items, $form, NULL); |
|
148 | - content_field('validate', $form['#node'], $field, $items, $form, NULL); |
|
147 | + $function('validate', $form['#node'], $field, $items, $form, NULL); |
|
148 | + content_field('validate', $form['#node'], $field, $items, $form, NULL); |
|
149 | + } |
|
149 | 150 | } |
150 | - } |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | function content_rules_action_populate_field_submit(&$settings, $form, &$form_state) { |
154 | - // Take over field values and filter out private properties added by CCK |
|
155 | - $settings['value'] = array_filter($form_state['values'][$settings['field_name']], 'is_array'); |
|
154 | + // Take over field values and filter out private properties added by CCK |
|
155 | + $settings['value'] = array_filter($form_state['values'][$settings['field_name']], 'is_array'); |
|
156 | 156 | |
157 | - foreach ($settings['value'] as $key => $data) { |
|
157 | + foreach ($settings['value'] as $key => $data) { |
|
158 | 158 | foreach (array_filter(array_keys($data)) as $col) { |
159 | - if ($col[0] == '_') { |
|
159 | + if ($col[0] == '_') { |
|
160 | 160 | unset($settings['value'][$key][$col]); |
161 | - } |
|
161 | + } |
|
162 | 162 | } |
163 | 163 | if ($key && count(array_filter($settings['value'][$key])) == 0) { |
164 | - // For multi-valued fields don't check for any additional empty values. |
|
165 | - unset($settings['value'][$key]); |
|
164 | + // For multi-valued fields don't check for any additional empty values. |
|
165 | + unset($settings['value'][$key]); |
|
166 | + } |
|
166 | 167 | } |
167 | - } |
|
168 | 168 | |
169 | - $settings['code'] = $form_state['values']['code']; |
|
169 | + $settings['code'] = $form_state['values']['code']; |
|
170 | 170 | |
171 | - if (function_exists('rules_action_custom_php_submit')) { |
|
171 | + if (function_exists('rules_action_custom_php_submit')) { |
|
172 | 172 | // Support adding variables to the php code, if php module is present. |
173 | 173 | rules_action_custom_php_submit($settings, $form, $form_state); |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - // Add all values to the input evaluator, so that textfields / textares can |
|
177 | - // make use of it. |
|
178 | - $names = array('code'); |
|
176 | + // Add all values to the input evaluator, so that textfields / textares can |
|
177 | + // make use of it. |
|
178 | + $names = array('code'); |
|
179 | 179 | |
180 | - foreach ($settings['value'] as $key => $data) { |
|
180 | + foreach ($settings['value'] as $key => $data) { |
|
181 | 181 | foreach (array_filter($data, 'is_string') as $col => $value) { |
182 | - $names[] = "value|$key|$col"; |
|
182 | + $names[] = "value|$key|$col"; |
|
183 | + } |
|
183 | 184 | } |
184 | - } |
|
185 | - $form_state['element']['#info']['eval input'] = $names; |
|
185 | + $form_state['element']['#info']['eval input'] = $names; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | * Label callback: Improve the label of the action. |
191 | 191 | */ |
192 | 192 | function content_rules_action_populate_field_label($settings, $argument_labels) { |
193 | - return t("Populate @node's field '@field'", array('@field' => $settings['field_name']) + $argument_labels); |
|
193 | + return t("Populate @node's field '@field'", array('@field' => $settings['field_name']) + $argument_labels); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | function workflow_ng_action_populate_field_upgrade(&$element) { |
197 | - $element['#name'] = 'content_rules_action_populate_field'; |
|
198 | - $element['#settings']['code'] = $element['#settings']['default_value_php']; |
|
199 | - $element['#settings'][$element['#settings']['field_name']] = array(); |
|
200 | - unset($element['#settings']['default_value_php']); |
|
197 | + $element['#name'] = 'content_rules_action_populate_field'; |
|
198 | + $element['#settings']['code'] = $element['#settings']['default_value_php']; |
|
199 | + $element['#settings'][$element['#settings']['field_name']] = array(); |
|
200 | + unset($element['#settings']['default_value_php']); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | |
@@ -205,84 +205,84 @@ discard block |
||
205 | 205 | * Implementation of hook_rules_condition_info(). |
206 | 206 | */ |
207 | 207 | function content_rules_condition_info() { |
208 | - $info = array(); |
|
209 | - $info['content_rules_field_has_value'] = array( |
|
208 | + $info = array(); |
|
209 | + $info['content_rules_field_has_value'] = array( |
|
210 | 210 | 'label' => t('Field has value'), |
211 | 211 | 'arguments' => array( |
212 | - 'node' => array('type' => 'node', 'label' => t('Content')), |
|
212 | + 'node' => array('type' => 'node', 'label' => t('Content')), |
|
213 | 213 | ), |
214 | 214 | 'eval input' => array('code'), |
215 | 215 | 'help' => t('You should make sure that the used field exists in the given content type. The condition returns TRUE, if the selected field has the given value.'), |
216 | 216 | 'module' => 'CCK', |
217 | - ); |
|
218 | - $info['content_rules_field_changed'] = array( |
|
217 | + ); |
|
218 | + $info['content_rules_field_changed'] = array( |
|
219 | 219 | 'label' => t('Field has changed'), |
220 | 220 | 'arguments' => array( |
221 | - 'node' => array('type' => 'node', 'label' => t('Content containing changes')), |
|
222 | - 'node_unchanged' => array('type' => 'node', 'label' => t('Content not containing changes')), |
|
221 | + 'node' => array('type' => 'node', 'label' => t('Content containing changes')), |
|
222 | + 'node_unchanged' => array('type' => 'node', 'label' => t('Content not containing changes')), |
|
223 | 223 | ), |
224 | 224 | 'help' => t('You should make sure that the used field exists in the given content type.'), |
225 | 225 | 'module' => 'CCK', |
226 | - ); |
|
227 | - return $info; |
|
226 | + ); |
|
227 | + return $info; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
231 | 231 | * Condition: Check the value of a field. |
232 | 232 | */ |
233 | 233 | function content_rules_field_has_value($node, $settings) { |
234 | - // Get information about the field. |
|
235 | - $field = content_fields($settings['field_name'], $node->type); |
|
236 | - $value = _content_rules_get_field_value($settings, $state); |
|
234 | + // Get information about the field. |
|
235 | + $field = content_fields($settings['field_name'], $node->type); |
|
236 | + $value = _content_rules_get_field_value($settings, $state); |
|
237 | 237 | |
238 | - if (empty($field) || !is_array($value)) { |
|
238 | + if (empty($field) || !is_array($value)) { |
|
239 | 239 | return FALSE; |
240 | - } |
|
240 | + } |
|
241 | 241 | |
242 | - return _content_rules_field_has_value($node->$settings['field_name'], $value); |
|
242 | + return _content_rules_field_has_value($node->$settings['field_name'], $value); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | 246 | * Use the same configuration form as the "populate field" action. |
247 | 247 | */ |
248 | 248 | function content_rules_field_has_value_form($settings, &$form, &$form_state) { |
249 | - content_rules_action_populate_field_form($settings, $form, $form_state); |
|
249 | + content_rules_action_populate_field_form($settings, $form, $form_state); |
|
250 | 250 | } |
251 | 251 | function content_rules_field_has_value_validate($form, &$form_state) { |
252 | - content_rules_action_populate_field_validate($form, $form_state); |
|
252 | + content_rules_action_populate_field_validate($form, $form_state); |
|
253 | 253 | } |
254 | 254 | function content_rules_field_has_value_submit(&$settings, $form, &$form_state) { |
255 | - content_rules_action_populate_field_submit($settings, $form, $form_state); |
|
255 | + content_rules_action_populate_field_submit($settings, $form, $form_state); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | function content_rules_field_has_value_label($settings, $argument_labels) { |
259 | - return t("@node's field '@field' has value", array('@field' => $settings['field_name']) + $argument_labels); |
|
259 | + return t("@node's field '@field' has value", array('@field' => $settings['field_name']) + $argument_labels); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Condition: Check if the field has changed. |
264 | 264 | */ |
265 | 265 | function content_rules_field_changed($node1, $node2, $settings) { |
266 | - // Get information about the field. |
|
267 | - $field = content_fields($settings['field_name'], $node1->type); |
|
266 | + // Get information about the field. |
|
267 | + $field = content_fields($settings['field_name'], $node1->type); |
|
268 | 268 | |
269 | - return !empty($field) && !_content_rules_field_has_value($node1->$settings['field_name'], $node2->$settings['field_name']); |
|
269 | + return !empty($field) && !_content_rules_field_has_value($node1->$settings['field_name'], $node2->$settings['field_name']); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | function content_rules_field_changed_form($settings, &$form, &$form_state) { |
273 | - $settings += array('field_name' => ''); |
|
274 | - $form['settings']['field_name'] = array( |
|
273 | + $settings += array('field_name' => ''); |
|
274 | + $form['settings']['field_name'] = array( |
|
275 | 275 | '#type' => 'select', |
276 | 276 | '#title' => t('Field'), |
277 | 277 | '#options' => content_rules_get_field_names_by_type(), |
278 | 278 | '#default_value' => $settings['field_name'], |
279 | 279 | '#description' => t('Select the machine-name of the field to look at.'), |
280 | 280 | '#required' => TRUE, |
281 | - ); |
|
281 | + ); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | function content_rules_field_changed_label($settings, $argument_labels) { |
285 | - return t("@node's field '@field' has been changed", array('@field' => $settings['field_name']) + $argument_labels); |
|
285 | + return t("@node's field '@field' has been changed", array('@field' => $settings['field_name']) + $argument_labels); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | |
@@ -291,32 +291,32 @@ discard block |
||
291 | 291 | * Suitable for using it with #options. |
292 | 292 | */ |
293 | 293 | function content_rules_get_field_names_by_type($type = NULL) { |
294 | - $fields = array(); |
|
295 | - foreach (content_fields() as $field) { |
|
294 | + $fields = array(); |
|
295 | + foreach (content_fields() as $field) { |
|
296 | 296 | if (!isset($type) || $field['type'] == $type) { |
297 | - $fields[$field['field_name']] = $field['field_name']; |
|
297 | + $fields[$field['field_name']] = $field['field_name']; |
|
298 | + } |
|
298 | 299 | } |
299 | - } |
|
300 | - asort($fields); |
|
301 | - return $fields; |
|
300 | + asort($fields); |
|
301 | + return $fields; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | function _content_rules_get_field_value($settings, &$state) { |
305 | - if ($settings['code']) { |
|
305 | + if ($settings['code']) { |
|
306 | 306 | if (function_exists('rules_input_evaluator_php_apply')) { |
307 | - // Support adding variables to the php code, if php module is present. |
|
308 | - $value = rules_input_evaluator_php_apply($settings['code'], $settings['vars'], $state, FALSE); |
|
307 | + // Support adding variables to the php code, if php module is present. |
|
308 | + $value = rules_input_evaluator_php_apply($settings['code'], $settings['vars'], $state, FALSE); |
|
309 | 309 | } |
310 | 310 | else { |
311 | - ob_start(); |
|
312 | - $value = eval($settings['code']); |
|
313 | - ob_end_clean(); |
|
311 | + ob_start(); |
|
312 | + $value = eval($settings['code']); |
|
313 | + ob_end_clean(); |
|
314 | 314 | } |
315 | - } |
|
316 | - else { |
|
315 | + } |
|
316 | + else { |
|
317 | 317 | $value = $settings['value']; |
318 | - } |
|
319 | - return $value; |
|
318 | + } |
|
319 | + return $value; |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -329,20 +329,20 @@ discard block |
||
329 | 329 | * @param $value The value to check for. |
330 | 330 | */ |
331 | 331 | function _content_rules_field_has_value($node_value, $value) { |
332 | - if (count($value) != count($node_value)) { |
|
332 | + if (count($value) != count($node_value)) { |
|
333 | 333 | return FALSE; |
334 | - } |
|
335 | - // Loop over multiple fields |
|
336 | - foreach ($value as $delta => $sub_value) { |
|
334 | + } |
|
335 | + // Loop over multiple fields |
|
336 | + foreach ($value as $delta => $sub_value) { |
|
337 | 337 | // Check if all properties of the value are there in the node value too |
338 | 338 | if (is_array($sub_value) && is_array($node_value[$delta])) { |
339 | - if (count(array_diff_assoc($sub_value, $node_value[$delta])) != 0) { |
|
339 | + if (count(array_diff_assoc($sub_value, $node_value[$delta])) != 0) { |
|
340 | 340 | return FALSE; |
341 | - } |
|
341 | + } |
|
342 | 342 | } |
343 | 343 | elseif ($sub_value !== $node_value[$delta]) { |
344 | - return FALSE; |
|
344 | + return FALSE; |
|
345 | + } |
|
345 | 346 | } |
346 | - } |
|
347 | - return TRUE; |
|
347 | + return TRUE; |
|
348 | 348 | } |
@@ -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 | } |
@@ -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 | } |