@@ -10,155 +10,155 @@ |
||
10 | 10 | * Callback function to supply a list of content types. |
11 | 11 | */ |
12 | 12 | function fieldgroup_content_fieldgroup_ctools_content_types() { |
13 | - return array( |
|
13 | + return array( |
|
14 | 14 | 'title' => t('Content fieldgroup'), |
15 | 15 | 'defaults' => array('label' => 'hidden', 'format' => 'simple', 'empty' => ''), |
16 | - ); |
|
16 | + ); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Return all fieldgroup content types available. |
21 | 21 | */ |
22 | 22 | function fieldgroup_content_fieldgroup_content_type_content_types() { |
23 | - // This will hold all the individual fieldgroup content types. |
|
24 | - $types = array(); |
|
23 | + // This will hold all the individual fieldgroup content types. |
|
24 | + $types = array(); |
|
25 | 25 | |
26 | - // The outer loop goes through each node type with groups. |
|
27 | - foreach (fieldgroup_groups() as $node_type_groups) { |
|
26 | + // The outer loop goes through each node type with groups. |
|
27 | + foreach (fieldgroup_groups() as $node_type_groups) { |
|
28 | 28 | // The inner loop gives us each fieldgroup on each node type with groups. |
29 | 29 | foreach ($node_type_groups as $group) { |
30 | - // Skip field groups that are not of standard type. |
|
31 | - if ($group['group_type'] != 'standard') { |
|
30 | + // Skip field groups that are not of standard type. |
|
31 | + if ($group['group_type'] != 'standard') { |
|
32 | 32 | continue; |
33 | - } |
|
33 | + } |
|
34 | 34 | |
35 | - // Name the content type a combination of fieldgroup and node type names. |
|
36 | - $content_type_name = $group['type_name'] . ':' . $group['group_name']; |
|
35 | + // Name the content type a combination of fieldgroup and node type names. |
|
36 | + $content_type_name = $group['type_name'] . ':' . $group['group_name']; |
|
37 | 37 | |
38 | - // Assemble the information about the content type. |
|
39 | - $info = array( |
|
38 | + // Assemble the information about the content type. |
|
39 | + $info = array( |
|
40 | 40 | 'category' => t('Node'), |
41 | 41 | 'icon' => 'icon_cck_field_group.png', |
42 | 42 | 'title' => t('Field group: @group in @type', array( |
43 | - '@group' => t($group['label']), |
|
44 | - '@type' => node_get_types('name', $group['type_name']), |
|
43 | + '@group' => t($group['label']), |
|
44 | + '@type' => node_get_types('name', $group['type_name']), |
|
45 | 45 | )), |
46 | 46 | 'description' => t('All fields from this field group on the referenced node.'), |
47 | 47 | 'required context' => new ctools_context_required(t('Node'), 'node', array('type' => array($group['type_name']))), |
48 | - ); |
|
48 | + ); |
|
49 | 49 | |
50 | - $types[$content_type_name] = $info; |
|
50 | + $types[$content_type_name] = $info; |
|
51 | + } |
|
51 | 52 | } |
52 | - } |
|
53 | 53 | |
54 | - return $types; |
|
54 | + return $types; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Output function for the 'fieldgroup' content type. |
59 | 59 | */ |
60 | 60 | function fieldgroup_content_fieldgroup_content_type_render($subtype, $conf, $panel_args, $context) { |
61 | - if (!isset($context->data)) { |
|
61 | + if (!isset($context->data)) { |
|
62 | 62 | return; |
63 | - } |
|
64 | - $node = drupal_clone($context->data); |
|
63 | + } |
|
64 | + $node = drupal_clone($context->data); |
|
65 | 65 | |
66 | - // Make sure old data doesn't cause problems: |
|
67 | - if (empty($conf['label'])) { |
|
66 | + // Make sure old data doesn't cause problems: |
|
67 | + if (empty($conf['label'])) { |
|
68 | 68 | $conf['label'] = 'hidden'; |
69 | - } |
|
70 | - if (empty($conf['format'])) { |
|
69 | + } |
|
70 | + if (empty($conf['format'])) { |
|
71 | 71 | $conf['format'] = 'simple'; |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | - // Extract the node type and fieldgroup name from the subtype. |
|
75 | - list($node_type, $group_name) = explode(':', $subtype, 2); |
|
74 | + // Extract the node type and fieldgroup name from the subtype. |
|
75 | + list($node_type, $group_name) = explode(':', $subtype, 2); |
|
76 | 76 | |
77 | - // Get a list of all fieldgroups for this node type. |
|
78 | - $groups = fieldgroup_groups($node_type); |
|
77 | + // Get a list of all fieldgroups for this node type. |
|
78 | + $groups = fieldgroup_groups($node_type); |
|
79 | 79 | |
80 | - if (!isset($groups[$group_name])) { |
|
80 | + if (!isset($groups[$group_name])) { |
|
81 | 81 | return; |
82 | - } |
|
83 | - $group = $groups[$group_name]; |
|
84 | - |
|
85 | - // Render the field group. |
|
86 | - $node->build_mode = NODE_BUILD_NORMAL; |
|
87 | - $group['settings']['display']['label'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label']; |
|
88 | - $group['settings']['display']['full']['format'] = $conf['format']; |
|
89 | - $group['settings']['display']['full']['exclude'] = 0; |
|
90 | - $output = fieldgroup_view_group($group, $node); |
|
91 | - |
|
92 | - $block = new stdClass(); |
|
93 | - if ($conf['label'] == 'normal') { |
|
82 | + } |
|
83 | + $group = $groups[$group_name]; |
|
84 | + |
|
85 | + // Render the field group. |
|
86 | + $node->build_mode = NODE_BUILD_NORMAL; |
|
87 | + $group['settings']['display']['label'] = $conf['label'] == 'normal' || !empty($conf['override_title']) ? 'hidden' : $conf['label']; |
|
88 | + $group['settings']['display']['full']['format'] = $conf['format']; |
|
89 | + $group['settings']['display']['full']['exclude'] = 0; |
|
90 | + $output = fieldgroup_view_group($group, $node); |
|
91 | + |
|
92 | + $block = new stdClass(); |
|
93 | + if ($conf['label'] == 'normal') { |
|
94 | 94 | $block->title = t($group['label']); |
95 | - } |
|
96 | - $block->content = !empty($output) ? $output : $conf['empty']; |
|
97 | - return $block; |
|
95 | + } |
|
96 | + $block->content = !empty($output) ? $output : $conf['empty']; |
|
97 | + return $block; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Returns a settings form for the custom type. |
102 | 102 | */ |
103 | 103 | function fieldgroup_content_fieldgroup_content_type_edit_form(&$form, &$form_state) { |
104 | - $conf = $form_state['conf']; |
|
104 | + $conf = $form_state['conf']; |
|
105 | 105 | |
106 | - $label_options = array( |
|
106 | + $label_options = array( |
|
107 | 107 | 'normal' => t('Block title'), |
108 | 108 | 'above' => t('Above'), |
109 | - ); |
|
110 | - $form['label'] = array( |
|
109 | + ); |
|
110 | + $form['label'] = array( |
|
111 | 111 | '#type' => 'select', |
112 | 112 | '#title' => t('Field group label'), |
113 | 113 | '#default_value' => !empty($conf['label']) && isset($label_options[$conf['label']]) ? $conf['label'] : 'hidden', |
114 | 114 | '#options' => $label_options, |
115 | 115 | '#description' => t('Configure how the field group label is going to be displayed. This option takes no effect when "Override title" option is enabled, the specified block title is displayed instead.'), |
116 | - ); |
|
116 | + ); |
|
117 | 117 | |
118 | - $format_options = array( |
|
118 | + $format_options = array( |
|
119 | 119 | 'simple' => t('Simple'), |
120 | 120 | 'fieldset' => t('Fieldset'), |
121 | 121 | 'fieldset_collapsible' => t('Fieldset - Collapsible'), |
122 | 122 | 'fieldset_collapsed' => t('Fieldset - Collapsed'), |
123 | - ); |
|
124 | - $form['format'] = array( |
|
123 | + ); |
|
124 | + $form['format'] = array( |
|
125 | 125 | '#type' => 'select', |
126 | 126 | '#title' => t('Field group format'), |
127 | 127 | '#default_value' => !empty($conf['format']) && isset($format_options[$conf['format']]) ? $conf['format'] : 'simple', |
128 | 128 | '#options' => $format_options, |
129 | 129 | '#description' => t('This option allows you to configure the field group format.'), |
130 | - ); |
|
130 | + ); |
|
131 | 131 | |
132 | - $form['empty'] = array( |
|
132 | + $form['empty'] = array( |
|
133 | 133 | '#type' => 'textarea', |
134 | 134 | '#title' => t('Empty text'), |
135 | 135 | '#description' => t('Text to display if group has no data. Note that title will not display unless overridden.'), |
136 | 136 | '#rows' => 5, |
137 | 137 | '#default_value' => $conf['empty'], |
138 | - ); |
|
138 | + ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | function fieldgroup_content_fieldgroup_content_type_edit_form_submit(&$form, &$form_state) { |
142 | - // Copy everything from our defaults. |
|
143 | - foreach (array_keys($form_state['plugin']['defaults']) as $key) { |
|
142 | + // Copy everything from our defaults. |
|
143 | + foreach (array_keys($form_state['plugin']['defaults']) as $key) { |
|
144 | 144 | $form_state['conf'][$key] = $form_state['values'][$key]; |
145 | - } |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
149 | 149 | * Admin title for fieldgroup content type. |
150 | 150 | */ |
151 | 151 | function fieldgroup_content_fieldgroup_content_type_admin_title($subtype, $conf, $context) { |
152 | - // Extract the node type and fieldgroup name from the subtype. |
|
153 | - list($node_type, $group_name) = explode(':', $subtype, 2); |
|
152 | + // Extract the node type and fieldgroup name from the subtype. |
|
153 | + list($node_type, $group_name) = explode(':', $subtype, 2); |
|
154 | 154 | |
155 | - // Get information about this field group for this node type. |
|
156 | - $groups = fieldgroup_groups($node_type); |
|
157 | - $group = $groups[$group_name]; |
|
155 | + // Get information about this field group for this node type. |
|
156 | + $groups = fieldgroup_groups($node_type); |
|
157 | + $group = $groups[$group_name]; |
|
158 | 158 | |
159 | - return t('"@s" field group: @group in @type', array( |
|
159 | + return t('"@s" field group: @group in @type', array( |
|
160 | 160 | '@s' => $context->identifier, |
161 | 161 | '@group' => t($group['label']), |
162 | 162 | '@type' => node_get_types('name', $node_type), |
163 | - )); |
|
163 | + )); |
|
164 | 164 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | // Name the content type a combination of fieldgroup and node type names. |
36 | - $content_type_name = $group['type_name'] . ':' . $group['group_name']; |
|
36 | + $content_type_name = $group['type_name'].':'.$group['group_name']; |
|
37 | 37 | |
38 | 38 | // Assemble the information about the content type. |
39 | 39 | $info = array( |
@@ -16,230 +16,230 @@ discard block |
||
16 | 16 | * Implementation of hook_init(). |
17 | 17 | */ |
18 | 18 | function fieldgroup_init() { |
19 | - drupal_add_css(drupal_get_path('module', 'fieldgroup') .'/fieldgroup.css'); |
|
19 | + drupal_add_css(drupal_get_path('module', 'fieldgroup') .'/fieldgroup.css'); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Implementation of hook_ctools_plugin_directory(). |
24 | 24 | */ |
25 | 25 | function fieldgroup_ctools_plugin_directory($module, $plugin) { |
26 | - if ($module == 'ctools' && $plugin == 'content_types') { |
|
26 | + if ($module == 'ctools' && $plugin == 'content_types') { |
|
27 | 27 | return 'panels/' . $plugin; |
28 | - } |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Implementation of hook_menu(). |
33 | 33 | */ |
34 | 34 | function fieldgroup_menu() { |
35 | - $items = array(); |
|
35 | + $items = array(); |
|
36 | 36 | |
37 | - // Make sure this doesn't fire until content_types is working, |
|
38 | - // needed to avoid errors on initial installation. |
|
39 | - if (!defined('MAINTENANCE_MODE')) { |
|
37 | + // Make sure this doesn't fire until content_types is working, |
|
38 | + // needed to avoid errors on initial installation. |
|
39 | + if (!defined('MAINTENANCE_MODE')) { |
|
40 | 40 | foreach (node_get_types() as $type) { |
41 | - $type_name = $type->type; |
|
42 | - $content_type = content_types($type_name); |
|
43 | - $type_url_str = $content_type['url_str']; |
|
44 | - $items['admin/content/node-type/'. $type_url_str .'/groups/%'] = array( |
|
41 | + $type_name = $type->type; |
|
42 | + $content_type = content_types($type_name); |
|
43 | + $type_url_str = $content_type['url_str']; |
|
44 | + $items['admin/content/node-type/'. $type_url_str .'/groups/%'] = array( |
|
45 | 45 | 'title' => 'Edit group', |
46 | 46 | 'page callback' => 'drupal_get_form', |
47 | 47 | 'page arguments' => array('fieldgroup_group_edit_form', $type_name, 5), |
48 | 48 | 'access arguments' => array('administer content types'), |
49 | 49 | 'type' => MENU_CALLBACK, |
50 | - ); |
|
51 | - $items['admin/content/node-type/'. $type_url_str .'/groups/%/remove'] = array( |
|
50 | + ); |
|
51 | + $items['admin/content/node-type/'. $type_url_str .'/groups/%/remove'] = array( |
|
52 | 52 | 'title' => 'Edit group', |
53 | 53 | 'page callback' => 'drupal_get_form', |
54 | 54 | 'page arguments' => array('fieldgroup_remove_group', $type_name, 5), |
55 | 55 | 'access arguments' => array('administer content types'), |
56 | 56 | 'type' => MENU_CALLBACK, |
57 | - ); |
|
57 | + ); |
|
58 | 58 | } |
59 | - } |
|
60 | - return $items; |
|
59 | + } |
|
60 | + return $items; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Implementation of hook_theme(). |
65 | 65 | */ |
66 | 66 | function fieldgroup_theme() { |
67 | - return array( |
|
67 | + return array( |
|
68 | 68 | 'fieldgroup_simple' => array( |
69 | - 'template' => 'fieldgroup-simple', |
|
70 | - 'arguments' => array('element' => NULL), |
|
69 | + 'template' => 'fieldgroup-simple', |
|
70 | + 'arguments' => array('element' => NULL), |
|
71 | 71 | ), |
72 | 72 | 'fieldgroup_fieldset' => array( |
73 | - 'arguments' => array('element' => NULL), |
|
73 | + 'arguments' => array('element' => NULL), |
|
74 | 74 | ), |
75 | 75 | 'fieldgroup_display_overview_form' => array( |
76 | - 'arguments' => array('form' => NULL), |
|
76 | + 'arguments' => array('form' => NULL), |
|
77 | 77 | ), |
78 | - ); |
|
78 | + ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Implementation of hook_elements(). |
83 | 83 | */ |
84 | 84 | function fieldgroup_elements() { |
85 | - return array( |
|
85 | + return array( |
|
86 | 86 | 'fieldgroup_simple' => array(), |
87 | 87 | 'fieldgroup_fieldset' => array('#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL,), |
88 | - ); |
|
88 | + ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Implementation of hook_fieldapi(). |
93 | 93 | */ |
94 | 94 | function fieldgroup_content_fieldapi($op, $field) { |
95 | - switch ($op) { |
|
95 | + switch ($op) { |
|
96 | 96 | case 'delete instance': |
97 | 97 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
98 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
99 | - break; |
|
100 | - } |
|
98 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
99 | + break; |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | function fieldgroup_group_edit_form(&$form_state, $type_name, $group_name) { |
104 | - $content_type = content_types($type_name); |
|
105 | - $groups = fieldgroup_groups($content_type['type']); |
|
104 | + $content_type = content_types($type_name); |
|
105 | + $groups = fieldgroup_groups($content_type['type']); |
|
106 | 106 | |
107 | - if (!$group = $groups[$group_name]) { |
|
107 | + if (!$group = $groups[$group_name]) { |
|
108 | 108 | drupal_not_found(); |
109 | 109 | exit; |
110 | - } |
|
110 | + } |
|
111 | 111 | |
112 | - $form['label'] = array( |
|
112 | + $form['label'] = array( |
|
113 | 113 | '#type' => 'textfield', |
114 | 114 | '#title' => t('Label'), |
115 | 115 | '#default_value' => $group['label'], |
116 | 116 | '#required' => TRUE, |
117 | - ); |
|
117 | + ); |
|
118 | 118 | |
119 | - // Set a default value for group type early in the form so it |
|
120 | - // can be overridden by subsequent form elements added by other modules. |
|
121 | - $group_type = !empty($group['group_type']) ? $group['group_type'] : 'standard'; |
|
122 | - $form['group_type'] = array('#type' => 'hidden', '#default_value' => $group_type); |
|
119 | + // Set a default value for group type early in the form so it |
|
120 | + // can be overridden by subsequent form elements added by other modules. |
|
121 | + $group_type = !empty($group['group_type']) ? $group['group_type'] : 'standard'; |
|
122 | + $form['group_type'] = array('#type' => 'hidden', '#default_value' => $group_type); |
|
123 | 123 | |
124 | - $form['settings']['#tree'] = TRUE; |
|
125 | - $form['settings']['form'] = array( |
|
124 | + $form['settings']['#tree'] = TRUE; |
|
125 | + $form['settings']['form'] = array( |
|
126 | 126 | '#type' => 'fieldset', |
127 | 127 | '#title' => t('Form settings'), |
128 | 128 | '#description' => t('These settings apply to the group in the node editing form.'), |
129 | - ); |
|
130 | - $form['settings']['form']['style'] = array( |
|
129 | + ); |
|
130 | + $form['settings']['form']['style'] = array( |
|
131 | 131 | '#type' => 'radios', |
132 | 132 | '#title' => t('Style'), |
133 | 133 | '#default_value' => $group['settings']['form']['style'], |
134 | 134 | '#options' => array( |
135 | - 'fieldset' => t('always open'), |
|
136 | - 'fieldset_collapsible' => t('collapsible'), |
|
137 | - 'fieldset_collapsed' => t('collapsed'), |
|
135 | + 'fieldset' => t('always open'), |
|
136 | + 'fieldset_collapsible' => t('collapsible'), |
|
137 | + 'fieldset_collapsed' => t('collapsed'), |
|
138 | 138 | ) |
139 | - ); |
|
140 | - $form['settings']['form']['description'] = array( |
|
139 | + ); |
|
140 | + $form['settings']['form']['description'] = array( |
|
141 | 141 | '#type' => 'textarea', |
142 | 142 | '#title' => t('Help text'), |
143 | 143 | '#default_value' => $group['settings']['form']['description'], |
144 | 144 | '#rows' => 5, |
145 | 145 | '#description' => t('Instructions to present to the user on the editing form.'), |
146 | 146 | '#required' => FALSE, |
147 | - ); |
|
148 | - $form['settings']['display'] = array( |
|
147 | + ); |
|
148 | + $form['settings']['display'] = array( |
|
149 | 149 | '#type' => 'fieldset', |
150 | 150 | '#title' => t('Display settings'), |
151 | 151 | '#description' => t('These settings apply to the group on node display.'), |
152 | - ); |
|
153 | - $form['settings']['display']['description'] = array( |
|
152 | + ); |
|
153 | + $form['settings']['display']['description'] = array( |
|
154 | 154 | '#type' => 'textarea', |
155 | 155 | '#title' => t('Description'), |
156 | 156 | '#default_value' => $group['settings']['display']['description'], |
157 | 157 | '#rows' => 5, |
158 | 158 | '#description' => t('A description of the group.'), |
159 | 159 | '#required' => FALSE, |
160 | - ); |
|
160 | + ); |
|
161 | 161 | |
162 | - foreach (array_keys(content_build_modes()) as $key) { |
|
162 | + foreach (array_keys(content_build_modes()) as $key) { |
|
163 | 163 | $form['settings']['display'][$key]['format'] = array('#type' => 'value', '#value' => isset($group['settings']['display'][$key]['format']) ? $group['settings']['display'][$key]['format'] : 'fieldset'); |
164 | 164 | $form['settings']['display'][$key]['exclude'] = array('#type' => 'value', '#value' => isset($group['settings']['display'][$key]['exclude']) ? $group['settings']['display'][$key]['exclude'] : 0); |
165 | - } |
|
166 | - $form['settings']['display']['label'] = array('#type' => 'value', '#value' => $group['settings']['display']['label']); |
|
167 | - $form['weight'] = array('#type' => 'hidden', '#default_value' => $group['weight']); |
|
168 | - $form['group_name'] = array('#type' => 'hidden', '#default_value' => $group_name); |
|
165 | + } |
|
166 | + $form['settings']['display']['label'] = array('#type' => 'value', '#value' => $group['settings']['display']['label']); |
|
167 | + $form['weight'] = array('#type' => 'hidden', '#default_value' => $group['weight']); |
|
168 | + $form['group_name'] = array('#type' => 'hidden', '#default_value' => $group_name); |
|
169 | 169 | |
170 | - $form['#content_type'] = $content_type; |
|
170 | + $form['#content_type'] = $content_type; |
|
171 | 171 | |
172 | - $form['submit'] = array( |
|
172 | + $form['submit'] = array( |
|
173 | 173 | '#type' => 'submit', |
174 | 174 | '#value' => t('Save'), |
175 | 175 | '#weight' => 10, |
176 | - ); |
|
176 | + ); |
|
177 | 177 | |
178 | - return $form; |
|
178 | + return $form; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | function fieldgroup_group_edit_form_submit($form, &$form_state) { |
182 | - $form_values = $form_state['values']; |
|
183 | - $content_type = $form['#content_type']; |
|
184 | - fieldgroup_save_group($content_type['type'], $form_values); |
|
185 | - $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
182 | + $form_values = $form_state['values']; |
|
183 | + $content_type = $form['#content_type']; |
|
184 | + fieldgroup_save_group($content_type['type'], $form_values); |
|
185 | + $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | function fieldgroup_remove_group(&$form_state, $type_name, $group_name) { |
189 | - $content_type = content_types($type_name); |
|
190 | - $groups = fieldgroup_groups($content_type['type']); |
|
191 | - $group = isset($groups[$group_name]) ? $groups[$group_name] : ''; |
|
189 | + $content_type = content_types($type_name); |
|
190 | + $groups = fieldgroup_groups($content_type['type']); |
|
191 | + $group = isset($groups[$group_name]) ? $groups[$group_name] : ''; |
|
192 | 192 | |
193 | - if (empty($group)) { |
|
193 | + if (empty($group)) { |
|
194 | 194 | drupal_not_found(); |
195 | 195 | exit; |
196 | - } |
|
196 | + } |
|
197 | 197 | |
198 | - $form['#submit'][] = 'fieldgroup_remove_group_submit'; |
|
199 | - $form['#content_type'] = $content_type; |
|
200 | - $form['#group_name'] = $group_name; |
|
198 | + $form['#submit'][] = 'fieldgroup_remove_group_submit'; |
|
199 | + $form['#content_type'] = $content_type; |
|
200 | + $form['#group_name'] = $group_name; |
|
201 | 201 | |
202 | - return confirm_form($form, |
|
203 | - t('Are you sure you want to remove the group %label?', |
|
204 | - array('%label' => t($group['label']))), |
|
205 | - 'admin/content/node-type/'. $content_type['url_str'] .'/fields', t('This action cannot be undone.'), |
|
206 | - t('Remove'), t('Cancel')); |
|
202 | + return confirm_form($form, |
|
203 | + t('Are you sure you want to remove the group %label?', |
|
204 | + array('%label' => t($group['label']))), |
|
205 | + 'admin/content/node-type/'. $content_type['url_str'] .'/fields', t('This action cannot be undone.'), |
|
206 | + t('Remove'), t('Cancel')); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | function fieldgroup_remove_group_submit($form, &$form_state) { |
210 | - $form_values = $form_state['values']; |
|
211 | - $content_type = $form['#content_type']; |
|
212 | - $group_name = $form['#group_name']; |
|
213 | - fieldgroup_delete($content_type['type'], $group_name); |
|
214 | - drupal_set_message(t('The group %group_name has been removed.', array('%group_name' => $group_name))); |
|
215 | - $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
210 | + $form_values = $form_state['values']; |
|
211 | + $content_type = $form['#content_type']; |
|
212 | + $group_name = $form['#group_name']; |
|
213 | + fieldgroup_delete($content_type['type'], $group_name); |
|
214 | + drupal_set_message(t('The group %group_name has been removed.', array('%group_name' => $group_name))); |
|
215 | + $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | 219 | * Returns all groups for a content type |
220 | 220 | */ |
221 | 221 | function fieldgroup_groups($content_type = '', $sorted = FALSE, $reset = FALSE) { |
222 | - global $language; |
|
223 | - static $groups, $groups_sorted; |
|
224 | - if (!isset($groups) || $reset) { |
|
222 | + global $language; |
|
223 | + static $groups, $groups_sorted; |
|
224 | + if (!isset($groups) || $reset) { |
|
225 | 225 | if ($cached = cache_get('fieldgroup_data:'. $language->language, content_cache_tablename())) { |
226 | - $data = $cached->data; |
|
227 | - $groups = $data['groups']; |
|
228 | - $groups_sorted = $data['groups_sorted']; |
|
226 | + $data = $cached->data; |
|
227 | + $groups = $data['groups']; |
|
228 | + $groups_sorted = $data['groups_sorted']; |
|
229 | 229 | } |
230 | 230 | else { |
231 | - $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name"); |
|
232 | - $groups = array(); |
|
233 | - $groups_sorted = array(); |
|
234 | - while ($group = db_fetch_array($result)) { |
|
231 | + $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name"); |
|
232 | + $groups = array(); |
|
233 | + $groups_sorted = array(); |
|
234 | + while ($group = db_fetch_array($result)) { |
|
235 | 235 | $group['settings'] = unserialize($group['settings']); |
236 | 236 | $group['fields'] = array(); |
237 | 237 | |
238 | 238 | // Allow external modules to translate field group strings. |
239 | 239 | $group_strings = array( |
240 | - 'label' => $group['label'], |
|
241 | - 'form_description' => $group['settings']['form']['description'], |
|
242 | - 'display_description' => $group['settings']['display']['description'], |
|
240 | + 'label' => $group['label'], |
|
241 | + 'form_description' => $group['settings']['form']['description'], |
|
242 | + 'display_description' => $group['settings']['display']['description'], |
|
243 | 243 | ); |
244 | 244 | drupal_alter('content_fieldgroup_strings', $group_strings, $group['type_name'], $group['group_name']); |
245 | 245 | $group['label'] = $group_strings['label']; |
@@ -248,58 +248,58 @@ discard block |
||
248 | 248 | |
249 | 249 | $groups[$group['type_name']][$group['group_name']] = $group; |
250 | 250 | $groups_sorted[$group['type_name']][] = &$groups[$group['type_name']][$group['group_name']]; |
251 | - } |
|
252 | - //load fields |
|
253 | - $result = db_query("SELECT nfi.*, ng.group_name FROM {". fieldgroup_tablename() ."} ng ". |
|
254 | - "INNER JOIN {". fieldgroup_fields_tablename() ."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ". |
|
255 | - "INNER JOIN {". content_instance_tablename() ."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ". |
|
256 | - "WHERE nfi.widget_active = 1 ORDER BY nfi.weight"); |
|
257 | - while ($field = db_fetch_array($result)) { |
|
251 | + } |
|
252 | + //load fields |
|
253 | + $result = db_query("SELECT nfi.*, ng.group_name FROM {". fieldgroup_tablename() ."} ng ". |
|
254 | + "INNER JOIN {". fieldgroup_fields_tablename() ."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ". |
|
255 | + "INNER JOIN {". content_instance_tablename() ."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ". |
|
256 | + "WHERE nfi.widget_active = 1 ORDER BY nfi.weight"); |
|
257 | + while ($field = db_fetch_array($result)) { |
|
258 | 258 | // Allow external modules to translate field strings. |
259 | 259 | $field_strings = array( |
260 | - 'widget_label' => $field['label'], |
|
261 | - 'widget_description' => $field['description'], |
|
260 | + 'widget_label' => $field['label'], |
|
261 | + 'widget_description' => $field['description'], |
|
262 | 262 | ); |
263 | 263 | drupal_alter('content_field_strings', $field_strings, $field['type_name'], $field['field_name']); |
264 | 264 | $field['label'] = $field_strings['widget_label']; |
265 | 265 | $field['description'] = $field_strings['widget_description']; |
266 | 266 | |
267 | 267 | $groups[$field['type_name']][$field['group_name']]['fields'][$field['field_name']] = $field; |
268 | - } |
|
269 | - cache_set('fieldgroup_data:'. $language->language, array('groups' => $groups, 'groups_sorted' => $groups_sorted), content_cache_tablename()); |
|
268 | + } |
|
269 | + cache_set('fieldgroup_data:'. $language->language, array('groups' => $groups, 'groups_sorted' => $groups_sorted), content_cache_tablename()); |
|
270 | + } |
|
270 | 271 | } |
271 | - } |
|
272 | - if (empty($content_type)) { |
|
272 | + if (empty($content_type)) { |
|
273 | 273 | return $groups; |
274 | - } |
|
275 | - elseif (empty($groups) || empty($groups[$content_type])) { |
|
274 | + } |
|
275 | + elseif (empty($groups) || empty($groups[$content_type])) { |
|
276 | 276 | return array(); |
277 | - } |
|
278 | - return $sorted ? $groups_sorted[$content_type] : $groups[$content_type]; |
|
277 | + } |
|
278 | + return $sorted ? $groups_sorted[$content_type] : $groups[$content_type]; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | |
282 | 282 | function _fieldgroup_groups_label($content_type) { |
283 | - $groups = fieldgroup_groups($content_type); |
|
283 | + $groups = fieldgroup_groups($content_type); |
|
284 | 284 | |
285 | - $labels[''] = '<'. t('none') .'>'; |
|
286 | - foreach ($groups as $group_name => $group) { |
|
285 | + $labels[''] = '<'. t('none') .'>'; |
|
286 | + foreach ($groups as $group_name => $group) { |
|
287 | 287 | $labels[$group_name] = t($group['label']); |
288 | - } |
|
289 | - return $labels; |
|
288 | + } |
|
289 | + return $labels; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | function _fieldgroup_field_get_group($content_type, $field_name) { |
293 | - return db_result(db_query("SELECT group_name FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name)); |
|
293 | + return db_result(db_query("SELECT group_name FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name)); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | 297 | * Implementation of hook_form_alter() |
298 | 298 | */ |
299 | 299 | function fieldgroup_form_alter(&$form, $form_state, $form_id) { |
300 | - if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
300 | + if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
301 | 301 | foreach (fieldgroup_groups($form['type']['#value']) as $group_name => $group) { |
302 | - $form[$group_name] = array( |
|
302 | + $form[$group_name] = array( |
|
303 | 303 | '#type' => 'fieldset', |
304 | 304 | '#title' => check_plain(t($group['label'])), |
305 | 305 | '#collapsed' => $group['settings']['form']['style'] == 'fieldset_collapsed', |
@@ -307,62 +307,62 @@ discard block |
||
307 | 307 | '#weight' => $group['weight'], |
308 | 308 | '#description' => content_filter_xss(t($group['settings']['form']['description'])), |
309 | 309 | '#attributes' => array('class' => strtr($group['group_name'], '_', '-')), |
310 | - ); |
|
310 | + ); |
|
311 | 311 | |
312 | - $has_accessible_field = FALSE; |
|
313 | - foreach ($group['fields'] as $field_name => $field) { |
|
312 | + $has_accessible_field = FALSE; |
|
313 | + foreach ($group['fields'] as $field_name => $field) { |
|
314 | 314 | if (isset($form[$field_name])) { |
315 | - $form[$group_name][$field_name] = $form[$field_name]; |
|
316 | - // Track whether this group has any accessible fields within it. |
|
317 | - if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== FALSE) { |
|
315 | + $form[$group_name][$field_name] = $form[$field_name]; |
|
316 | + // Track whether this group has any accessible fields within it. |
|
317 | + if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== FALSE) { |
|
318 | 318 | $has_accessible_field = TRUE; |
319 | - } |
|
320 | - unset($form[$field_name]); |
|
319 | + } |
|
320 | + unset($form[$field_name]); |
|
321 | + } |
|
321 | 322 | } |
322 | - } |
|
323 | - if (!empty($group['fields']) && !element_children($form[$group_name])) { |
|
323 | + if (!empty($group['fields']) && !element_children($form[$group_name])) { |
|
324 | 324 | //hide the fieldgroup, because the fields are hidden too |
325 | 325 | unset($form[$group_name]); |
326 | - } |
|
326 | + } |
|
327 | 327 | |
328 | - if (!$has_accessible_field) { |
|
328 | + if (!$has_accessible_field) { |
|
329 | 329 | // Hide the fieldgroup, because the fields are inaccessible. |
330 | 330 | $form[$group_name]['#access'] = FALSE; |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | - // Allow other modules to alter the form. |
|
334 | - // Can't use module_invoke_all because we want |
|
335 | - // to be able to use a reference to $form and $form_state. |
|
336 | - foreach (module_implements('fieldgroup_form') as $module) { |
|
333 | + // Allow other modules to alter the form. |
|
334 | + // Can't use module_invoke_all because we want |
|
335 | + // to be able to use a reference to $form and $form_state. |
|
336 | + foreach (module_implements('fieldgroup_form') as $module) { |
|
337 | 337 | $function = $module .'_fieldgroup_form'; |
338 | 338 | $function($form, $form_state, $form_id, $group); |
339 | - } |
|
339 | + } |
|
340 | 340 | |
341 | 341 | } |
342 | 342 | |
343 | - } |
|
344 | - // The group is only added here so it will appear in the export |
|
345 | - // when using Content Copy. |
|
346 | - elseif ($form_id == 'content_field_edit_form' && isset($form['widget'])) { |
|
343 | + } |
|
344 | + // The group is only added here so it will appear in the export |
|
345 | + // when using Content Copy. |
|
346 | + elseif ($form_id == 'content_field_edit_form' && isset($form['widget'])) { |
|
347 | 347 | $content_type = content_types($form['type_name']['#value']); |
348 | 348 | $form['widget']['group'] = array( |
349 | - '#type' => 'value', |
|
350 | - '#value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']), |
|
349 | + '#type' => 'value', |
|
350 | + '#value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']), |
|
351 | 351 | ); |
352 | - } |
|
353 | - elseif ($form_id == 'content_field_overview_form') { |
|
352 | + } |
|
353 | + elseif ($form_id == 'content_field_overview_form') { |
|
354 | 354 | $form['#validate'][] = 'fieldgroup_field_overview_form_validate'; |
355 | 355 | $form['#submit'][] = 'fieldgroup_field_overview_form_submit'; |
356 | - } |
|
357 | - elseif ($form_id == 'content_display_overview_form' && !empty($form['#groups'])) { |
|
356 | + } |
|
357 | + elseif ($form_id == 'content_display_overview_form' && !empty($form['#groups'])) { |
|
358 | 358 | $form['#submit'][] = 'fieldgroup_display_overview_form_submit'; |
359 | 359 | if (!isset($form['submit'])) { |
360 | - $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 10); |
|
360 | + $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 10); |
|
361 | 361 | } |
362 | - } |
|
363 | - elseif ($form_id == 'content_field_remove_form') { |
|
362 | + } |
|
363 | + elseif ($form_id == 'content_field_remove_form') { |
|
364 | 364 | $form['#submit'][] = 'fieldgroup_field_remove_form_submit'; |
365 | - } |
|
365 | + } |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -371,185 +371,185 @@ discard block |
||
371 | 371 | * Pulled into separate function to be re-usable. |
372 | 372 | */ |
373 | 373 | function fieldgroup_validate_name($group, $type_name) { |
374 | - $errors = array(); |
|
374 | + $errors = array(); |
|
375 | 375 | |
376 | - // No label. |
|
377 | - if (!$group['label']) { |
|
376 | + // No label. |
|
377 | + if (!$group['label']) { |
|
378 | 378 | $errors['label'][] = t('You need to provide a label.'); |
379 | - } |
|
379 | + } |
|
380 | 380 | |
381 | - // No group name. |
|
382 | - if (!$group['group_name']) { |
|
381 | + // No group name. |
|
382 | + if (!$group['group_name']) { |
|
383 | 383 | $errors['group_name'][] = t('You need to provide a group name.'); |
384 | - } |
|
385 | - // Group name validation. |
|
386 | - else { |
|
384 | + } |
|
385 | + // Group name validation. |
|
386 | + else { |
|
387 | 387 | $group_name = $group['group_name']; |
388 | 388 | $group['group_type'] = !empty($group['group_type']) ? $group['group_type'] : 'standard'; |
389 | 389 | |
390 | 390 | // Add the 'group_' prefix. |
391 | 391 | if (substr($group_name, 0, 6) != 'group_') { |
392 | - $group_name = 'group_'. $group_name; |
|
392 | + $group_name = 'group_'. $group_name; |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | // Invalid field name. |
396 | 396 | if (!preg_match('!^group_[a-z0-9_]+$!', $group_name)) { |
397 | - $errors['group_name'][] = t('The group name %group_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%group_name' => $group_name)); |
|
397 | + $errors['group_name'][] = t('The group name %group_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%group_name' => $group_name)); |
|
398 | 398 | } |
399 | 399 | if (strlen($group_name) > 32) { |
400 | - $errors['group_name'][] = t('The group name %group_name is too long. The name is limited to 32 characters, including the \'group_\' prefix.', array('%group_name' => $group_name)); |
|
400 | + $errors['group_name'][] = t('The group name %group_name is too long. The name is limited to 32 characters, including the \'group_\' prefix.', array('%group_name' => $group_name)); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | // Group name already exists. |
404 | 404 | $groups = fieldgroup_groups($type_name); |
405 | 405 | if (isset($groups[$group_name])) { |
406 | - $errors['group_name'][] = t('The group name %group_name already exists.', array('%group_name' => $group_name)); |
|
406 | + $errors['group_name'][] = t('The group name %group_name already exists.', array('%group_name' => $group_name)); |
|
407 | 407 | } |
408 | 408 | if (empty($errors['group_name'])) { |
409 | - $group['group_name'] = $group_name; |
|
409 | + $group['group_name'] = $group_name; |
|
410 | + } |
|
410 | 411 | } |
411 | - } |
|
412 | - return array('group_name' => $group['group_name'], 'errors' => $errors); |
|
412 | + return array('group_name' => $group['group_name'], 'errors' => $errors); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | function fieldgroup_field_overview_form_validate($form, &$form_state) { |
416 | - $form_values = $form_state['values']; |
|
417 | - $group = $form_values['_add_new_group']; |
|
416 | + $form_values = $form_state['values']; |
|
417 | + $group = $form_values['_add_new_group']; |
|
418 | 418 | |
419 | - if (array_filter(array($group['label'], $group['group_name']))) { |
|
419 | + if (array_filter(array($group['label'], $group['group_name']))) { |
|
420 | 420 | $validation = fieldgroup_validate_name($group, $form['#type_name']); |
421 | 421 | if (!empty($validation['errors'])) { |
422 | - foreach ($validation['errors'] as $type => $messages) { |
|
422 | + foreach ($validation['errors'] as $type => $messages) { |
|
423 | 423 | foreach ($messages as $message) { |
424 | - if ($type == 'label') { |
|
424 | + if ($type == 'label') { |
|
425 | 425 | form_set_error('_add_new_group][label', t('Add new group:') .' '. $message); |
426 | - } |
|
427 | - else { |
|
426 | + } |
|
427 | + else { |
|
428 | 428 | form_set_error('_add_new_group][group_name', t('Add new group:') .' '. $message); |
429 | - } |
|
429 | + } |
|
430 | + } |
|
430 | 431 | } |
431 | - } |
|
432 | 432 | } |
433 | 433 | $group_name = $validation['group_name']; |
434 | 434 | form_set_value($form['_add_new_group']['group_name'], $group_name, $form_state); |
435 | - } |
|
436 | - else { |
|
435 | + } |
|
436 | + else { |
|
437 | 437 | // Fail validation if attempt to nest fields under a new group without the |
438 | 438 | // proper information. Not raising an error would cause the nested fields |
439 | 439 | // to get weights the user doesn't expect. |
440 | 440 | |
441 | 441 | foreach ($form_values as $key => $values) { |
442 | - if ($values['parent'] == '_add_new_group') { |
|
442 | + if ($values['parent'] == '_add_new_group') { |
|
443 | 443 | form_set_error('_add_new_group][label', t('Add new group: you need to provide a label.')); |
444 | 444 | form_set_error('_add_new_group][group_name', t('Add new group: you need to provide a group name.')); |
445 | 445 | break; |
446 | - } |
|
446 | + } |
|
447 | + } |
|
447 | 448 | } |
448 | - } |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | function fieldgroup_field_overview_form_submit($form, &$form_state) { |
452 | - $form_values = $form_state['values']; |
|
453 | - $type_name = $form['#type_name']; |
|
452 | + $form_values = $form_state['values']; |
|
453 | + $type_name = $form['#type_name']; |
|
454 | 454 | |
455 | - // Create new group if needed. |
|
456 | - if (!empty($form_values['_add_new_group']['label'])) { |
|
455 | + // Create new group if needed. |
|
456 | + if (!empty($form_values['_add_new_group']['label'])) { |
|
457 | 457 | $group = $form_values['_add_new_group']; |
458 | 458 | $group['settings'] = field_group_default_settings($group['group_type']); |
459 | 459 | fieldgroup_save_group($type_name, $group); |
460 | 460 | $new_group_name = $group['group_name']; |
461 | - } |
|
461 | + } |
|
462 | 462 | |
463 | - // Parse incoming rows. |
|
464 | - $add_field_rows = array('_add_new_field', '_add_existing_field'); |
|
465 | - $field_rows = array_merge($form['#fields'], $add_field_rows); |
|
466 | - foreach ($form_values as $key => $values) { |
|
463 | + // Parse incoming rows. |
|
464 | + $add_field_rows = array('_add_new_field', '_add_existing_field'); |
|
465 | + $field_rows = array_merge($form['#fields'], $add_field_rows); |
|
466 | + foreach ($form_values as $key => $values) { |
|
467 | 467 | // If 'field' row: update field parenting. |
468 | 468 | if (in_array($key, $field_rows)) { |
469 | - // If newly added fields were added to a group: |
|
470 | - if (in_array($key, $add_field_rows)) { |
|
469 | + // If newly added fields were added to a group: |
|
470 | + if (in_array($key, $add_field_rows)) { |
|
471 | 471 | // We replace the '_add_*_field' key with the actual name of |
472 | 472 | // the field that got added. |
473 | 473 | // content_field_overview_form_submit() placed those |
474 | 474 | // in $form_state['fields_added'] for us. |
475 | 475 | if (isset($form_state['fields_added'][$key])) { |
476 | - $key = $form_state['fields_added'][$key]; |
|
476 | + $key = $form_state['fields_added'][$key]; |
|
477 | 477 | } |
478 | 478 | else { |
479 | - // No field was actually created : skip to next row. |
|
480 | - continue; |
|
479 | + // No field was actually created : skip to next row. |
|
480 | + continue; |
|
481 | 481 | } |
482 | - } |
|
483 | - // If the field was added to the newly created group, replace the |
|
484 | - // '_add_new_group' value with the actual name of the group. |
|
485 | - $parent = ($values['parent'] == '_add_new_group' && isset($new_group_name)) ? $new_group_name : $values['parent']; |
|
486 | - // TODO: check the parent group does exist ? |
|
487 | - fieldgroup_update_fields(array('field_name' => $key, 'group' => $parent, 'type_name' => $type_name)); |
|
482 | + } |
|
483 | + // If the field was added to the newly created group, replace the |
|
484 | + // '_add_new_group' value with the actual name of the group. |
|
485 | + $parent = ($values['parent'] == '_add_new_group' && isset($new_group_name)) ? $new_group_name : $values['parent']; |
|
486 | + // TODO: check the parent group does exist ? |
|
487 | + fieldgroup_update_fields(array('field_name' => $key, 'group' => $parent, 'type_name' => $type_name)); |
|
488 | 488 | } |
489 | 489 | |
490 | 490 | // If 'group' row: update groups weights |
491 | 491 | // (possible newly created group has already been taken care of). |
492 | 492 | elseif (in_array($key, $form['#groups'])) { |
493 | - db_query("UPDATE {". fieldgroup_tablename() ."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'", |
|
493 | + db_query("UPDATE {". fieldgroup_tablename() ."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'", |
|
494 | 494 | $values['weight'], $type_name, $key); |
495 | 495 | } |
496 | - } |
|
496 | + } |
|
497 | 497 | |
498 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
498 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | function field_group_default_settings($group_type) { |
502 | - $settings = array( |
|
502 | + $settings = array( |
|
503 | 503 | 'form' => array('style' => 'fieldset', 'description' => ''), |
504 | 504 | 'display' => array('description' => '', 'label' => 'above'), |
505 | - ); |
|
506 | - module_load_include('inc', 'content', 'includes/content.admin'); |
|
507 | - foreach (array_keys(content_build_modes()) as $key) { |
|
505 | + ); |
|
506 | + module_load_include('inc', 'content', 'includes/content.admin'); |
|
507 | + foreach (array_keys(content_build_modes()) as $key) { |
|
508 | 508 | $settings['display'][$key]['format'] = 'fieldset'; |
509 | 509 | $settings['display'][$key]['exclude'] = 0; |
510 | - } |
|
511 | - // Allow other modules to add new default settings. |
|
512 | - $settings = array_merge($settings, module_invoke_all('fieldgroup_default_settings', $group_type)); |
|
513 | - return $settings; |
|
510 | + } |
|
511 | + // Allow other modules to add new default settings. |
|
512 | + $settings = array_merge($settings, module_invoke_all('fieldgroup_default_settings', $group_type)); |
|
513 | + return $settings; |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | function fieldgroup_display_overview_form_submit($form, &$form_state) { |
517 | - $form_values = $form_state['values']; |
|
518 | - $groups = fieldgroup_groups($form['#type_name']); |
|
519 | - foreach ($form_values as $key => $values) { |
|
517 | + $form_values = $form_state['values']; |
|
518 | + $groups = fieldgroup_groups($form['#type_name']); |
|
519 | + foreach ($form_values as $key => $values) { |
|
520 | 520 | if (in_array($key, $form['#groups'])) { |
521 | - $group = $groups[$key]; |
|
522 | - // We have some numeric keys here, so we can't use array_merge. |
|
523 | - $group['settings']['display'] = $values + $group['settings']['display']; |
|
524 | - fieldgroup_save_group($form['#type_name'], $group); |
|
521 | + $group = $groups[$key]; |
|
522 | + // We have some numeric keys here, so we can't use array_merge. |
|
523 | + $group['settings']['display'] = $values + $group['settings']['display']; |
|
524 | + fieldgroup_save_group($form['#type_name'], $group); |
|
525 | + } |
|
525 | 526 | } |
526 | - } |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | function fieldgroup_field_remove_form_submit($form, &$form_state) { |
530 | - $form_values = $form_state['values']; |
|
531 | - // TODO: |
|
532 | - // - when a (non last) field is removed from a group, a 'ghost row' remains in the fields overview |
|
533 | - // - when the last field is removed, the group disappears |
|
534 | - // seems to be fixed when emptying the cache. |
|
535 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
530 | + $form_values = $form_state['values']; |
|
531 | + // TODO: |
|
532 | + // - when a (non last) field is removed from a group, a 'ghost row' remains in the fields overview |
|
533 | + // - when the last field is removed, the group disappears |
|
534 | + // seems to be fixed when emptying the cache. |
|
535 | + db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
539 | 539 | * Implementation of hook_nodeapi(). |
540 | 540 | */ |
541 | 541 | function fieldgroup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
542 | - switch ($op) { |
|
542 | + switch ($op) { |
|
543 | 543 | case 'view': |
544 | 544 | // Prevent against invalid 'nodes' built by broken 3rd party code. |
545 | 545 | if (isset($node->type)) { |
546 | 546 | // Build the node content element needed to render each fieldgroup. |
547 | 547 | foreach (fieldgroup_groups($node->type) as $group) { |
548 | - fieldgroup_build_content($group, $node, $teaser, $page); |
|
548 | + fieldgroup_build_content($group, $node, $teaser, $page); |
|
549 | + } |
|
549 | 550 | } |
550 | - } |
|
551 | - break; |
|
552 | - } |
|
551 | + break; |
|
552 | + } |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -569,80 +569,80 @@ discard block |
||
569 | 569 | * @see fieldgroup_view_group() |
570 | 570 | */ |
571 | 571 | function fieldgroup_build_content($group, &$node, $teaser, $page) { |
572 | - // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
573 | - if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
572 | + // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
573 | + if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
574 | 574 | $context = $teaser ? 'teaser' : 'full'; |
575 | - } |
|
576 | - else { |
|
575 | + } |
|
576 | + else { |
|
577 | 577 | $context = $node->build_mode; |
578 | - } |
|
578 | + } |
|
579 | 579 | |
580 | - $group_name = $group['group_name']; |
|
580 | + $group_name = $group['group_name']; |
|
581 | 581 | |
582 | - // Do not include group labels when indexing content. |
|
583 | - if ($context == NODE_BUILD_SEARCH_INDEX) { |
|
582 | + // Do not include group labels when indexing content. |
|
583 | + if ($context == NODE_BUILD_SEARCH_INDEX) { |
|
584 | 584 | $group['settings']['display']['label'] = 'hidden'; |
585 | - } |
|
586 | - $label = $group['settings']['display']['label'] == 'above'; |
|
587 | - $element = array( |
|
585 | + } |
|
586 | + $label = $group['settings']['display']['label'] == 'above'; |
|
587 | + $element = array( |
|
588 | 588 | '#title' => $label ? check_plain(t($group['label'])) : '', |
589 | 589 | '#description' => $label ? content_filter_xss(t($group['settings']['display']['description'])) : '', |
590 | - ); |
|
591 | - $format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset'; |
|
590 | + ); |
|
591 | + $format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset'; |
|
592 | 592 | |
593 | - switch ($format) { |
|
593 | + switch ($format) { |
|
594 | 594 | case 'simple': |
595 | 595 | $element['#type'] = 'fieldgroup_simple'; |
596 | - $element['#group_name'] = $group_name; |
|
597 | - $element['#node'] = $node; |
|
598 | - break; |
|
596 | + $element['#group_name'] = $group_name; |
|
597 | + $element['#node'] = $node; |
|
598 | + break; |
|
599 | 599 | case 'hidden': |
600 | 600 | $element['#access'] = FALSE; |
601 | - break; |
|
601 | + break; |
|
602 | 602 | case 'fieldset_collapsed': |
603 | 603 | $element['#collapsed'] = TRUE; |
604 | 604 | case 'fieldset_collapsible': |
605 | 605 | $element['#collapsible'] = TRUE; |
606 | 606 | case 'fieldset': |
607 | 607 | $element['#type'] = 'fieldgroup_fieldset'; |
608 | - $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
|
609 | - break; |
|
610 | - } |
|
611 | - foreach ($group['fields'] as $field_name => $field) { |
|
608 | + $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
|
609 | + break; |
|
610 | + } |
|
611 | + foreach ($group['fields'] as $field_name => $field) { |
|
612 | 612 | if (isset($node->content[$field_name])) { |
613 | - $element[$field_name] = $node->content[$field_name]; |
|
613 | + $element[$field_name] = $node->content[$field_name]; |
|
614 | + } |
|
614 | 615 | } |
615 | - } |
|
616 | 616 | |
617 | - // Allow other modules to alter the group view. |
|
618 | - // Can't use module_invoke_all because we want |
|
619 | - // to be able to use a reference to $node and $element. |
|
620 | - foreach (module_implements('fieldgroup_view') as $module) { |
|
617 | + // Allow other modules to alter the group view. |
|
618 | + // Can't use module_invoke_all because we want |
|
619 | + // to be able to use a reference to $node and $element. |
|
620 | + foreach (module_implements('fieldgroup_view') as $module) { |
|
621 | 621 | $function = $module .'_fieldgroup_view'; |
622 | 622 | $function($node, $element, $group, $context); |
623 | - } |
|
623 | + } |
|
624 | 624 | |
625 | - // Unset the original field values now that we've moved them. |
|
626 | - foreach ($group['fields'] as $field_name => $field) { |
|
625 | + // Unset the original field values now that we've moved them. |
|
626 | + foreach ($group['fields'] as $field_name => $field) { |
|
627 | 627 | if (isset($node->content[$field_name])) { |
628 | - unset($node->content[$field_name]); |
|
628 | + unset($node->content[$field_name]); |
|
629 | + } |
|
629 | 630 | } |
630 | - } |
|
631 | 631 | |
632 | - // The wrapper lets us get the themed output for the group |
|
633 | - // to populate the $GROUP_NAME_rendered variable for node templates, |
|
634 | - // and hide it from the $content variable if needed. |
|
635 | - // See fieldgroup_preprocess_node(), theme_fieldgroup_wrapper(). |
|
636 | - $wrapper = array( |
|
632 | + // The wrapper lets us get the themed output for the group |
|
633 | + // to populate the $GROUP_NAME_rendered variable for node templates, |
|
634 | + // and hide it from the $content variable if needed. |
|
635 | + // See fieldgroup_preprocess_node(), theme_fieldgroup_wrapper(). |
|
636 | + $wrapper = array( |
|
637 | 637 | 'group' => $element, |
638 | 638 | '#weight' => $group['weight'], |
639 | 639 | '#post_render' => array('fieldgroup_wrapper_post_render'), |
640 | 640 | '#group_name' => $group_name, |
641 | 641 | '#type_name' => $node->type, |
642 | 642 | '#context' => $context, |
643 | - ); |
|
643 | + ); |
|
644 | 644 | |
645 | - $node->content[$group_name] = $wrapper; |
|
645 | + $node->content[$group_name] = $wrapper; |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | /** |
@@ -674,64 +674,64 @@ discard block |
||
674 | 674 | * @see content_view_field() |
675 | 675 | */ |
676 | 676 | function fieldgroup_view_group($group, &$node, $teaser = FALSE, $page = FALSE) { |
677 | - $group_name = $group['group_name']; |
|
678 | - $field_types = _content_field_types(); |
|
677 | + $group_name = $group['group_name']; |
|
678 | + $field_types = _content_field_types(); |
|
679 | 679 | |
680 | - // Clone the node to prevent from altering the original. |
|
681 | - $node_copy = drupal_clone($node); |
|
680 | + // Clone the node to prevent from altering the original. |
|
681 | + $node_copy = drupal_clone($node); |
|
682 | 682 | |
683 | - // Use 'full'/'teaser' if not specified otherwise. |
|
684 | - $node_copy->build_mode = isset($node_copy->build_mode) ? $node_copy->build_mode : NODE_BUILD_NORMAL; |
|
683 | + // Use 'full'/'teaser' if not specified otherwise. |
|
684 | + $node_copy->build_mode = isset($node_copy->build_mode) ? $node_copy->build_mode : NODE_BUILD_NORMAL; |
|
685 | 685 | |
686 | - // Build the content element for individual fields in the field group. |
|
687 | - if (!isset($node_copy->content)) { |
|
686 | + // Build the content element for individual fields in the field group. |
|
687 | + if (!isset($node_copy->content)) { |
|
688 | 688 | $node_copy->content = array(); |
689 | - } |
|
690 | - foreach (array_keys($group['fields']) as $field_name) { |
|
689 | + } |
|
690 | + foreach (array_keys($group['fields']) as $field_name) { |
|
691 | 691 | $field = content_fields($field_name, $node_copy->type); |
692 | 692 | |
693 | 693 | if (isset($node_copy->{$field_name})) { |
694 | - $items = $node_copy->{$field_name}; |
|
694 | + $items = $node_copy->{$field_name}; |
|
695 | 695 | |
696 | - // One-field equivalent to _content_field_invoke('sanitize'). |
|
697 | - $module = $field_types[$field['type']]['module']; |
|
698 | - $function = $module .'_field'; |
|
699 | - if (function_exists($function)) { |
|
696 | + // One-field equivalent to _content_field_invoke('sanitize'). |
|
697 | + $module = $field_types[$field['type']]['module']; |
|
698 | + $function = $module .'_field'; |
|
699 | + if (function_exists($function)) { |
|
700 | 700 | $function('sanitize', $node_copy, $field, $items, $teaser, $page); |
701 | 701 | $node_copy->{$field_name} = $items; |
702 | - } |
|
702 | + } |
|
703 | 703 | |
704 | - $field_view = content_field('view', $node_copy, $field, $items, $teaser, $page); |
|
705 | - // content_field('view') adds a wrapper to handle variables and 'excluded' |
|
706 | - // fields for node templates. We bypass it and get the actual field. |
|
707 | - $node_copy->content[$field_name] = $field_view[$field_name]; |
|
704 | + $field_view = content_field('view', $node_copy, $field, $items, $teaser, $page); |
|
705 | + // content_field('view') adds a wrapper to handle variables and 'excluded' |
|
706 | + // fields for node templates. We bypass it and get the actual field. |
|
707 | + $node_copy->content[$field_name] = $field_view[$field_name]; |
|
708 | + } |
|
708 | 709 | } |
709 | - } |
|
710 | 710 | |
711 | - // Build the content element of the field group itself. |
|
712 | - fieldgroup_build_content($group, $node_copy, $teaser, $page); |
|
711 | + // Build the content element of the field group itself. |
|
712 | + fieldgroup_build_content($group, $node_copy, $teaser, $page); |
|
713 | 713 | |
714 | - // fieldgroup_build_content() adds a wrapper to handle variables and 'excluded' |
|
715 | - // groups for node templates. We bypass it and render the actual field group. |
|
716 | - $output = drupal_render($node_copy->content[$group_name]['group']); |
|
714 | + // fieldgroup_build_content() adds a wrapper to handle variables and 'excluded' |
|
715 | + // groups for node templates. We bypass it and render the actual field group. |
|
716 | + $output = drupal_render($node_copy->content[$group_name]['group']); |
|
717 | 717 | |
718 | - return $output; |
|
718 | + return $output; |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | /** |
722 | 722 | * Hide specified fields from the $content variable in node templates. |
723 | 723 | */ |
724 | 724 | function fieldgroup_wrapper_post_render($content, $element) { |
725 | - $groups = fieldgroup_groups($element['#type_name']); |
|
726 | - $group = $groups[$element['#group_name']]; |
|
725 | + $groups = fieldgroup_groups($element['#type_name']); |
|
726 | + $group = $groups[$element['#group_name']]; |
|
727 | 727 | |
728 | - // The display settings are not in quite the same place in the |
|
729 | - // group and the field, so create the value the theme will expect. |
|
730 | - $group['display_settings'] = $group['settings']['display']; |
|
731 | - if (theme('content_exclude', $content, $group, $element['#context'])) { |
|
728 | + // The display settings are not in quite the same place in the |
|
729 | + // group and the field, so create the value the theme will expect. |
|
730 | + $group['display_settings'] = $group['settings']['display']; |
|
731 | + if (theme('content_exclude', $content, $group, $element['#context'])) { |
|
732 | 732 | return ''; |
733 | - } |
|
734 | - return $content; |
|
733 | + } |
|
734 | + return $content; |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | /* |
@@ -740,12 +740,12 @@ discard block |
||
740 | 740 | * @return The name of the group, or FALSE. |
741 | 741 | */ |
742 | 742 | function fieldgroup_get_group($content_type, $field_name) { |
743 | - foreach (fieldgroup_groups($content_type) as $group_name => $group) { |
|
743 | + foreach (fieldgroup_groups($content_type) as $group_name => $group) { |
|
744 | 744 | if (in_array($field_name, array_keys($group['fields']))) { |
745 | - return $group_name; |
|
745 | + return $group_name; |
|
746 | 746 | } |
747 | - } |
|
748 | - return FALSE; |
|
747 | + } |
|
748 | + return FALSE; |
|
749 | 749 | } |
750 | 750 | |
751 | 751 | /** |
@@ -753,37 +753,37 @@ discard block |
||
753 | 753 | * React to change in node types |
754 | 754 | */ |
755 | 755 | function fieldgroup_node_type($op, $info) { |
756 | - if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) { |
|
756 | + if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) { |
|
757 | 757 | // update the tables |
758 | 758 | db_query("UPDATE {". fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
759 | 759 | db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
760 | 760 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
761 | - } |
|
762 | - elseif ($op == 'delete') { |
|
761 | + } |
|
762 | + elseif ($op == 'delete') { |
|
763 | 763 | db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type); |
764 | 764 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s'", $info->type); |
765 | - } |
|
765 | + } |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | function fieldgroup_types() { |
769 | - $types = array('standard' => t('Standard group')); |
|
770 | - // Allow other modules to add new group_types. |
|
771 | - $types = array_merge($types, module_invoke_all('fieldgroup_types')); |
|
772 | - return $types; |
|
769 | + $types = array('standard' => t('Standard group')); |
|
770 | + // Allow other modules to add new group_types. |
|
771 | + $types = array_merge($types, module_invoke_all('fieldgroup_types')); |
|
772 | + return $types; |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | function fieldgroup_tablename($version = NULL) { |
776 | - if (is_null($version)) { |
|
776 | + if (is_null($version)) { |
|
777 | 777 | $version = variable_get('fieldgroup_schema_version', 0); |
778 | - } |
|
779 | - return $version < 6000 ? 'node_group' : 'content_group'; |
|
778 | + } |
|
779 | + return $version < 6000 ? 'node_group' : 'content_group'; |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | function fieldgroup_fields_tablename($version = NULL) { |
783 | - if (is_null($version)) { |
|
783 | + if (is_null($version)) { |
|
784 | 784 | $version = variable_get('fieldgroup_schema_version', 0); |
785 | - } |
|
786 | - return $version < 6000 ? 'node_group_fields' : 'content_group_fields'; |
|
785 | + } |
|
786 | + return $version < 6000 ? 'node_group_fields' : 'content_group_fields'; |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -796,51 +796,51 @@ discard block |
||
796 | 796 | * Saves the given group for this content-type |
797 | 797 | */ |
798 | 798 | function fieldgroup_save_group($type_name, $group) { |
799 | - $groups = fieldgroup_groups($type_name); |
|
799 | + $groups = fieldgroup_groups($type_name); |
|
800 | 800 | |
801 | - // Allow other modules to intervene when the group is saved. |
|
802 | - foreach (module_implements('fieldgroup_save_group') as $module) { |
|
801 | + // Allow other modules to intervene when the group is saved. |
|
802 | + foreach (module_implements('fieldgroup_save_group') as $module) { |
|
803 | 803 | $function = $module .'_fieldgroup_save_group'; |
804 | 804 | $function($group); |
805 | - } |
|
805 | + } |
|
806 | 806 | |
807 | - if (!isset($groups[$group['group_name']])) { |
|
807 | + if (!isset($groups[$group['group_name']])) { |
|
808 | 808 | // Accept group name from programmed submissions if valid. |
809 | 809 | db_query("INSERT INTO {". fieldgroup_tablename() ."} (group_type, type_name, group_name, label, settings, weight)". |
810 | - " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']); |
|
810 | + " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']); |
|
811 | 811 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
812 | 812 | return SAVED_NEW; |
813 | - } |
|
814 | - else { |
|
813 | + } |
|
814 | + else { |
|
815 | 815 | db_query("UPDATE {". fieldgroup_tablename() ."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ". |
816 | - "WHERE type_name = '%s' AND group_name = '%s'", |
|
817 | - $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); |
|
816 | + "WHERE type_name = '%s' AND group_name = '%s'", |
|
817 | + $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); |
|
818 | 818 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
819 | 819 | return SAVED_UPDATED; |
820 | - } |
|
820 | + } |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | function fieldgroup_update_fields($form_values) { |
824 | - $default = _fieldgroup_field_get_group($form_values['type_name'], $form_values['field_name']); |
|
824 | + $default = _fieldgroup_field_get_group($form_values['type_name'], $form_values['field_name']); |
|
825 | 825 | |
826 | - if ($default != $form_values['group']) { |
|
826 | + if ($default != $form_values['group']) { |
|
827 | 827 | if ($form_values['group'] && !$default) { |
828 | - db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); |
|
828 | + db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); |
|
829 | 829 | } |
830 | 830 | elseif ($form_values['group']) { |
831 | - db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); |
|
831 | + db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); |
|
832 | 832 | } |
833 | 833 | else { |
834 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
834 | + db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
835 | 835 | } |
836 | 836 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
837 | - } |
|
837 | + } |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | function fieldgroup_delete($content_type, $group_name) { |
841 | - db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
842 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
843 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
841 | + db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
842 | + db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
843 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
@@ -849,23 +849,23 @@ discard block |
||
849 | 849 | * Derived from core's theme_fieldset, with no output if the content is empty. |
850 | 850 | */ |
851 | 851 | function theme_fieldgroup_fieldset($element) { |
852 | - if (empty($element['#children']) && empty($element['#value'])) { |
|
852 | + if (empty($element['#children']) && empty($element['#value'])) { |
|
853 | 853 | return ''; |
854 | - } |
|
854 | + } |
|
855 | 855 | |
856 | - if ($element['#collapsible']) { |
|
856 | + if ($element['#collapsible']) { |
|
857 | 857 | drupal_add_js('misc/collapse.js'); |
858 | 858 | |
859 | 859 | if (!isset($element['#attributes']['class'])) { |
860 | - $element['#attributes']['class'] = ''; |
|
860 | + $element['#attributes']['class'] = ''; |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | $element['#attributes']['class'] .= ' collapsible'; |
864 | 864 | if ($element['#collapsed']) { |
865 | - $element['#attributes']['class'] .= ' collapsed'; |
|
865 | + $element['#attributes']['class'] .= ' collapsed'; |
|
866 | + } |
|
866 | 867 | } |
867 | - } |
|
868 | - return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n"; |
|
868 | + return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n"; |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | |
@@ -882,19 +882,19 @@ discard block |
||
882 | 882 | * @see fieldgroup-simple.tpl.php |
883 | 883 | */ |
884 | 884 | function template_preprocess_fieldgroup_simple(&$vars) { |
885 | - $element = $vars['element']; |
|
886 | - |
|
887 | - $vars['group_name'] = $element['#group_name']; |
|
888 | - $vars['group_name_css'] = strtr($element['#group_name'], '_', '-'); |
|
889 | - $vars['label'] = isset($element['#title']) ? $element['#title'] : '';; |
|
890 | - $vars['description'] = isset($element['#description']) ? $element['#description'] : '';; |
|
891 | - $vars['content'] = isset($element['#children']) ? $element['#children'] : ''; |
|
892 | - $vars['template_files'] = array( |
|
885 | + $element = $vars['element']; |
|
886 | + |
|
887 | + $vars['group_name'] = $element['#group_name']; |
|
888 | + $vars['group_name_css'] = strtr($element['#group_name'], '_', '-'); |
|
889 | + $vars['label'] = isset($element['#title']) ? $element['#title'] : '';; |
|
890 | + $vars['description'] = isset($element['#description']) ? $element['#description'] : '';; |
|
891 | + $vars['content'] = isset($element['#children']) ? $element['#children'] : ''; |
|
892 | + $vars['template_files'] = array( |
|
893 | 893 | 'fieldgroup-simple-', |
894 | 894 | 'fieldgroup-simple-'. $element['#group_name'], |
895 | 895 | 'fieldgroup-simple-'. $element['#node']->type, |
896 | 896 | 'fieldgroup-simple-'. $element['#group_name'] .'-'. $element['#node']->type, |
897 | - ); |
|
897 | + ); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -904,10 +904,10 @@ discard block |
||
904 | 904 | * containing the themed output for the whole group. |
905 | 905 | */ |
906 | 906 | function fieldgroup_preprocess_node(&$vars) { |
907 | - $node = $vars['node']; |
|
907 | + $node = $vars['node']; |
|
908 | 908 | |
909 | - foreach (fieldgroup_groups($node->type) as $group_name => $group) { |
|
909 | + foreach (fieldgroup_groups($node->type) as $group_name => $group) { |
|
910 | 910 | // '#chilren' might not be set if the group is empty. |
911 | 911 | $vars[$group_name .'_rendered'] = isset($node->content[$group_name]['#children']) ? $node->content[$group_name]['#children'] : ''; |
912 | - } |
|
912 | + } |
|
913 | 913 | } |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | */ |
94 | 94 | function fieldgroup_content_fieldapi($op, $field) { |
95 | 95 | switch ($op) { |
96 | - case 'delete instance': |
|
97 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
|
98 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
99 | - break; |
|
96 | + case 'delete instance': |
|
97 | + db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
|
98 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
99 | + break; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -540,15 +540,15 @@ discard block |
||
540 | 540 | */ |
541 | 541 | function fieldgroup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
542 | 542 | switch ($op) { |
543 | - case 'view': |
|
544 | - // Prevent against invalid 'nodes' built by broken 3rd party code. |
|
545 | - if (isset($node->type)) { |
|
546 | - // Build the node content element needed to render each fieldgroup. |
|
547 | - foreach (fieldgroup_groups($node->type) as $group) { |
|
548 | - fieldgroup_build_content($group, $node, $teaser, $page); |
|
549 | - } |
|
543 | + case 'view': |
|
544 | + // Prevent against invalid 'nodes' built by broken 3rd party code. |
|
545 | + if (isset($node->type)) { |
|
546 | + // Build the node content element needed to render each fieldgroup. |
|
547 | + foreach (fieldgroup_groups($node->type) as $group) { |
|
548 | + fieldgroup_build_content($group, $node, $teaser, $page); |
|
550 | 549 | } |
551 | - break; |
|
550 | + } |
|
551 | + break; |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
@@ -591,22 +591,22 @@ discard block |
||
591 | 591 | $format = isset($group['settings']['display'][$context]['format']) ? $group['settings']['display'][$context]['format'] : 'fieldset'; |
592 | 592 | |
593 | 593 | switch ($format) { |
594 | - case 'simple': |
|
595 | - $element['#type'] = 'fieldgroup_simple'; |
|
596 | - $element['#group_name'] = $group_name; |
|
597 | - $element['#node'] = $node; |
|
598 | - break; |
|
599 | - case 'hidden': |
|
600 | - $element['#access'] = FALSE; |
|
601 | - break; |
|
602 | - case 'fieldset_collapsed': |
|
603 | - $element['#collapsed'] = TRUE; |
|
604 | - case 'fieldset_collapsible': |
|
605 | - $element['#collapsible'] = TRUE; |
|
606 | - case 'fieldset': |
|
607 | - $element['#type'] = 'fieldgroup_fieldset'; |
|
608 | - $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
|
609 | - break; |
|
594 | + case 'simple': |
|
595 | + $element['#type'] = 'fieldgroup_simple'; |
|
596 | + $element['#group_name'] = $group_name; |
|
597 | + $element['#node'] = $node; |
|
598 | + break; |
|
599 | + case 'hidden': |
|
600 | + $element['#access'] = FALSE; |
|
601 | + break; |
|
602 | + case 'fieldset_collapsed': |
|
603 | + $element['#collapsed'] = TRUE; |
|
604 | + case 'fieldset_collapsible': |
|
605 | + $element['#collapsible'] = TRUE; |
|
606 | + case 'fieldset': |
|
607 | + $element['#type'] = 'fieldgroup_fieldset'; |
|
608 | + $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
|
609 | + break; |
|
610 | 610 | } |
611 | 611 | foreach ($group['fields'] as $field_name => $field) { |
612 | 612 | if (isset($node->content[$field_name])) { |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * Implementation of hook_init(). |
17 | 17 | */ |
18 | 18 | function fieldgroup_init() { |
19 | - drupal_add_css(drupal_get_path('module', 'fieldgroup') .'/fieldgroup.css'); |
|
19 | + drupal_add_css(drupal_get_path('module', 'fieldgroup').'/fieldgroup.css'); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | function fieldgroup_ctools_plugin_directory($module, $plugin) { |
26 | 26 | if ($module == 'ctools' && $plugin == 'content_types') { |
27 | - return 'panels/' . $plugin; |
|
27 | + return 'panels/'.$plugin; |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | $type_name = $type->type; |
42 | 42 | $content_type = content_types($type_name); |
43 | 43 | $type_url_str = $content_type['url_str']; |
44 | - $items['admin/content/node-type/'. $type_url_str .'/groups/%'] = array( |
|
44 | + $items['admin/content/node-type/'.$type_url_str.'/groups/%'] = array( |
|
45 | 45 | 'title' => 'Edit group', |
46 | 46 | 'page callback' => 'drupal_get_form', |
47 | 47 | 'page arguments' => array('fieldgroup_group_edit_form', $type_name, 5), |
48 | 48 | 'access arguments' => array('administer content types'), |
49 | 49 | 'type' => MENU_CALLBACK, |
50 | 50 | ); |
51 | - $items['admin/content/node-type/'. $type_url_str .'/groups/%/remove'] = array( |
|
51 | + $items['admin/content/node-type/'.$type_url_str.'/groups/%/remove'] = array( |
|
52 | 52 | 'title' => 'Edit group', |
53 | 53 | 'page callback' => 'drupal_get_form', |
54 | 54 | 'page arguments' => array('fieldgroup_remove_group', $type_name, 5), |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | function fieldgroup_content_fieldapi($op, $field) { |
95 | 95 | switch ($op) { |
96 | 96 | case 'delete instance': |
97 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
|
97 | + db_query("DELETE FROM {".fieldgroup_fields_tablename()."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
|
98 | 98 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
99 | 99 | break; |
100 | 100 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $form_values = $form_state['values']; |
183 | 183 | $content_type = $form['#content_type']; |
184 | 184 | fieldgroup_save_group($content_type['type'], $form_values); |
185 | - $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
185 | + $form_state['redirect'] = 'admin/content/node-type/'.$content_type['url_str'].'/fields'; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | function fieldgroup_remove_group(&$form_state, $type_name, $group_name) { |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | return confirm_form($form, |
203 | 203 | t('Are you sure you want to remove the group %label?', |
204 | 204 | array('%label' => t($group['label']))), |
205 | - 'admin/content/node-type/'. $content_type['url_str'] .'/fields', t('This action cannot be undone.'), |
|
205 | + 'admin/content/node-type/'.$content_type['url_str'].'/fields', t('This action cannot be undone.'), |
|
206 | 206 | t('Remove'), t('Cancel')); |
207 | 207 | } |
208 | 208 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $group_name = $form['#group_name']; |
213 | 213 | fieldgroup_delete($content_type['type'], $group_name); |
214 | 214 | drupal_set_message(t('The group %group_name has been removed.', array('%group_name' => $group_name))); |
215 | - $form_state['redirect'] = 'admin/content/node-type/'. $content_type['url_str'] .'/fields'; |
|
215 | + $form_state['redirect'] = 'admin/content/node-type/'.$content_type['url_str'].'/fields'; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -222,13 +222,13 @@ discard block |
||
222 | 222 | global $language; |
223 | 223 | static $groups, $groups_sorted; |
224 | 224 | if (!isset($groups) || $reset) { |
225 | - if ($cached = cache_get('fieldgroup_data:'. $language->language, content_cache_tablename())) { |
|
225 | + if ($cached = cache_get('fieldgroup_data:'.$language->language, content_cache_tablename())) { |
|
226 | 226 | $data = $cached->data; |
227 | 227 | $groups = $data['groups']; |
228 | 228 | $groups_sorted = $data['groups_sorted']; |
229 | 229 | } |
230 | 230 | else { |
231 | - $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name"); |
|
231 | + $result = db_query("SELECT * FROM {".fieldgroup_tablename()."} ORDER BY weight, group_name"); |
|
232 | 232 | $groups = array(); |
233 | 233 | $groups_sorted = array(); |
234 | 234 | while ($group = db_fetch_array($result)) { |
@@ -250,9 +250,9 @@ discard block |
||
250 | 250 | $groups_sorted[$group['type_name']][] = &$groups[$group['type_name']][$group['group_name']]; |
251 | 251 | } |
252 | 252 | //load fields |
253 | - $result = db_query("SELECT nfi.*, ng.group_name FROM {". fieldgroup_tablename() ."} ng ". |
|
254 | - "INNER JOIN {". fieldgroup_fields_tablename() ."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ". |
|
255 | - "INNER JOIN {". content_instance_tablename() ."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ". |
|
253 | + $result = db_query("SELECT nfi.*, ng.group_name FROM {".fieldgroup_tablename()."} ng ". |
|
254 | + "INNER JOIN {".fieldgroup_fields_tablename()."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ". |
|
255 | + "INNER JOIN {".content_instance_tablename()."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ". |
|
256 | 256 | "WHERE nfi.widget_active = 1 ORDER BY nfi.weight"); |
257 | 257 | while ($field = db_fetch_array($result)) { |
258 | 258 | // Allow external modules to translate field strings. |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | |
267 | 267 | $groups[$field['type_name']][$field['group_name']]['fields'][$field['field_name']] = $field; |
268 | 268 | } |
269 | - cache_set('fieldgroup_data:'. $language->language, array('groups' => $groups, 'groups_sorted' => $groups_sorted), content_cache_tablename()); |
|
269 | + cache_set('fieldgroup_data:'.$language->language, array('groups' => $groups, 'groups_sorted' => $groups_sorted), content_cache_tablename()); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | if (empty($content_type)) { |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | function _fieldgroup_groups_label($content_type) { |
283 | 283 | $groups = fieldgroup_groups($content_type); |
284 | 284 | |
285 | - $labels[''] = '<'. t('none') .'>'; |
|
285 | + $labels[''] = '<'.t('none').'>'; |
|
286 | 286 | foreach ($groups as $group_name => $group) { |
287 | 287 | $labels[$group_name] = t($group['label']); |
288 | 288 | } |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | } |
291 | 291 | |
292 | 292 | function _fieldgroup_field_get_group($content_type, $field_name) { |
293 | - return db_result(db_query("SELECT group_name FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name)); |
|
293 | + return db_result(db_query("SELECT group_name FROM {".fieldgroup_fields_tablename()."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name)); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | 297 | * Implementation of hook_form_alter() |
298 | 298 | */ |
299 | 299 | function fieldgroup_form_alter(&$form, $form_state, $form_id) { |
300 | - if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
300 | + if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'].'_node_form' == $form_id) { |
|
301 | 301 | foreach (fieldgroup_groups($form['type']['#value']) as $group_name => $group) { |
302 | 302 | $form[$group_name] = array( |
303 | 303 | '#type' => 'fieldset', |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | // Can't use module_invoke_all because we want |
335 | 335 | // to be able to use a reference to $form and $form_state. |
336 | 336 | foreach (module_implements('fieldgroup_form') as $module) { |
337 | - $function = $module .'_fieldgroup_form'; |
|
337 | + $function = $module.'_fieldgroup_form'; |
|
338 | 338 | $function($form, $form_state, $form_id, $group); |
339 | 339 | } |
340 | 340 | |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | |
390 | 390 | // Add the 'group_' prefix. |
391 | 391 | if (substr($group_name, 0, 6) != 'group_') { |
392 | - $group_name = 'group_'. $group_name; |
|
392 | + $group_name = 'group_'.$group_name; |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | // Invalid field name. |
@@ -422,10 +422,10 @@ discard block |
||
422 | 422 | foreach ($validation['errors'] as $type => $messages) { |
423 | 423 | foreach ($messages as $message) { |
424 | 424 | if ($type == 'label') { |
425 | - form_set_error('_add_new_group][label', t('Add new group:') .' '. $message); |
|
425 | + form_set_error('_add_new_group][label', t('Add new group:').' '.$message); |
|
426 | 426 | } |
427 | 427 | else { |
428 | - form_set_error('_add_new_group][group_name', t('Add new group:') .' '. $message); |
|
428 | + form_set_error('_add_new_group][group_name', t('Add new group:').' '.$message); |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | } |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | // If 'group' row: update groups weights |
491 | 491 | // (possible newly created group has already been taken care of). |
492 | 492 | elseif (in_array($key, $form['#groups'])) { |
493 | - db_query("UPDATE {". fieldgroup_tablename() ."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'", |
|
493 | + db_query("UPDATE {".fieldgroup_tablename()."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'", |
|
494 | 494 | $values['weight'], $type_name, $key); |
495 | 495 | } |
496 | 496 | } |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | // - when a (non last) field is removed from a group, a 'ghost row' remains in the fields overview |
533 | 533 | // - when the last field is removed, the group disappears |
534 | 534 | // seems to be fixed when emptying the cache. |
535 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
535 | + db_query("DELETE FROM {".fieldgroup_fields_tablename()."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | $element['#collapsible'] = TRUE; |
606 | 606 | case 'fieldset': |
607 | 607 | $element['#type'] = 'fieldgroup_fieldset'; |
608 | - $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
|
608 | + $element['#attributes'] = array('class' => 'fieldgroup '.strtr($group['group_name'], '_', '-')); |
|
609 | 609 | break; |
610 | 610 | } |
611 | 611 | foreach ($group['fields'] as $field_name => $field) { |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | // Can't use module_invoke_all because we want |
619 | 619 | // to be able to use a reference to $node and $element. |
620 | 620 | foreach (module_implements('fieldgroup_view') as $module) { |
621 | - $function = $module .'_fieldgroup_view'; |
|
621 | + $function = $module.'_fieldgroup_view'; |
|
622 | 622 | $function($node, $element, $group, $context); |
623 | 623 | } |
624 | 624 | |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | |
696 | 696 | // One-field equivalent to _content_field_invoke('sanitize'). |
697 | 697 | $module = $field_types[$field['type']]['module']; |
698 | - $function = $module .'_field'; |
|
698 | + $function = $module.'_field'; |
|
699 | 699 | if (function_exists($function)) { |
700 | 700 | $function('sanitize', $node_copy, $field, $items, $teaser, $page); |
701 | 701 | $node_copy->{$field_name} = $items; |
@@ -755,13 +755,13 @@ discard block |
||
755 | 755 | function fieldgroup_node_type($op, $info) { |
756 | 756 | if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) { |
757 | 757 | // update the tables |
758 | - db_query("UPDATE {". fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
|
759 | - db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
|
758 | + db_query("UPDATE {".fieldgroup_tablename()."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
|
759 | + db_query("UPDATE {".fieldgroup_fields_tablename()."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
|
760 | 760 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
761 | 761 | } |
762 | 762 | elseif ($op == 'delete') { |
763 | - db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type); |
|
764 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s'", $info->type); |
|
763 | + db_query("DELETE FROM {".fieldgroup_tablename()."} WHERE type_name = '%s'", $info->type); |
|
764 | + db_query("DELETE FROM {".fieldgroup_fields_tablename()."} WHERE type_name = '%s'", $info->type); |
|
765 | 765 | } |
766 | 766 | } |
767 | 767 | |
@@ -800,19 +800,19 @@ discard block |
||
800 | 800 | |
801 | 801 | // Allow other modules to intervene when the group is saved. |
802 | 802 | foreach (module_implements('fieldgroup_save_group') as $module) { |
803 | - $function = $module .'_fieldgroup_save_group'; |
|
803 | + $function = $module.'_fieldgroup_save_group'; |
|
804 | 804 | $function($group); |
805 | 805 | } |
806 | 806 | |
807 | 807 | if (!isset($groups[$group['group_name']])) { |
808 | 808 | // Accept group name from programmed submissions if valid. |
809 | - db_query("INSERT INTO {". fieldgroup_tablename() ."} (group_type, type_name, group_name, label, settings, weight)". |
|
809 | + db_query("INSERT INTO {".fieldgroup_tablename()."} (group_type, type_name, group_name, label, settings, weight)". |
|
810 | 810 | " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']); |
811 | 811 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
812 | 812 | return SAVED_NEW; |
813 | 813 | } |
814 | 814 | else { |
815 | - db_query("UPDATE {". fieldgroup_tablename() ."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ". |
|
815 | + db_query("UPDATE {".fieldgroup_tablename()."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ". |
|
816 | 816 | "WHERE type_name = '%s' AND group_name = '%s'", |
817 | 817 | $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); |
818 | 818 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
@@ -825,21 +825,21 @@ discard block |
||
825 | 825 | |
826 | 826 | if ($default != $form_values['group']) { |
827 | 827 | if ($form_values['group'] && !$default) { |
828 | - db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); |
|
828 | + db_query("INSERT INTO {".fieldgroup_fields_tablename()."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); |
|
829 | 829 | } |
830 | 830 | elseif ($form_values['group']) { |
831 | - db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); |
|
831 | + db_query("UPDATE {".fieldgroup_fields_tablename()."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); |
|
832 | 832 | } |
833 | 833 | else { |
834 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
834 | + db_query("DELETE FROM {".fieldgroup_fields_tablename()."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
|
835 | 835 | } |
836 | 836 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | 840 | function fieldgroup_delete($content_type, $group_name) { |
841 | - db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
842 | - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
841 | + db_query("DELETE FROM {".fieldgroup_tablename()."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
842 | + db_query("DELETE FROM {".fieldgroup_fields_tablename()."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
|
843 | 843 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
844 | 844 | } |
845 | 845 | |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | $element['#attributes']['class'] .= ' collapsed'; |
866 | 866 | } |
867 | 867 | } |
868 | - return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n"; |
|
868 | + return '<fieldset'.drupal_attributes($element['#attributes']).'>'.($element['#title'] ? '<legend>'.$element['#title'].'</legend>' : '').(isset($element['#description']) && $element['#description'] ? '<div class="description">'.$element['#description'].'</div>' : '').(!empty($element['#children']) ? $element['#children'] : '').(isset($element['#value']) ? $element['#value'] : '')."</fieldset>\n"; |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | |
@@ -886,14 +886,14 @@ discard block |
||
886 | 886 | |
887 | 887 | $vars['group_name'] = $element['#group_name']; |
888 | 888 | $vars['group_name_css'] = strtr($element['#group_name'], '_', '-'); |
889 | - $vars['label'] = isset($element['#title']) ? $element['#title'] : '';; |
|
890 | - $vars['description'] = isset($element['#description']) ? $element['#description'] : '';; |
|
889 | + $vars['label'] = isset($element['#title']) ? $element['#title'] : ''; ; |
|
890 | + $vars['description'] = isset($element['#description']) ? $element['#description'] : ''; ; |
|
891 | 891 | $vars['content'] = isset($element['#children']) ? $element['#children'] : ''; |
892 | 892 | $vars['template_files'] = array( |
893 | 893 | 'fieldgroup-simple-', |
894 | - 'fieldgroup-simple-'. $element['#group_name'], |
|
895 | - 'fieldgroup-simple-'. $element['#node']->type, |
|
896 | - 'fieldgroup-simple-'. $element['#group_name'] .'-'. $element['#node']->type, |
|
894 | + 'fieldgroup-simple-'.$element['#group_name'], |
|
895 | + 'fieldgroup-simple-'.$element['#node']->type, |
|
896 | + 'fieldgroup-simple-'.$element['#group_name'].'-'.$element['#node']->type, |
|
897 | 897 | ); |
898 | 898 | } |
899 | 899 | |
@@ -908,6 +908,6 @@ discard block |
||
908 | 908 | |
909 | 909 | foreach (fieldgroup_groups($node->type) as $group_name => $group) { |
910 | 910 | // '#chilren' might not be set if the group is empty. |
911 | - $vars[$group_name .'_rendered'] = isset($node->content[$group_name]['#children']) ? $node->content[$group_name]['#children'] : ''; |
|
911 | + $vars[$group_name.'_rendered'] = isset($node->content[$group_name]['#children']) ? $node->content[$group_name]['#children'] : ''; |
|
912 | 912 | } |
913 | 913 | } |
@@ -226,8 +226,7 @@ discard block |
||
226 | 226 | $data = $cached->data; |
227 | 227 | $groups = $data['groups']; |
228 | 228 | $groups_sorted = $data['groups_sorted']; |
229 | - } |
|
230 | - else { |
|
229 | + } else { |
|
231 | 230 | $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name"); |
232 | 231 | $groups = array(); |
233 | 232 | $groups_sorted = array(); |
@@ -271,8 +270,7 @@ discard block |
||
271 | 270 | } |
272 | 271 | if (empty($content_type)) { |
273 | 272 | return $groups; |
274 | - } |
|
275 | - elseif (empty($groups) || empty($groups[$content_type])) { |
|
273 | + } elseif (empty($groups) || empty($groups[$content_type])) { |
|
276 | 274 | return array(); |
277 | 275 | } |
278 | 276 | return $sorted ? $groups_sorted[$content_type] : $groups[$content_type]; |
@@ -349,18 +347,15 @@ discard block |
||
349 | 347 | '#type' => 'value', |
350 | 348 | '#value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']), |
351 | 349 | ); |
352 | - } |
|
353 | - elseif ($form_id == 'content_field_overview_form') { |
|
350 | + } elseif ($form_id == 'content_field_overview_form') { |
|
354 | 351 | $form['#validate'][] = 'fieldgroup_field_overview_form_validate'; |
355 | 352 | $form['#submit'][] = 'fieldgroup_field_overview_form_submit'; |
356 | - } |
|
357 | - elseif ($form_id == 'content_display_overview_form' && !empty($form['#groups'])) { |
|
353 | + } elseif ($form_id == 'content_display_overview_form' && !empty($form['#groups'])) { |
|
358 | 354 | $form['#submit'][] = 'fieldgroup_display_overview_form_submit'; |
359 | 355 | if (!isset($form['submit'])) { |
360 | 356 | $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 10); |
361 | 357 | } |
362 | - } |
|
363 | - elseif ($form_id == 'content_field_remove_form') { |
|
358 | + } elseif ($form_id == 'content_field_remove_form') { |
|
364 | 359 | $form['#submit'][] = 'fieldgroup_field_remove_form_submit'; |
365 | 360 | } |
366 | 361 | } |
@@ -423,8 +418,7 @@ discard block |
||
423 | 418 | foreach ($messages as $message) { |
424 | 419 | if ($type == 'label') { |
425 | 420 | form_set_error('_add_new_group][label', t('Add new group:') .' '. $message); |
426 | - } |
|
427 | - else { |
|
421 | + } else { |
|
428 | 422 | form_set_error('_add_new_group][group_name', t('Add new group:') .' '. $message); |
429 | 423 | } |
430 | 424 | } |
@@ -432,8 +426,7 @@ discard block |
||
432 | 426 | } |
433 | 427 | $group_name = $validation['group_name']; |
434 | 428 | form_set_value($form['_add_new_group']['group_name'], $group_name, $form_state); |
435 | - } |
|
436 | - else { |
|
429 | + } else { |
|
437 | 430 | // Fail validation if attempt to nest fields under a new group without the |
438 | 431 | // proper information. Not raising an error would cause the nested fields |
439 | 432 | // to get weights the user doesn't expect. |
@@ -474,8 +467,7 @@ discard block |
||
474 | 467 | // in $form_state['fields_added'] for us. |
475 | 468 | if (isset($form_state['fields_added'][$key])) { |
476 | 469 | $key = $form_state['fields_added'][$key]; |
477 | - } |
|
478 | - else { |
|
470 | + } else { |
|
479 | 471 | // No field was actually created : skip to next row. |
480 | 472 | continue; |
481 | 473 | } |
@@ -572,8 +564,7 @@ discard block |
||
572 | 564 | // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
573 | 565 | if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
574 | 566 | $context = $teaser ? 'teaser' : 'full'; |
575 | - } |
|
576 | - else { |
|
567 | + } else { |
|
577 | 568 | $context = $node->build_mode; |
578 | 569 | } |
579 | 570 | |
@@ -758,8 +749,7 @@ discard block |
||
758 | 749 | db_query("UPDATE {". fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
759 | 750 | db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
760 | 751 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
761 | - } |
|
762 | - elseif ($op == 'delete') { |
|
752 | + } elseif ($op == 'delete') { |
|
763 | 753 | db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type); |
764 | 754 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s'", $info->type); |
765 | 755 | } |
@@ -810,8 +800,7 @@ discard block |
||
810 | 800 | " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']); |
811 | 801 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
812 | 802 | return SAVED_NEW; |
813 | - } |
|
814 | - else { |
|
803 | + } else { |
|
815 | 804 | db_query("UPDATE {". fieldgroup_tablename() ."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ". |
816 | 805 | "WHERE type_name = '%s' AND group_name = '%s'", |
817 | 806 | $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); |
@@ -826,11 +815,9 @@ discard block |
||
826 | 815 | if ($default != $form_values['group']) { |
827 | 816 | if ($form_values['group'] && !$default) { |
828 | 817 | db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); |
829 | - } |
|
830 | - elseif ($form_values['group']) { |
|
818 | + } elseif ($form_values['group']) { |
|
831 | 819 | db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); |
832 | - } |
|
833 | - else { |
|
820 | + } else { |
|
834 | 821 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
835 | 822 | } |
836 | 823 | cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | return array( |
68 | 68 | 'fieldgroup_simple' => array( |
69 | 69 | 'template' => 'fieldgroup-simple', |
70 | - 'arguments' => array('element' => NULL), |
|
70 | + 'arguments' => array('element' => null), |
|
71 | 71 | ), |
72 | 72 | 'fieldgroup_fieldset' => array( |
73 | - 'arguments' => array('element' => NULL), |
|
73 | + 'arguments' => array('element' => null), |
|
74 | 74 | ), |
75 | 75 | 'fieldgroup_display_overview_form' => array( |
76 | - 'arguments' => array('form' => NULL), |
|
76 | + 'arguments' => array('form' => null), |
|
77 | 77 | ), |
78 | 78 | ); |
79 | 79 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | function fieldgroup_elements() { |
85 | 85 | return array( |
86 | 86 | 'fieldgroup_simple' => array(), |
87 | - 'fieldgroup_fieldset' => array('#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL,), |
|
87 | + 'fieldgroup_fieldset' => array('#collapsible' => false, '#collapsed' => false, '#value' => null,), |
|
88 | 88 | ); |
89 | 89 | } |
90 | 90 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | switch ($op) { |
96 | 96 | case 'delete instance': |
97 | 97 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
98 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
98 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
99 | 99 | break; |
100 | 100 | } |
101 | 101 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | '#type' => 'textfield', |
114 | 114 | '#title' => t('Label'), |
115 | 115 | '#default_value' => $group['label'], |
116 | - '#required' => TRUE, |
|
116 | + '#required' => true, |
|
117 | 117 | ); |
118 | 118 | |
119 | 119 | // Set a default value for group type early in the form so it |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | $group_type = !empty($group['group_type']) ? $group['group_type'] : 'standard'; |
122 | 122 | $form['group_type'] = array('#type' => 'hidden', '#default_value' => $group_type); |
123 | 123 | |
124 | - $form['settings']['#tree'] = TRUE; |
|
124 | + $form['settings']['#tree'] = true; |
|
125 | 125 | $form['settings']['form'] = array( |
126 | 126 | '#type' => 'fieldset', |
127 | 127 | '#title' => t('Form settings'), |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | '#default_value' => $group['settings']['form']['description'], |
144 | 144 | '#rows' => 5, |
145 | 145 | '#description' => t('Instructions to present to the user on the editing form.'), |
146 | - '#required' => FALSE, |
|
146 | + '#required' => false, |
|
147 | 147 | ); |
148 | 148 | $form['settings']['display'] = array( |
149 | 149 | '#type' => 'fieldset', |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | '#default_value' => $group['settings']['display']['description'], |
157 | 157 | '#rows' => 5, |
158 | 158 | '#description' => t('A description of the group.'), |
159 | - '#required' => FALSE, |
|
159 | + '#required' => false, |
|
160 | 160 | ); |
161 | 161 | |
162 | 162 | foreach (array_keys(content_build_modes()) as $key) { |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | /** |
219 | 219 | * Returns all groups for a content type |
220 | 220 | */ |
221 | -function fieldgroup_groups($content_type = '', $sorted = FALSE, $reset = FALSE) { |
|
221 | +function fieldgroup_groups($content_type = '', $sorted = false, $reset = false) { |
|
222 | 222 | global $language; |
223 | 223 | static $groups, $groups_sorted; |
224 | 224 | if (!isset($groups) || $reset) { |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | '#attributes' => array('class' => strtr($group['group_name'], '_', '-')), |
310 | 310 | ); |
311 | 311 | |
312 | - $has_accessible_field = FALSE; |
|
312 | + $has_accessible_field = false; |
|
313 | 313 | foreach ($group['fields'] as $field_name => $field) { |
314 | 314 | if (isset($form[$field_name])) { |
315 | 315 | $form[$group_name][$field_name] = $form[$field_name]; |
316 | 316 | // Track whether this group has any accessible fields within it. |
317 | - if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== FALSE) { |
|
318 | - $has_accessible_field = TRUE; |
|
317 | + if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== false) { |
|
318 | + $has_accessible_field = true; |
|
319 | 319 | } |
320 | 320 | unset($form[$field_name]); |
321 | 321 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | if (!$has_accessible_field) { |
329 | 329 | // Hide the fieldgroup, because the fields are inaccessible. |
330 | - $form[$group_name]['#access'] = FALSE; |
|
330 | + $form[$group_name]['#access'] = false; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | // Allow other modules to alter the form. |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | } |
496 | 496 | } |
497 | 497 | |
498 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
498 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | function field_group_default_settings($group_type) { |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | /** |
539 | 539 | * Implementation of hook_nodeapi(). |
540 | 540 | */ |
541 | -function fieldgroup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
|
541 | +function fieldgroup_nodeapi(&$node, $op, $teaser = null, $page = null) { |
|
542 | 542 | switch ($op) { |
543 | 543 | case 'view': |
544 | 544 | // Prevent against invalid 'nodes' built by broken 3rd party code. |
@@ -597,12 +597,12 @@ discard block |
||
597 | 597 | $element['#node'] = $node; |
598 | 598 | break; |
599 | 599 | case 'hidden': |
600 | - $element['#access'] = FALSE; |
|
600 | + $element['#access'] = false; |
|
601 | 601 | break; |
602 | 602 | case 'fieldset_collapsed': |
603 | - $element['#collapsed'] = TRUE; |
|
603 | + $element['#collapsed'] = true; |
|
604 | 604 | case 'fieldset_collapsible': |
605 | - $element['#collapsible'] = TRUE; |
|
605 | + $element['#collapsible'] = true; |
|
606 | 606 | case 'fieldset': |
607 | 607 | $element['#type'] = 'fieldgroup_fieldset'; |
608 | 608 | $element['#attributes'] = array('class' => 'fieldgroup '. strtr($group['group_name'], '_', '-')); |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | * |
674 | 674 | * @see content_view_field() |
675 | 675 | */ |
676 | -function fieldgroup_view_group($group, &$node, $teaser = FALSE, $page = FALSE) { |
|
676 | +function fieldgroup_view_group($group, &$node, $teaser = false, $page = false) { |
|
677 | 677 | $group_name = $group['group_name']; |
678 | 678 | $field_types = _content_field_types(); |
679 | 679 | |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | return $group_name; |
746 | 746 | } |
747 | 747 | } |
748 | - return FALSE; |
|
748 | + return false; |
|
749 | 749 | } |
750 | 750 | |
751 | 751 | /** |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | // update the tables |
758 | 758 | db_query("UPDATE {". fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
759 | 759 | db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); |
760 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
760 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
761 | 761 | } |
762 | 762 | elseif ($op == 'delete') { |
763 | 763 | db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type); |
@@ -772,14 +772,14 @@ discard block |
||
772 | 772 | return $types; |
773 | 773 | } |
774 | 774 | |
775 | -function fieldgroup_tablename($version = NULL) { |
|
775 | +function fieldgroup_tablename($version = null) { |
|
776 | 776 | if (is_null($version)) { |
777 | 777 | $version = variable_get('fieldgroup_schema_version', 0); |
778 | 778 | } |
779 | 779 | return $version < 6000 ? 'node_group' : 'content_group'; |
780 | 780 | } |
781 | 781 | |
782 | -function fieldgroup_fields_tablename($version = NULL) { |
|
782 | +function fieldgroup_fields_tablename($version = null) { |
|
783 | 783 | if (is_null($version)) { |
784 | 784 | $version = variable_get('fieldgroup_schema_version', 0); |
785 | 785 | } |
@@ -808,14 +808,14 @@ discard block |
||
808 | 808 | // Accept group name from programmed submissions if valid. |
809 | 809 | db_query("INSERT INTO {". fieldgroup_tablename() ."} (group_type, type_name, group_name, label, settings, weight)". |
810 | 810 | " VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $group['group_type'], $type_name, $group['group_name'], $group['label'], serialize($group['settings']), $group['weight']); |
811 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
811 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
812 | 812 | return SAVED_NEW; |
813 | 813 | } |
814 | 814 | else { |
815 | 815 | db_query("UPDATE {". fieldgroup_tablename() ."} SET group_type = '%s', label = '%s', settings = '%s', weight = %d ". |
816 | 816 | "WHERE type_name = '%s' AND group_name = '%s'", |
817 | 817 | $group['group_type'], $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); |
818 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
818 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
819 | 819 | return SAVED_UPDATED; |
820 | 820 | } |
821 | 821 | } |
@@ -833,14 +833,14 @@ discard block |
||
833 | 833 | else { |
834 | 834 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); |
835 | 835 | } |
836 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
836 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | 840 | function fieldgroup_delete($content_type, $group_name) { |
841 | 841 | db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
842 | 842 | db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); |
843 | - cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE); |
|
843 | + cache_clear_all('fieldgroup_data:', content_cache_tablename(), true); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
@@ -10,37 +10,37 @@ discard block |
||
10 | 10 | * Implementation of hook_rules_action_info(). |
11 | 11 | */ |
12 | 12 | function nodereference_rules_action_info() { |
13 | - $info = array(); |
|
14 | - $info['nodereference_rules_action_load'] = array( |
|
13 | + $info = array(); |
|
14 | + $info['nodereference_rules_action_load'] = array( |
|
15 | 15 | 'label' => t('Load a referenced node'), |
16 | 16 | 'arguments' => array( |
17 | - 'node' => array( |
|
17 | + 'node' => array( |
|
18 | 18 | 'type' => 'node', |
19 | 19 | 'label' => t('Content containing the node reference field'), |
20 | - ), |
|
20 | + ), |
|
21 | 21 | ), |
22 | 22 | 'new variables' => array( |
23 | - 'referenced_node' => array( |
|
23 | + 'referenced_node' => array( |
|
24 | 24 | 'type' => 'node', |
25 | 25 | 'label' => t('Referenced content'), |
26 | - ), |
|
26 | + ), |
|
27 | 27 | ), |
28 | 28 | 'module' => 'CCK', |
29 | 29 | 'help' => t('Note that if the field has multiple values, only the first content node will be loaded.'), |
30 | - ); |
|
31 | - return $info; |
|
30 | + ); |
|
31 | + return $info; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | function nodereference_rules_action_load($node, $settings) { |
35 | - if ($nid = $node->{$settings['field']}[0]['nid']) { |
|
35 | + if ($nid = $node->{$settings['field']}[0]['nid']) { |
|
36 | 36 | return array('referenced_node' => node_load(array('nid' => $nid))); |
37 | - } |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | function nodereference_rules_action_load_form($settings, &$form) { |
41 | - $settings += array('field' => ''); |
|
42 | - $options = content_rules_get_field_names_by_type('nodereference'); |
|
43 | - $form['settings']['field'] = array( |
|
41 | + $settings += array('field' => ''); |
|
42 | + $options = content_rules_get_field_names_by_type('nodereference'); |
|
43 | + $form['settings']['field'] = array( |
|
44 | 44 | '#type' => 'select', |
45 | 45 | '#title' => t('Field'), |
46 | 46 | '#default_value' => $settings['field'], |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | '#required' => TRUE, |
49 | 49 | '#disabled' => empty($options), |
50 | 50 | '#description' => empty($options) ? t('There are no nodereference fields defined.') : '', |
51 | - ); |
|
51 | + ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -56,5 +56,5 @@ discard block |
||
56 | 56 | * "workflow_ng_action_load_referenced_node" to the equivalent rules action. |
57 | 57 | */ |
58 | 58 | function workflow_ng_action_load_referenced_node_upgrade(&$element) { |
59 | - $element['#name'] = 'nodereference_rules_action_load'; |
|
59 | + $element['#name'] = 'nodereference_rules_action_load'; |
|
60 | 60 | } |
@@ -45,7 +45,7 @@ |
||
45 | 45 | '#title' => t('Field'), |
46 | 46 | '#default_value' => $settings['field'], |
47 | 47 | '#options' => $options, |
48 | - '#required' => TRUE, |
|
48 | + '#required' => true, |
|
49 | 49 | '#disabled' => empty($options), |
50 | 50 | '#description' => empty($options) ? t('There are no nodereference fields defined.') : '', |
51 | 51 | ); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * Implementation of hook_ctools_relationships(). |
11 | 11 | */ |
12 | 12 | function nodereference_node_from_noderef_ctools_relationships() { |
13 | - return array( |
|
13 | + return array( |
|
14 | 14 | 'title' => t('Node from reference'), |
15 | 15 | 'keyword' => 'nodereference', |
16 | 16 | 'description' => t('Adds a node from a node reference in a node context; if multiple nodes are referenced, this will get the first referenced node only.'), |
@@ -18,59 +18,59 @@ discard block |
||
18 | 18 | 'context' => 'nodereference_node_from_noderef_context', |
19 | 19 | 'settings form' => 'nodereference_node_from_noderef_settings_form', |
20 | 20 | 'settings form validate' => 'nodereference_node_from_noderef_settings_form_validate', |
21 | - ); |
|
21 | + ); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Return a new ctools context based on an existing context. |
26 | 26 | */ |
27 | 27 | function nodereference_node_from_noderef_context($context, $conf) { |
28 | - $field = content_fields($conf['field_name']); |
|
28 | + $field = content_fields($conf['field_name']); |
|
29 | 29 | |
30 | - // If unset it wants a generic, unfilled context, which is just NULL. |
|
31 | - if (empty($context->data)) { |
|
30 | + // If unset it wants a generic, unfilled context, which is just NULL. |
|
31 | + if (empty($context->data)) { |
|
32 | 32 | $new_context = ctools_context_create_empty('node', NULL); |
33 | - } |
|
34 | - else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) { |
|
33 | + } |
|
34 | + else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) { |
|
35 | 35 | if ($node = node_load($nid)) { |
36 | - $new_context = ctools_context_create('node', $node); |
|
36 | + $new_context = ctools_context_create('node', $node); |
|
37 | + } |
|
37 | 38 | } |
38 | - } |
|
39 | 39 | |
40 | - if (!empty($new_context)) { |
|
40 | + if (!empty($new_context)) { |
|
41 | 41 | // Have nodereference relationships limit CCK field availability as well. |
42 | 42 | $restrictions = array_keys(array_filter($field['referenceable_types'])); |
43 | 43 | if ($restrictions) { |
44 | - if (isset($new_context->restrictions['type'])) { |
|
44 | + if (isset($new_context->restrictions['type'])) { |
|
45 | 45 | $new_context->restrictions['type'] = array_unique(array_merge($new_context->restrictions['type'], $restrictions)); |
46 | - } |
|
47 | - else { |
|
46 | + } |
|
47 | + else { |
|
48 | 48 | $new_context->restrictions['type'] = $restrictions; |
49 | - } |
|
49 | + } |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | return $new_context; |
53 | - } |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Settings form for the ctools relationship. |
58 | 58 | */ |
59 | 59 | function nodereference_node_from_noderef_settings_form($conf) { |
60 | - $options = array(); |
|
61 | - foreach (content_fields() as $field) { |
|
60 | + $options = array(); |
|
61 | + foreach (content_fields() as $field) { |
|
62 | 62 | if ($field['type'] == 'nodereference') { |
63 | - $options[$field['field_name']] = t($field['widget']['label']); |
|
63 | + $options[$field['field_name']] = t($field['widget']['label']); |
|
64 | + } |
|
64 | 65 | } |
65 | - } |
|
66 | - $form['field_name'] = array( |
|
66 | + $form['field_name'] = array( |
|
67 | 67 | '#title' => t('Node reference field'), |
68 | 68 | '#type' => 'select', |
69 | 69 | '#options' => $options, |
70 | 70 | '#default_value' => isset($conf['field_name']) ? $conf['field_name'] : '', |
71 | 71 | '#prefix' => '<div class="clear-block">', |
72 | 72 | '#suffix' => '</div>', |
73 | - ); |
|
73 | + ); |
|
74 | 74 | |
75 | - return $form; |
|
75 | + return $form; |
|
76 | 76 | } |
@@ -30,8 +30,7 @@ discard block |
||
30 | 30 | // If unset it wants a generic, unfilled context, which is just NULL. |
31 | 31 | if (empty($context->data)) { |
32 | 32 | $new_context = ctools_context_create_empty('node', NULL); |
33 | - } |
|
34 | - else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) { |
|
33 | + } else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) { |
|
35 | 34 | if ($node = node_load($nid)) { |
36 | 35 | $new_context = ctools_context_create('node', $node); |
37 | 36 | } |
@@ -43,8 +42,7 @@ discard block |
||
43 | 42 | if ($restrictions) { |
44 | 43 | if (isset($new_context->restrictions['type'])) { |
45 | 44 | $new_context->restrictions['type'] = array_unique(array_merge($new_context->restrictions['type'], $restrictions)); |
46 | - } |
|
47 | - else { |
|
45 | + } else { |
|
48 | 46 | $new_context->restrictions['type'] = $restrictions; |
49 | 47 | } |
50 | 48 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | // If unset it wants a generic, unfilled context, which is just NULL. |
31 | 31 | if (empty($context->data)) { |
32 | - $new_context = ctools_context_create_empty('node', NULL); |
|
32 | + $new_context = ctools_context_create_empty('node', null); |
|
33 | 33 | } |
34 | 34 | else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) { |
35 | 35 | if ($node = node_load($nid)) { |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * Implementation of hook_theme(). |
11 | 11 | */ |
12 | 12 | function number_theme() { |
13 | - return array( |
|
13 | + return array( |
|
14 | 14 | 'number' => array('arguments' => array('element' => NULL)), |
15 | 15 | 'number_formatter_default' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
16 | 16 | 'number_formatter_us_0' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
@@ -23,156 +23,156 @@ discard block |
||
23 | 23 | 'number_formatter_fr_1' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
24 | 24 | 'number_formatter_fr_2' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
25 | 25 | 'number_formatter_unformatted' => array('arguments' => array('element' => NULL)), |
26 | - ); |
|
26 | + ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Implementation of hook_field_info(). |
31 | 31 | */ |
32 | 32 | function number_field_info() { |
33 | - return array( |
|
33 | + return array( |
|
34 | 34 | 'number_integer' => array( |
35 | - 'label' => t('Integer'), |
|
36 | - 'description' => t('Store a number in the database as an integer.'), |
|
35 | + 'label' => t('Integer'), |
|
36 | + 'description' => t('Store a number in the database as an integer.'), |
|
37 | 37 | // 'content_icon' => 'icon_content_number.png', |
38 | 38 | ), |
39 | 39 | 'number_decimal' => array( |
40 | - 'label' => t('Decimal'), |
|
41 | - 'description' => t('Store a number in the database in a fixed decimal format.'), |
|
40 | + 'label' => t('Decimal'), |
|
41 | + 'description' => t('Store a number in the database in a fixed decimal format.'), |
|
42 | 42 | // 'content_icon' => 'icon_content_number.png', |
43 | 43 | ), |
44 | 44 | 'number_float' => array( |
45 | - 'label' => t('Float'), |
|
46 | - 'description' => t('Store a number in the database in a floating point format.'), |
|
45 | + 'label' => t('Float'), |
|
46 | + 'description' => t('Store a number in the database in a floating point format.'), |
|
47 | 47 | // 'content_icon' => 'icon_content_number.png', |
48 | 48 | ), |
49 | - ); |
|
49 | + ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Implementation of hook_field_settings(). |
54 | 54 | */ |
55 | 55 | function number_field_settings($op, $field) { |
56 | - switch ($op) { |
|
56 | + switch ($op) { |
|
57 | 57 | case 'form': |
58 | 58 | $form = array(); |
59 | - $form['min'] = array( |
|
59 | + $form['min'] = array( |
|
60 | 60 | '#type' => 'textfield', |
61 | 61 | '#title' => t('Minimum'), |
62 | 62 | '#element_validate' => array('_element_validate_number'), |
63 | 63 | '#default_value' => is_numeric($field['min']) ? $field['min'] : '', |
64 | - ); |
|
65 | - $form['max'] = array( |
|
64 | + ); |
|
65 | + $form['max'] = array( |
|
66 | 66 | '#type' => 'textfield', |
67 | 67 | '#title' => t('Maximum'), |
68 | 68 | '#element_validate' => array('_element_validate_number'), |
69 | 69 | '#default_value' => is_numeric($field['max']) ? $field['max'] : '', |
70 | - ); |
|
71 | - if ($field['type'] == 'number_decimal') { |
|
70 | + ); |
|
71 | + if ($field['type'] == 'number_decimal') { |
|
72 | 72 | $form['precision'] = array( |
73 | - '#type' => 'select', |
|
74 | - '#options' => drupal_map_assoc(range(10, 32)), |
|
75 | - '#title' => t('Precision'), |
|
76 | - '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), |
|
77 | - '#default_value' => is_numeric($field['precision']) ? $field['precision'] : 10, |
|
73 | + '#type' => 'select', |
|
74 | + '#options' => drupal_map_assoc(range(10, 32)), |
|
75 | + '#title' => t('Precision'), |
|
76 | + '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), |
|
77 | + '#default_value' => is_numeric($field['precision']) ? $field['precision'] : 10, |
|
78 | 78 | ); |
79 | 79 | $form['scale'] = array( |
80 | - '#type' => 'select', |
|
81 | - '#options' => drupal_map_assoc(range(0, 10)), |
|
82 | - '#title' => t('Scale'), |
|
83 | - '#description' => t('The number of digits to the right of the decimal.'), |
|
84 | - '#default_value' => is_numeric($field['scale']) ? $field['scale'] : 2, |
|
80 | + '#type' => 'select', |
|
81 | + '#options' => drupal_map_assoc(range(0, 10)), |
|
82 | + '#title' => t('Scale'), |
|
83 | + '#description' => t('The number of digits to the right of the decimal.'), |
|
84 | + '#default_value' => is_numeric($field['scale']) ? $field['scale'] : 2, |
|
85 | 85 | ); |
86 | 86 | $form['decimal'] = array( |
87 | - '#type' => 'select', |
|
88 | - '#options' => array('.' => 'decimal point', ',' => 'comma', ' ' => 'space'), |
|
89 | - '#title' => t('Decimal marker'), |
|
90 | - '#description' => t('The character users will input to mark the decimal point in forms.'), |
|
91 | - '#default_value' => !empty($field['decimal']) ? $field['decimal'] : '.', |
|
87 | + '#type' => 'select', |
|
88 | + '#options' => array('.' => 'decimal point', ',' => 'comma', ' ' => 'space'), |
|
89 | + '#title' => t('Decimal marker'), |
|
90 | + '#description' => t('The character users will input to mark the decimal point in forms.'), |
|
91 | + '#default_value' => !empty($field['decimal']) ? $field['decimal'] : '.', |
|
92 | 92 | ); |
93 | - } |
|
94 | - $form['append']['prefix'] = array( |
|
93 | + } |
|
94 | + $form['append']['prefix'] = array( |
|
95 | 95 | '#type' => 'textfield', |
96 | 96 | '#title' => t('Prefix'), |
97 | 97 | '#size' => 60, |
98 | 98 | '#default_value' => !empty($field['prefix']) ? $field['prefix'] : '', |
99 | 99 | '#description' => t('Define a string that should be prefixed to the value, like $ or €. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
100 | - ); |
|
101 | - $form['append']['suffix'] = array( |
|
100 | + ); |
|
101 | + $form['append']['suffix'] = array( |
|
102 | 102 | '#type' => 'textfield', |
103 | 103 | '#title' => t('Suffix'), |
104 | 104 | '#size' => 60, |
105 | 105 | '#default_value' => !empty($field['suffix']) ? $field['suffix'] : '', |
106 | 106 | '#description' => t('Define a string that should suffixed to the value, like m², m/s², kb/s. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
107 | - ); |
|
108 | - $form['allowed_values_fieldset'] = array( |
|
107 | + ); |
|
108 | + $form['allowed_values_fieldset'] = array( |
|
109 | 109 | '#type' => 'fieldset', |
110 | 110 | '#title' => t('Allowed values'), |
111 | 111 | '#collapsible' => TRUE, |
112 | 112 | '#collapsed' => TRUE, |
113 | - ); |
|
114 | - $form['allowed_values_fieldset']['allowed_values'] = array( |
|
113 | + ); |
|
114 | + $form['allowed_values_fieldset']['allowed_values'] = array( |
|
115 | 115 | '#type' => 'textarea', |
116 | 116 | '#title' => t('Allowed values list'), |
117 | 117 | '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
118 | 118 | '#required' => FALSE, |
119 | 119 | '#rows' => 10, |
120 | 120 | '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
121 | - ); |
|
122 | - $form['allowed_values_fieldset']['advanced_options'] = array( |
|
121 | + ); |
|
122 | + $form['allowed_values_fieldset']['advanced_options'] = array( |
|
123 | 123 | '#type' => 'fieldset', |
124 | 124 | '#title' => t('PHP code'), |
125 | 125 | '#collapsible' => TRUE, |
126 | 126 | '#collapsed' => empty($field['allowed_values_php']), |
127 | - ); |
|
128 | - if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
127 | + ); |
|
128 | + if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
129 | 129 | $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array( |
130 | - '#type' => 'textarea', |
|
131 | - '#title' => t('Code'), |
|
132 | - '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
133 | - '#rows' => 6, |
|
134 | - '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
130 | + '#type' => 'textarea', |
|
131 | + '#title' => t('Code'), |
|
132 | + '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
133 | + '#rows' => 6, |
|
134 | + '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
135 | 135 | ); |
136 | - } |
|
137 | - else { |
|
136 | + } |
|
137 | + else { |
|
138 | 138 | $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
139 | - '#type' => 'item', |
|
140 | - '#title' => t('Code'), |
|
141 | - '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
142 | - '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
139 | + '#type' => 'item', |
|
140 | + '#title' => t('Code'), |
|
141 | + '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
142 | + '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
143 | 143 | ); |
144 | - } |
|
145 | - return $form; |
|
144 | + } |
|
145 | + return $form; |
|
146 | 146 | |
147 | 147 | case 'save': |
148 | 148 | $values = array('prefix', 'suffix', 'min', 'max', 'allowed_values', 'allowed_values_php'); |
149 | - if ($field['type'] == 'number_decimal') { |
|
149 | + if ($field['type'] == 'number_decimal') { |
|
150 | 150 | $values = array_merge($values, array('precision', 'scale', 'decimal')); |
151 | - } |
|
152 | - return $values; |
|
151 | + } |
|
152 | + return $values; |
|
153 | 153 | |
154 | 154 | case 'database columns': |
155 | 155 | if ($field['type'] == 'number_integer') { |
156 | 156 | return array( |
157 | - 'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE), |
|
157 | + 'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE), |
|
158 | 158 | ); |
159 | - } |
|
160 | - if ($field['type'] == 'number_float') { |
|
159 | + } |
|
160 | + if ($field['type'] == 'number_float') { |
|
161 | 161 | return array( |
162 | - 'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE), |
|
162 | + 'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE), |
|
163 | 163 | ); |
164 | - } |
|
165 | - if ($field['type'] == 'number_decimal') { |
|
164 | + } |
|
165 | + if ($field['type'] == 'number_decimal') { |
|
166 | 166 | $precision = isset($field['precision']) ? $field['precision'] : 10; |
167 | 167 | $scale = isset($field['scale']) ? $field['scale'] : 2; |
168 | 168 | return array( |
169 | - 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE), |
|
169 | + 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE), |
|
170 | 170 | ); |
171 | - } |
|
171 | + } |
|
172 | 172 | |
173 | 173 | case 'views data': |
174 | 174 | $allowed_values = content_allowed_values($field); |
175 | - if (count($allowed_values)) { |
|
175 | + if (count($allowed_values)) { |
|
176 | 176 | $data = content_views_field_views_data($field); |
177 | 177 | $db_info = content_database_info($field); |
178 | 178 | $table_alias = content_views_tablename($field); |
@@ -188,79 +188,79 @@ discard block |
||
188 | 188 | $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
189 | 189 | $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE; |
190 | 190 | return $data; |
191 | - } |
|
192 | - break; |
|
193 | - } |
|
191 | + } |
|
192 | + break; |
|
193 | + } |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | function _number_widget_settings_min_validate($element, &$form_state) { |
197 | - $value = $form_state['values']['min']; |
|
198 | - if ($value && !is_numeric($value)) { |
|
197 | + $value = $form_state['values']['min']; |
|
198 | + if ($value && !is_numeric($value)) { |
|
199 | 199 | form_set_error('min', t('"Minimum" must be a number.')); |
200 | - } |
|
200 | + } |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | function _number_widget_settings_max_validate($element, &$form_state) { |
204 | - $value = $form_state['values']['max']; |
|
205 | - if ($value && !is_numeric($value)) { |
|
204 | + $value = $form_state['values']['max']; |
|
205 | + if ($value && !is_numeric($value)) { |
|
206 | 206 | form_set_error('max', t('"Maximum" must be a number.')); |
207 | - } |
|
207 | + } |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * Implementation of hook_field(). |
212 | 212 | */ |
213 | 213 | function number_field($op, &$node, $field, &$items, $teaser, $page) { |
214 | - switch ($op) { |
|
214 | + switch ($op) { |
|
215 | 215 | case 'validate': |
216 | 216 | $allowed_values = content_allowed_values($field); |
217 | - if (is_array($items)) { |
|
217 | + if (is_array($items)) { |
|
218 | 218 | foreach ($items as $delta => $item) { |
219 | - $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
220 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
221 | - if ($item['value'] != '') { |
|
219 | + $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
220 | + if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
221 | + if ($item['value'] != '') { |
|
222 | 222 | if (is_numeric($field['min']) && $item['value'] < $field['min']) { |
223 | - form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min']))); |
|
223 | + form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min']))); |
|
224 | 224 | } |
225 | 225 | if (is_numeric($field['max']) && $item['value'] > $field['max']) { |
226 | - form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max']))); |
|
226 | + form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max']))); |
|
227 | 227 | } |
228 | 228 | if (count($allowed_values)) { |
229 | - // We cannot use array_key_exists() because allowed values are |
|
230 | - // stored as strings, and we need to compare numeric equality. |
|
231 | - $valid = FALSE; |
|
232 | - foreach ($allowed_values as $kay => $value) { |
|
229 | + // We cannot use array_key_exists() because allowed values are |
|
230 | + // stored as strings, and we need to compare numeric equality. |
|
231 | + $valid = FALSE; |
|
232 | + foreach ($allowed_values as $kay => $value) { |
|
233 | 233 | if ((float) $item['value'] == (float) $kay) { |
234 | - $valid = TRUE; |
|
235 | - break; |
|
234 | + $valid = TRUE; |
|
235 | + break; |
|
236 | 236 | } |
237 | - } |
|
238 | - if (!$valid) { |
|
237 | + } |
|
238 | + if (!$valid) { |
|
239 | 239 | form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label'])))); |
240 | - } |
|
240 | + } |
|
241 | + } |
|
241 | 242 | } |
242 | - } |
|
243 | 243 | } |
244 | - } |
|
245 | - return $items; |
|
246 | - } |
|
244 | + } |
|
245 | + return $items; |
|
246 | + } |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
250 | 250 | * Implementation of hook_content_is_empty(). |
251 | 251 | */ |
252 | 252 | function number_content_is_empty($item, $field) { |
253 | - if (empty($item['value']) && (string)$item['value'] !== '0') { |
|
253 | + if (empty($item['value']) && (string)$item['value'] !== '0') { |
|
254 | 254 | return TRUE; |
255 | - } |
|
256 | - return FALSE; |
|
255 | + } |
|
256 | + return FALSE; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | 260 | * Implementation of hook_field_formatter_info(). |
261 | 261 | */ |
262 | 262 | function number_field_formatter_info() { |
263 | - return array( |
|
263 | + return array( |
|
264 | 264 | 'default' => array('label' => '9999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
265 | 265 | 'us_0' => array('label' => '9,999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
266 | 266 | 'us_1' => array('label' => '9,999.9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
@@ -272,72 +272,72 @@ discard block |
||
272 | 272 | 'fr_1' => array('label' => '9 999, 9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
273 | 273 | 'fr_2' => array('label' => '9 999, 99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
274 | 274 | 'unformatted' => array('label' => t('unformatted'), 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
275 | - ); |
|
275 | + ); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
279 | 279 | * Proxy theme function for 'unformatted' number field formatter. |
280 | 280 | */ |
281 | 281 | function theme_number_formatter_unformatted($element) { |
282 | - return $element['#item']['value']; |
|
282 | + return $element['#item']['value']; |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | 286 | * Proxy theme function for number field formatters. |
287 | 287 | */ |
288 | 288 | function theme_number_formatter_generic($element) { |
289 | - $field = content_fields($element['#field_name'], $element['#type_name']); |
|
290 | - $value = $element['#item']['value']; |
|
289 | + $field = content_fields($element['#field_name'], $element['#type_name']); |
|
290 | + $value = $element['#item']['value']; |
|
291 | 291 | |
292 | - if (($allowed_values = content_allowed_values($field))) { |
|
292 | + if (($allowed_values = content_allowed_values($field))) { |
|
293 | 293 | if (isset($allowed_values[$value]) && $allowed_values[$value] != $value) { |
294 | - return $allowed_values[$value]; |
|
294 | + return $allowed_values[$value]; |
|
295 | + } |
|
295 | 296 | } |
296 | - } |
|
297 | 297 | |
298 | - if (empty($value) && $value !== '0') { |
|
298 | + if (empty($value) && $value !== '0') { |
|
299 | 299 | return ''; |
300 | - } |
|
300 | + } |
|
301 | 301 | |
302 | - switch ($element['#formatter']) { |
|
302 | + switch ($element['#formatter']) { |
|
303 | 303 | case 'us_0': |
304 | 304 | $output = number_format($value, 0, '.', ','); |
305 | - break; |
|
305 | + break; |
|
306 | 306 | case 'us_1': |
307 | 307 | $output = number_format($value, 1, '.', ','); |
308 | - break; |
|
308 | + break; |
|
309 | 309 | case 'us_2': |
310 | 310 | $output = number_format($value, 2, '.', ','); |
311 | - break; |
|
311 | + break; |
|
312 | 312 | case 'be_0': |
313 | 313 | $output = number_format($value, 0, ',', '.'); |
314 | - break; |
|
314 | + break; |
|
315 | 315 | case 'be_1': |
316 | 316 | $output = number_format($value, 1, ',', '.'); |
317 | - break; |
|
317 | + break; |
|
318 | 318 | case 'be_2': |
319 | 319 | $output = number_format($value, 2, ',', '.'); |
320 | - break; |
|
320 | + break; |
|
321 | 321 | case 'fr_0': |
322 | 322 | $output = number_format($value, 0, ', ', ' '); |
323 | - break; |
|
323 | + break; |
|
324 | 324 | case 'fr_1': |
325 | 325 | $output = number_format($value, 1, ', ', ' '); |
326 | - break; |
|
326 | + break; |
|
327 | 327 | case 'fr_2': |
328 | 328 | $output = number_format($value, 2, ', ', ' '); |
329 | - break; |
|
329 | + break; |
|
330 | 330 | default: |
331 | 331 | $output = $value; |
332 | - break; |
|
333 | - } |
|
332 | + break; |
|
333 | + } |
|
334 | 334 | |
335 | - $prefixes = isset($field['prefix']) ? array_map('content_filter_xss', explode('|', $field['prefix'])) : array(''); |
|
336 | - $suffixes = isset($field['suffix']) ? array_map('content_filter_xss', explode('|', $field['suffix'])) : array(''); |
|
337 | - $prefix = (count($prefixes) > 1) ? format_plural($value, $prefixes[0], $prefixes[1]) : $prefixes[0]; |
|
338 | - $suffix = (count($suffixes) > 1) ? format_plural($value, $suffixes[0], $suffixes[1]) : $suffixes[0]; |
|
335 | + $prefixes = isset($field['prefix']) ? array_map('content_filter_xss', explode('|', $field['prefix'])) : array(''); |
|
336 | + $suffixes = isset($field['suffix']) ? array_map('content_filter_xss', explode('|', $field['suffix'])) : array(''); |
|
337 | + $prefix = (count($prefixes) > 1) ? format_plural($value, $prefixes[0], $prefixes[1]) : $prefixes[0]; |
|
338 | + $suffix = (count($suffixes) > 1) ? format_plural($value, $suffixes[0], $suffixes[1]) : $suffixes[0]; |
|
339 | 339 | |
340 | - return $prefix . $output . $suffix; |
|
340 | + return $prefix . $output . $suffix; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -352,16 +352,16 @@ discard block |
||
352 | 352 | * differently. |
353 | 353 | */ |
354 | 354 | function number_widget_info() { |
355 | - return array( |
|
355 | + return array( |
|
356 | 356 | 'number' => array( |
357 | - 'label' => t('Text field'), |
|
358 | - 'field types' => array('number_integer', 'number_decimal', 'number_float'), |
|
359 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
360 | - 'callbacks' => array( |
|
357 | + 'label' => t('Text field'), |
|
358 | + 'field types' => array('number_integer', 'number_decimal', 'number_float'), |
|
359 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
360 | + 'callbacks' => array( |
|
361 | 361 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
362 | - ), |
|
362 | + ), |
|
363 | 363 | ), |
364 | - ); |
|
364 | + ); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | /** |
@@ -377,13 +377,13 @@ discard block |
||
377 | 377 | * the validator can use. The regex can be overridden if necessary. |
378 | 378 | */ |
379 | 379 | function number_elements() { |
380 | - return array( |
|
380 | + return array( |
|
381 | 381 | 'number' => array( |
382 | - '#input' => TRUE, |
|
383 | - '#columns' => array('value'), '#delta' => 0, |
|
384 | - '#process' => array('number_process'), |
|
382 | + '#input' => TRUE, |
|
383 | + '#columns' => array('value'), '#delta' => 0, |
|
384 | + '#process' => array('number_process'), |
|
385 | 385 | ), |
386 | - ); |
|
386 | + ); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -418,11 +418,11 @@ discard block |
||
418 | 418 | * the form item for a single element for this field |
419 | 419 | */ |
420 | 420 | function number_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
421 | - $element = array( |
|
421 | + $element = array( |
|
422 | 422 | '#type' => $field['widget']['type'], |
423 | 423 | '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL, |
424 | - ); |
|
425 | - return $element; |
|
424 | + ); |
|
425 | + return $element; |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -434,13 +434,13 @@ discard block |
||
434 | 434 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
435 | 435 | */ |
436 | 436 | function number_process($element, $edit, $form_state, $form) { |
437 | - $field_name = $element['#field_name']; |
|
438 | - $field = $form['#field_info'][$field_name]; |
|
439 | - $field_key = $element['#columns'][0]; |
|
437 | + $field_name = $element['#field_name']; |
|
438 | + $field = $form['#field_info'][$field_name]; |
|
439 | + $field_key = $element['#columns'][0]; |
|
440 | 440 | |
441 | - $value = isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : ''; |
|
442 | - $value = isset($field['decimal']) ? str_replace('.', $field['decimal'], $value) : $value; |
|
443 | - $element[$field_key] = array( |
|
441 | + $value = isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : ''; |
|
442 | + $value = isset($field['decimal']) ? str_replace('.', $field['decimal'], $value) : $value; |
|
443 | + $element[$field_key] = array( |
|
444 | 444 | '#type' => 'textfield', |
445 | 445 | '#default_value' => $value, |
446 | 446 | // Need to allow a slightly larger size that the field length to allow |
@@ -457,117 +457,117 @@ discard block |
||
457 | 457 | '#type_name' => $element['#type_name'], |
458 | 458 | '#delta' => $element['#delta'], |
459 | 459 | '#columns' => $element['#columns'], |
460 | - ); |
|
460 | + ); |
|
461 | 461 | |
462 | - $prefixes = array(); |
|
463 | - $suffixes = array(); |
|
462 | + $prefixes = array(); |
|
463 | + $suffixes = array(); |
|
464 | 464 | |
465 | - // Make sure we don't wipe out element validation added elsewhere. |
|
466 | - if (empty($element['#element_validate'])) { |
|
465 | + // Make sure we don't wipe out element validation added elsewhere. |
|
466 | + if (empty($element['#element_validate'])) { |
|
467 | 467 | $element['#element_validate'] = array(); |
468 | - } |
|
469 | - if (!empty($field['prefix'])) { |
|
468 | + } |
|
469 | + if (!empty($field['prefix'])) { |
|
470 | 470 | $prefixes = explode('|', $field['prefix']); |
471 | 471 | $element[$field_key]['#field_prefix'] = content_filter_xss(array_pop($prefixes)); |
472 | - } |
|
473 | - if (!empty($field['suffix'])) { |
|
472 | + } |
|
473 | + if (!empty($field['suffix'])) { |
|
474 | 474 | $suffixes = explode('|', $field['suffix']); |
475 | 475 | $element[$field_key]['#field_suffix'] = content_filter_xss(array_pop($suffixes)); |
476 | - } |
|
477 | - switch ($field['type']) { |
|
476 | + } |
|
477 | + switch ($field['type']) { |
|
478 | 478 | case 'number_float': |
479 | 479 | $element['#element_validate'][] = 'number_float_validate'; |
480 | - break; |
|
480 | + break; |
|
481 | 481 | case 'number_integer': |
482 | 482 | $element['#element_validate'][] = 'number_integer_validate'; |
483 | - break; |
|
483 | + break; |
|
484 | 484 | case 'number_decimal': |
485 | 485 | $element['#element_validate'][] = 'number_decimal_validate'; |
486 | - $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.'; |
|
487 | - $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10; |
|
488 | - $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2; |
|
489 | - break; |
|
490 | - } |
|
491 | - |
|
492 | - // Used so that hook_field('validate') knows where to flag an error. |
|
493 | - $element['_error_element'] = array( |
|
486 | + $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.'; |
|
487 | + $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10; |
|
488 | + $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2; |
|
489 | + break; |
|
490 | + } |
|
491 | + |
|
492 | + // Used so that hook_field('validate') knows where to flag an error. |
|
493 | + $element['_error_element'] = array( |
|
494 | 494 | '#type' => 'value', |
495 | 495 | '#value' => implode('][', array_merge($element['#parents'], array($field_key))), |
496 | - ); |
|
496 | + ); |
|
497 | 497 | |
498 | - return $element; |
|
498 | + return $element; |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
502 | 502 | * FAPI validation of an individual float element. |
503 | 503 | */ |
504 | 504 | function number_float_validate($element, &$form_state) { |
505 | - $field_name = $element['#field_name']; |
|
506 | - $type_name = $element['#type_name']; |
|
507 | - $field = content_fields($field_name, $type_name); |
|
508 | - $field_key = $element['#columns'][0]; |
|
509 | - $value = $element['#value'][$field_key]; |
|
505 | + $field_name = $element['#field_name']; |
|
506 | + $type_name = $element['#type_name']; |
|
507 | + $field = content_fields($field_name, $type_name); |
|
508 | + $field_key = $element['#columns'][0]; |
|
509 | + $value = $element['#value'][$field_key]; |
|
510 | 510 | |
511 | - if (($element[$field_key]['#required'] || !empty($value))) { |
|
511 | + if (($element[$field_key]['#required'] || !empty($value))) { |
|
512 | 512 | $start = $value; |
513 | 513 | $value = preg_replace('@[^-0-9\.]@', '', $value); |
514 | 514 | if ($start != $value) { |
515 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
516 | - form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
|
515 | + $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
516 | + form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
|
517 | 517 | } |
518 | 518 | else { |
519 | - form_set_value($element[$field_key], $value, $form_state); |
|
519 | + form_set_value($element[$field_key], $value, $form_state); |
|
520 | + } |
|
520 | 521 | } |
521 | - } |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
525 | 525 | * FAPI validation of an individual integer element. |
526 | 526 | */ |
527 | 527 | function number_integer_validate($element, &$form_state) { |
528 | - $field_name = $element['#field_name']; |
|
529 | - $type_name = $element['#type_name']; |
|
530 | - $field = content_fields($field_name, $type_name); |
|
531 | - $field_key = $element['#columns'][0]; |
|
532 | - $value = $element['#value'][$field_key]; |
|
528 | + $field_name = $element['#field_name']; |
|
529 | + $type_name = $element['#type_name']; |
|
530 | + $field = content_fields($field_name, $type_name); |
|
531 | + $field_key = $element['#columns'][0]; |
|
532 | + $value = $element['#value'][$field_key]; |
|
533 | 533 | |
534 | - if (($element[$field_key]['#required'] || !empty($value))) { |
|
534 | + if (($element[$field_key]['#required'] || !empty($value))) { |
|
535 | 535 | $start = $value; |
536 | 536 | $value = preg_replace('@[^-0-9]@', '', $value); |
537 | 537 | if ($start != $value) { |
538 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
539 | - form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
|
538 | + $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
539 | + form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
|
540 | 540 | } |
541 | 541 | else { |
542 | - form_set_value($element[$field_key], $value, $form_state); |
|
542 | + form_set_value($element[$field_key], $value, $form_state); |
|
543 | + } |
|
543 | 544 | } |
544 | - } |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
548 | 548 | * FAPI validation of an individual decimal element. |
549 | 549 | */ |
550 | 550 | function number_decimal_validate($element, &$form_state) { |
551 | - $field_name = $element['#field_name']; |
|
552 | - $type_name = $element['#type_name']; |
|
553 | - $field = content_fields($field_name, $type_name); |
|
554 | - $field_key = $element['#columns'][0]; |
|
555 | - $value = $element['#value'][$field_key]; |
|
551 | + $field_name = $element['#field_name']; |
|
552 | + $type_name = $element['#type_name']; |
|
553 | + $field = content_fields($field_name, $type_name); |
|
554 | + $field_key = $element['#columns'][0]; |
|
555 | + $value = $element['#value'][$field_key]; |
|
556 | 556 | |
557 | - if (($element[$field_key]['#required'] || !empty($value))) { |
|
557 | + if (($element[$field_key]['#required'] || !empty($value))) { |
|
558 | 558 | $decimal = $element['#decimal'] ? $element['#decimal'] : '.'; |
559 | 559 | $start = $value; |
560 | 560 | $value = preg_replace('@[^-0-9\\'. $decimal .']@', '', $value); |
561 | 561 | if ($start != $value) { |
562 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
563 | - form_set_error($error_field, t('Only numbers and the decimal character (%decimal) are allowed in %field.', array('%decimal' => $element['#decimal'], '%field' => t($field['widget']['label'])))); |
|
562 | + $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
563 | + form_set_error($error_field, t('Only numbers and the decimal character (%decimal) are allowed in %field.', array('%decimal' => $element['#decimal'], '%field' => t($field['widget']['label'])))); |
|
564 | 564 | } |
565 | 565 | else { |
566 | - $value = str_replace($element['#decimal'], '.', $value); |
|
567 | - $value = round($value, $element['#scale']); |
|
568 | - form_set_value($element[$field_key], $value, $form_state); |
|
566 | + $value = str_replace($element['#decimal'], '.', $value); |
|
567 | + $value = round($value, $element['#scale']); |
|
568 | + form_set_value($element[$field_key], $value, $form_state); |
|
569 | + } |
|
569 | 570 | } |
570 | - } |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -581,5 +581,5 @@ discard block |
||
581 | 581 | * $element['#delta] is the position of this element in the group |
582 | 582 | */ |
583 | 583 | function theme_number($element) { |
584 | - return $element['#children']; |
|
584 | + return $element['#children']; |
|
585 | 585 | } |
586 | 586 | \ No newline at end of file |
@@ -54,142 +54,142 @@ discard block |
||
54 | 54 | */ |
55 | 55 | function number_field_settings($op, $field) { |
56 | 56 | switch ($op) { |
57 | - case 'form': |
|
58 | - $form = array(); |
|
59 | - $form['min'] = array( |
|
60 | - '#type' => 'textfield', |
|
61 | - '#title' => t('Minimum'), |
|
62 | - '#element_validate' => array('_element_validate_number'), |
|
63 | - '#default_value' => is_numeric($field['min']) ? $field['min'] : '', |
|
57 | + case 'form': |
|
58 | + $form = array(); |
|
59 | + $form['min'] = array( |
|
60 | + '#type' => 'textfield', |
|
61 | + '#title' => t('Minimum'), |
|
62 | + '#element_validate' => array('_element_validate_number'), |
|
63 | + '#default_value' => is_numeric($field['min']) ? $field['min'] : '', |
|
64 | + ); |
|
65 | + $form['max'] = array( |
|
66 | + '#type' => 'textfield', |
|
67 | + '#title' => t('Maximum'), |
|
68 | + '#element_validate' => array('_element_validate_number'), |
|
69 | + '#default_value' => is_numeric($field['max']) ? $field['max'] : '', |
|
70 | + ); |
|
71 | + if ($field['type'] == 'number_decimal') { |
|
72 | + $form['precision'] = array( |
|
73 | + '#type' => 'select', |
|
74 | + '#options' => drupal_map_assoc(range(10, 32)), |
|
75 | + '#title' => t('Precision'), |
|
76 | + '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), |
|
77 | + '#default_value' => is_numeric($field['precision']) ? $field['precision'] : 10, |
|
64 | 78 | ); |
65 | - $form['max'] = array( |
|
66 | - '#type' => 'textfield', |
|
67 | - '#title' => t('Maximum'), |
|
68 | - '#element_validate' => array('_element_validate_number'), |
|
69 | - '#default_value' => is_numeric($field['max']) ? $field['max'] : '', |
|
79 | + $form['scale'] = array( |
|
80 | + '#type' => 'select', |
|
81 | + '#options' => drupal_map_assoc(range(0, 10)), |
|
82 | + '#title' => t('Scale'), |
|
83 | + '#description' => t('The number of digits to the right of the decimal.'), |
|
84 | + '#default_value' => is_numeric($field['scale']) ? $field['scale'] : 2, |
|
70 | 85 | ); |
71 | - if ($field['type'] == 'number_decimal') { |
|
72 | - $form['precision'] = array( |
|
73 | - '#type' => 'select', |
|
74 | - '#options' => drupal_map_assoc(range(10, 32)), |
|
75 | - '#title' => t('Precision'), |
|
76 | - '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), |
|
77 | - '#default_value' => is_numeric($field['precision']) ? $field['precision'] : 10, |
|
78 | - ); |
|
79 | - $form['scale'] = array( |
|
80 | - '#type' => 'select', |
|
81 | - '#options' => drupal_map_assoc(range(0, 10)), |
|
82 | - '#title' => t('Scale'), |
|
83 | - '#description' => t('The number of digits to the right of the decimal.'), |
|
84 | - '#default_value' => is_numeric($field['scale']) ? $field['scale'] : 2, |
|
85 | - ); |
|
86 | - $form['decimal'] = array( |
|
87 | - '#type' => 'select', |
|
88 | - '#options' => array('.' => 'decimal point', ',' => 'comma', ' ' => 'space'), |
|
89 | - '#title' => t('Decimal marker'), |
|
90 | - '#description' => t('The character users will input to mark the decimal point in forms.'), |
|
91 | - '#default_value' => !empty($field['decimal']) ? $field['decimal'] : '.', |
|
92 | - ); |
|
93 | - } |
|
94 | - $form['append']['prefix'] = array( |
|
95 | - '#type' => 'textfield', |
|
96 | - '#title' => t('Prefix'), |
|
97 | - '#size' => 60, |
|
98 | - '#default_value' => !empty($field['prefix']) ? $field['prefix'] : '', |
|
99 | - '#description' => t('Define a string that should be prefixed to the value, like $ or €. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
|
100 | - ); |
|
101 | - $form['append']['suffix'] = array( |
|
102 | - '#type' => 'textfield', |
|
103 | - '#title' => t('Suffix'), |
|
104 | - '#size' => 60, |
|
105 | - '#default_value' => !empty($field['suffix']) ? $field['suffix'] : '', |
|
106 | - '#description' => t('Define a string that should suffixed to the value, like m², m/s², kb/s. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
|
86 | + $form['decimal'] = array( |
|
87 | + '#type' => 'select', |
|
88 | + '#options' => array('.' => 'decimal point', ',' => 'comma', ' ' => 'space'), |
|
89 | + '#title' => t('Decimal marker'), |
|
90 | + '#description' => t('The character users will input to mark the decimal point in forms.'), |
|
91 | + '#default_value' => !empty($field['decimal']) ? $field['decimal'] : '.', |
|
107 | 92 | ); |
108 | - $form['allowed_values_fieldset'] = array( |
|
109 | - '#type' => 'fieldset', |
|
110 | - '#title' => t('Allowed values'), |
|
111 | - '#collapsible' => TRUE, |
|
112 | - '#collapsed' => TRUE, |
|
113 | - ); |
|
114 | - $form['allowed_values_fieldset']['allowed_values'] = array( |
|
93 | + } |
|
94 | + $form['append']['prefix'] = array( |
|
95 | + '#type' => 'textfield', |
|
96 | + '#title' => t('Prefix'), |
|
97 | + '#size' => 60, |
|
98 | + '#default_value' => !empty($field['prefix']) ? $field['prefix'] : '', |
|
99 | + '#description' => t('Define a string that should be prefixed to the value, like $ or €. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
|
100 | + ); |
|
101 | + $form['append']['suffix'] = array( |
|
102 | + '#type' => 'textfield', |
|
103 | + '#title' => t('Suffix'), |
|
104 | + '#size' => 60, |
|
105 | + '#default_value' => !empty($field['suffix']) ? $field['suffix'] : '', |
|
106 | + '#description' => t('Define a string that should suffixed to the value, like m², m/s², kb/s. Leave blank for none. Separate singular and plural values with a pipe (pound|pounds).'), |
|
107 | + ); |
|
108 | + $form['allowed_values_fieldset'] = array( |
|
109 | + '#type' => 'fieldset', |
|
110 | + '#title' => t('Allowed values'), |
|
111 | + '#collapsible' => TRUE, |
|
112 | + '#collapsed' => TRUE, |
|
113 | + ); |
|
114 | + $form['allowed_values_fieldset']['allowed_values'] = array( |
|
115 | + '#type' => 'textarea', |
|
116 | + '#title' => t('Allowed values list'), |
|
117 | + '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
|
118 | + '#required' => FALSE, |
|
119 | + '#rows' => 10, |
|
120 | + '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
|
121 | + ); |
|
122 | + $form['allowed_values_fieldset']['advanced_options'] = array( |
|
123 | + '#type' => 'fieldset', |
|
124 | + '#title' => t('PHP code'), |
|
125 | + '#collapsible' => TRUE, |
|
126 | + '#collapsed' => empty($field['allowed_values_php']), |
|
127 | + ); |
|
128 | + if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
129 | + $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array( |
|
115 | 130 | '#type' => 'textarea', |
116 | - '#title' => t('Allowed values list'), |
|
117 | - '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
|
118 | - '#required' => FALSE, |
|
119 | - '#rows' => 10, |
|
120 | - '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
|
131 | + '#title' => t('Code'), |
|
132 | + '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
133 | + '#rows' => 6, |
|
134 | + '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
121 | 135 | ); |
122 | - $form['allowed_values_fieldset']['advanced_options'] = array( |
|
123 | - '#type' => 'fieldset', |
|
124 | - '#title' => t('PHP code'), |
|
125 | - '#collapsible' => TRUE, |
|
126 | - '#collapsed' => empty($field['allowed_values_php']), |
|
136 | + } |
|
137 | + else { |
|
138 | + $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
|
139 | + '#type' => 'item', |
|
140 | + '#title' => t('Code'), |
|
141 | + '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
142 | + '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
127 | 143 | ); |
128 | - if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
129 | - $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array( |
|
130 | - '#type' => 'textarea', |
|
131 | - '#title' => t('Code'), |
|
132 | - '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
133 | - '#rows' => 6, |
|
134 | - '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
135 | - ); |
|
136 | - } |
|
137 | - else { |
|
138 | - $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
|
139 | - '#type' => 'item', |
|
140 | - '#title' => t('Code'), |
|
141 | - '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
142 | - '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
143 | - ); |
|
144 | - } |
|
145 | - return $form; |
|
144 | + } |
|
145 | + return $form; |
|
146 | 146 | |
147 | - case 'save': |
|
148 | - $values = array('prefix', 'suffix', 'min', 'max', 'allowed_values', 'allowed_values_php'); |
|
149 | - if ($field['type'] == 'number_decimal') { |
|
150 | - $values = array_merge($values, array('precision', 'scale', 'decimal')); |
|
151 | - } |
|
152 | - return $values; |
|
147 | + case 'save': |
|
148 | + $values = array('prefix', 'suffix', 'min', 'max', 'allowed_values', 'allowed_values_php'); |
|
149 | + if ($field['type'] == 'number_decimal') { |
|
150 | + $values = array_merge($values, array('precision', 'scale', 'decimal')); |
|
151 | + } |
|
152 | + return $values; |
|
153 | 153 | |
154 | - case 'database columns': |
|
155 | - if ($field['type'] == 'number_integer') { |
|
156 | - return array( |
|
157 | - 'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE), |
|
158 | - ); |
|
159 | - } |
|
160 | - if ($field['type'] == 'number_float') { |
|
161 | - return array( |
|
162 | - 'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE), |
|
163 | - ); |
|
164 | - } |
|
165 | - if ($field['type'] == 'number_decimal') { |
|
166 | - $precision = isset($field['precision']) ? $field['precision'] : 10; |
|
167 | - $scale = isset($field['scale']) ? $field['scale'] : 2; |
|
168 | - return array( |
|
169 | - 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE), |
|
170 | - ); |
|
171 | - } |
|
154 | + case 'database columns': |
|
155 | + if ($field['type'] == 'number_integer') { |
|
156 | + return array( |
|
157 | + 'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE), |
|
158 | + ); |
|
159 | + } |
|
160 | + if ($field['type'] == 'number_float') { |
|
161 | + return array( |
|
162 | + 'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE), |
|
163 | + ); |
|
164 | + } |
|
165 | + if ($field['type'] == 'number_decimal') { |
|
166 | + $precision = isset($field['precision']) ? $field['precision'] : 10; |
|
167 | + $scale = isset($field['scale']) ? $field['scale'] : 2; |
|
168 | + return array( |
|
169 | + 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE), |
|
170 | + ); |
|
171 | + } |
|
172 | 172 | |
173 | - case 'views data': |
|
174 | - $allowed_values = content_allowed_values($field); |
|
175 | - if (count($allowed_values)) { |
|
176 | - $data = content_views_field_views_data($field); |
|
177 | - $db_info = content_database_info($field); |
|
178 | - $table_alias = content_views_tablename($field); |
|
179 | - |
|
180 | - // Filter: Add a 'many to one' filter. |
|
181 | - $copy = $data[$table_alias][$field['field_name'] .'_value']; |
|
182 | - $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
|
183 | - $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
184 | - $copy['filter']['numeric'] = TRUE; |
|
185 | - unset($copy['field'], $copy['argument'], $copy['sort']); |
|
186 | - $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
|
187 | - // Argument: swap the handler to the 'many to one' operator |
|
188 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
189 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE; |
|
190 | - return $data; |
|
191 | - } |
|
192 | - break; |
|
173 | + case 'views data': |
|
174 | + $allowed_values = content_allowed_values($field); |
|
175 | + if (count($allowed_values)) { |
|
176 | + $data = content_views_field_views_data($field); |
|
177 | + $db_info = content_database_info($field); |
|
178 | + $table_alias = content_views_tablename($field); |
|
179 | + |
|
180 | + // Filter: Add a 'many to one' filter. |
|
181 | + $copy = $data[$table_alias][$field['field_name'] .'_value']; |
|
182 | + $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
|
183 | + $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
184 | + $copy['filter']['numeric'] = TRUE; |
|
185 | + unset($copy['field'], $copy['argument'], $copy['sort']); |
|
186 | + $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
|
187 | + // Argument: swap the handler to the 'many to one' operator |
|
188 | + $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
189 | + $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE; |
|
190 | + return $data; |
|
191 | + } |
|
192 | + break; |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
@@ -212,37 +212,37 @@ discard block |
||
212 | 212 | */ |
213 | 213 | function number_field($op, &$node, $field, &$items, $teaser, $page) { |
214 | 214 | switch ($op) { |
215 | - case 'validate': |
|
216 | - $allowed_values = content_allowed_values($field); |
|
217 | - if (is_array($items)) { |
|
218 | - foreach ($items as $delta => $item) { |
|
219 | - $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
220 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
221 | - if ($item['value'] != '') { |
|
222 | - if (is_numeric($field['min']) && $item['value'] < $field['min']) { |
|
223 | - form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min']))); |
|
224 | - } |
|
225 | - if (is_numeric($field['max']) && $item['value'] > $field['max']) { |
|
226 | - form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max']))); |
|
227 | - } |
|
228 | - if (count($allowed_values)) { |
|
229 | - // We cannot use array_key_exists() because allowed values are |
|
230 | - // stored as strings, and we need to compare numeric equality. |
|
231 | - $valid = FALSE; |
|
232 | - foreach ($allowed_values as $kay => $value) { |
|
233 | - if ((float) $item['value'] == (float) $kay) { |
|
234 | - $valid = TRUE; |
|
235 | - break; |
|
236 | - } |
|
237 | - } |
|
238 | - if (!$valid) { |
|
239 | - form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label'])))); |
|
215 | + case 'validate': |
|
216 | + $allowed_values = content_allowed_values($field); |
|
217 | + if (is_array($items)) { |
|
218 | + foreach ($items as $delta => $item) { |
|
219 | + $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
220 | + if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
221 | + if ($item['value'] != '') { |
|
222 | + if (is_numeric($field['min']) && $item['value'] < $field['min']) { |
|
223 | + form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min']))); |
|
224 | + } |
|
225 | + if (is_numeric($field['max']) && $item['value'] > $field['max']) { |
|
226 | + form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max']))); |
|
227 | + } |
|
228 | + if (count($allowed_values)) { |
|
229 | + // We cannot use array_key_exists() because allowed values are |
|
230 | + // stored as strings, and we need to compare numeric equality. |
|
231 | + $valid = FALSE; |
|
232 | + foreach ($allowed_values as $kay => $value) { |
|
233 | + if ((float) $item['value'] == (float) $kay) { |
|
234 | + $valid = TRUE; |
|
235 | + break; |
|
240 | 236 | } |
241 | 237 | } |
238 | + if (!$valid) { |
|
239 | + form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label'])))); |
|
240 | + } |
|
242 | 241 | } |
243 | 242 | } |
244 | 243 | } |
245 | - return $items; |
|
244 | + } |
|
245 | + return $items; |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
@@ -300,36 +300,36 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | switch ($element['#formatter']) { |
303 | - case 'us_0': |
|
304 | - $output = number_format($value, 0, '.', ','); |
|
305 | - break; |
|
306 | - case 'us_1': |
|
307 | - $output = number_format($value, 1, '.', ','); |
|
308 | - break; |
|
309 | - case 'us_2': |
|
310 | - $output = number_format($value, 2, '.', ','); |
|
311 | - break; |
|
312 | - case 'be_0': |
|
313 | - $output = number_format($value, 0, ',', '.'); |
|
314 | - break; |
|
315 | - case 'be_1': |
|
316 | - $output = number_format($value, 1, ',', '.'); |
|
317 | - break; |
|
318 | - case 'be_2': |
|
319 | - $output = number_format($value, 2, ',', '.'); |
|
320 | - break; |
|
321 | - case 'fr_0': |
|
322 | - $output = number_format($value, 0, ', ', ' '); |
|
323 | - break; |
|
324 | - case 'fr_1': |
|
325 | - $output = number_format($value, 1, ', ', ' '); |
|
326 | - break; |
|
327 | - case 'fr_2': |
|
328 | - $output = number_format($value, 2, ', ', ' '); |
|
329 | - break; |
|
330 | - default: |
|
331 | - $output = $value; |
|
332 | - break; |
|
303 | + case 'us_0': |
|
304 | + $output = number_format($value, 0, '.', ','); |
|
305 | + break; |
|
306 | + case 'us_1': |
|
307 | + $output = number_format($value, 1, '.', ','); |
|
308 | + break; |
|
309 | + case 'us_2': |
|
310 | + $output = number_format($value, 2, '.', ','); |
|
311 | + break; |
|
312 | + case 'be_0': |
|
313 | + $output = number_format($value, 0, ',', '.'); |
|
314 | + break; |
|
315 | + case 'be_1': |
|
316 | + $output = number_format($value, 1, ',', '.'); |
|
317 | + break; |
|
318 | + case 'be_2': |
|
319 | + $output = number_format($value, 2, ',', '.'); |
|
320 | + break; |
|
321 | + case 'fr_0': |
|
322 | + $output = number_format($value, 0, ', ', ' '); |
|
323 | + break; |
|
324 | + case 'fr_1': |
|
325 | + $output = number_format($value, 1, ', ', ' '); |
|
326 | + break; |
|
327 | + case 'fr_2': |
|
328 | + $output = number_format($value, 2, ', ', ' '); |
|
329 | + break; |
|
330 | + default: |
|
331 | + $output = $value; |
|
332 | + break; |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | $prefixes = isset($field['prefix']) ? array_map('content_filter_xss', explode('|', $field['prefix'])) : array(''); |
@@ -475,18 +475,18 @@ discard block |
||
475 | 475 | $element[$field_key]['#field_suffix'] = content_filter_xss(array_pop($suffixes)); |
476 | 476 | } |
477 | 477 | switch ($field['type']) { |
478 | - case 'number_float': |
|
479 | - $element['#element_validate'][] = 'number_float_validate'; |
|
480 | - break; |
|
481 | - case 'number_integer': |
|
482 | - $element['#element_validate'][] = 'number_integer_validate'; |
|
483 | - break; |
|
484 | - case 'number_decimal': |
|
485 | - $element['#element_validate'][] = 'number_decimal_validate'; |
|
486 | - $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.'; |
|
487 | - $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10; |
|
488 | - $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2; |
|
489 | - break; |
|
478 | + case 'number_float': |
|
479 | + $element['#element_validate'][] = 'number_float_validate'; |
|
480 | + break; |
|
481 | + case 'number_integer': |
|
482 | + $element['#element_validate'][] = 'number_integer_validate'; |
|
483 | + break; |
|
484 | + case 'number_decimal': |
|
485 | + $element['#element_validate'][] = 'number_decimal_validate'; |
|
486 | + $element['#decimal'] = isset($field['decimal']) ? $field['decimal'] : '.'; |
|
487 | + $element['#precision'] = isset($field['precision']) ? $field['precision'] : 10; |
|
488 | + $element['#scale'] = isset($field['scale']) ? $field['scale'] : 2; |
|
489 | + break; |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | // Used so that hook_field('validate') knows where to flag an error. |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
139 | 139 | '#type' => 'item', |
140 | 140 | '#title' => t('Code'), |
141 | - '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
141 | + '#value' => !empty($field['allowed_values_php']) ? '<code>'.check_plain($field['allowed_values_php']).'</code>' : t('<none>'), |
|
142 | 142 | '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
143 | 143 | ); |
144 | 144 | } |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | $table_alias = content_views_tablename($field); |
179 | 179 | |
180 | 180 | // Filter: Add a 'many to one' filter. |
181 | - $copy = $data[$table_alias][$field['field_name'] .'_value']; |
|
181 | + $copy = $data[$table_alias][$field['field_name'].'_value']; |
|
182 | 182 | $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
183 | 183 | $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
184 | 184 | $copy['filter']['numeric'] = TRUE; |
185 | 185 | unset($copy['field'], $copy['argument'], $copy['sort']); |
186 | - $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
|
186 | + $data[$table_alias][$field['field_name'].'_value_many_to_one'] = $copy; |
|
187 | 187 | // Argument: swap the handler to the 'many to one' operator |
188 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
189 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE; |
|
188 | + $data[$table_alias][$field['field_name'].'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
189 | + $data[$table_alias][$field['field_name'].'_value']['argument']['numeric'] = TRUE; |
|
190 | 190 | return $data; |
191 | 191 | } |
192 | 192 | break; |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | // stored as strings, and we need to compare numeric equality. |
231 | 231 | $valid = FALSE; |
232 | 232 | foreach ($allowed_values as $kay => $value) { |
233 | - if ((float) $item['value'] == (float) $kay) { |
|
233 | + if ((float)$item['value'] == (float)$kay) { |
|
234 | 234 | $valid = TRUE; |
235 | 235 | break; |
236 | 236 | } |
@@ -261,16 +261,16 @@ discard block |
||
261 | 261 | */ |
262 | 262 | function number_field_formatter_info() { |
263 | 263 | return array( |
264 | - 'default' => array('label' => '9999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
265 | - 'us_0' => array('label' => '9,999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
266 | - 'us_1' => array('label' => '9,999.9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
267 | - 'us_2' => array('label' => '9,999.99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
268 | - 'be_0' => array('label' => '9.999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
269 | - 'be_1' => array('label' => '9.999,9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
270 | - 'be_2' => array('label' => '9.999,99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
271 | - 'fr_0' => array('label' => '9 999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
272 | - 'fr_1' => array('label' => '9 999, 9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
273 | - 'fr_2' => array('label' => '9 999, 99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
264 | + 'default' => array('label' => '9999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
265 | + 'us_0' => array('label' => '9,999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
266 | + 'us_1' => array('label' => '9,999.9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
267 | + 'us_2' => array('label' => '9,999.99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
268 | + 'be_0' => array('label' => '9.999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
269 | + 'be_1' => array('label' => '9.999,9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
270 | + 'be_2' => array('label' => '9.999,99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
271 | + 'fr_0' => array('label' => '9 999', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
|
272 | + 'fr_1' => array('label' => '9 999, 9', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
273 | + 'fr_2' => array('label' => '9 999, 99', 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_decimal', 'number_float')), |
|
274 | 274 | 'unformatted' => array('label' => t('unformatted'), 'multiple values' => CONTENT_HANDLE_CORE, 'field types' => array('number_integer', 'number_decimal', 'number_float')), |
275 | 275 | ); |
276 | 276 | } |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $prefix = (count($prefixes) > 1) ? format_plural($value, $prefixes[0], $prefixes[1]) : $prefixes[0]; |
338 | 338 | $suffix = (count($suffixes) > 1) ? format_plural($value, $suffixes[0], $suffixes[1]) : $suffixes[0]; |
339 | 339 | |
340 | - return $prefix . $output . $suffix; |
|
340 | + return $prefix.$output.$suffix; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | $start = $value; |
513 | 513 | $value = preg_replace('@[^-0-9\.]@', '', $value); |
514 | 514 | if ($start != $value) { |
515 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
515 | + $error_field = implode('][', $element['#parents']).']['.$field_key; |
|
516 | 516 | form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
517 | 517 | } |
518 | 518 | else { |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | $start = $value; |
536 | 536 | $value = preg_replace('@[^-0-9]@', '', $value); |
537 | 537 | if ($start != $value) { |
538 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
538 | + $error_field = implode('][', $element['#parents']).']['.$field_key; |
|
539 | 539 | form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
540 | 540 | } |
541 | 541 | else { |
@@ -557,9 +557,9 @@ discard block |
||
557 | 557 | if (($element[$field_key]['#required'] || !empty($value))) { |
558 | 558 | $decimal = $element['#decimal'] ? $element['#decimal'] : '.'; |
559 | 559 | $start = $value; |
560 | - $value = preg_replace('@[^-0-9\\'. $decimal .']@', '', $value); |
|
560 | + $value = preg_replace('@[^-0-9\\'.$decimal.']@', '', $value); |
|
561 | 561 | if ($start != $value) { |
562 | - $error_field = implode('][', $element['#parents']) .']['. $field_key; |
|
562 | + $error_field = implode('][', $element['#parents']).']['.$field_key; |
|
563 | 563 | form_set_error($error_field, t('Only numbers and the decimal character (%decimal) are allowed in %field.', array('%decimal' => $element['#decimal'], '%field' => t($field['widget']['label'])))); |
564 | 564 | } |
565 | 565 | else { |
@@ -133,8 +133,7 @@ discard block |
||
133 | 133 | '#rows' => 6, |
134 | 134 | '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
135 | 135 | ); |
136 | - } |
|
137 | - else { |
|
136 | + } else { |
|
138 | 137 | $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
139 | 138 | '#type' => 'item', |
140 | 139 | '#title' => t('Code'), |
@@ -514,8 +513,7 @@ discard block |
||
514 | 513 | if ($start != $value) { |
515 | 514 | $error_field = implode('][', $element['#parents']) .']['. $field_key; |
516 | 515 | form_set_error($error_field, t('Only numbers and decimals are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
517 | - } |
|
518 | - else { |
|
516 | + } else { |
|
519 | 517 | form_set_value($element[$field_key], $value, $form_state); |
520 | 518 | } |
521 | 519 | } |
@@ -537,8 +535,7 @@ discard block |
||
537 | 535 | if ($start != $value) { |
538 | 536 | $error_field = implode('][', $element['#parents']) .']['. $field_key; |
539 | 537 | form_set_error($error_field, t('Only numbers are allowed in %field.', array('%field' => t($field['widget']['label'])))); |
540 | - } |
|
541 | - else { |
|
538 | + } else { |
|
542 | 539 | form_set_value($element[$field_key], $value, $form_state); |
543 | 540 | } |
544 | 541 | } |
@@ -561,8 +558,7 @@ discard block |
||
561 | 558 | if ($start != $value) { |
562 | 559 | $error_field = implode('][', $element['#parents']) .']['. $field_key; |
563 | 560 | form_set_error($error_field, t('Only numbers and the decimal character (%decimal) are allowed in %field.', array('%decimal' => $element['#decimal'], '%field' => t($field['widget']['label'])))); |
564 | - } |
|
565 | - else { |
|
561 | + } else { |
|
566 | 562 | $value = str_replace($element['#decimal'], '.', $value); |
567 | 563 | $value = round($value, $element['#scale']); |
568 | 564 | form_set_value($element[$field_key], $value, $form_state); |
@@ -11,18 +11,18 @@ discard block |
||
11 | 11 | */ |
12 | 12 | function number_theme() { |
13 | 13 | return array( |
14 | - 'number' => array('arguments' => array('element' => NULL)), |
|
15 | - 'number_formatter_default' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
16 | - 'number_formatter_us_0' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
17 | - 'number_formatter_us_1' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
18 | - 'number_formatter_us_2' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
19 | - 'number_formatter_be_0' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
20 | - 'number_formatter_be_1' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
21 | - 'number_formatter_be_2' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
22 | - 'number_formatter_fr_0' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
23 | - 'number_formatter_fr_1' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
24 | - 'number_formatter_fr_2' => array('arguments' => array('element' => NULL), 'function' => 'theme_number_formatter_generic'), |
|
25 | - 'number_formatter_unformatted' => array('arguments' => array('element' => NULL)), |
|
14 | + 'number' => array('arguments' => array('element' => null)), |
|
15 | + 'number_formatter_default' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
16 | + 'number_formatter_us_0' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
17 | + 'number_formatter_us_1' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
18 | + 'number_formatter_us_2' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
19 | + 'number_formatter_be_0' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
20 | + 'number_formatter_be_1' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
21 | + 'number_formatter_be_2' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
22 | + 'number_formatter_fr_0' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
23 | + 'number_formatter_fr_1' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
24 | + 'number_formatter_fr_2' => array('arguments' => array('element' => null), 'function' => 'theme_number_formatter_generic'), |
|
25 | + 'number_formatter_unformatted' => array('arguments' => array('element' => null)), |
|
26 | 26 | ); |
27 | 27 | } |
28 | 28 | |
@@ -108,21 +108,21 @@ discard block |
||
108 | 108 | $form['allowed_values_fieldset'] = array( |
109 | 109 | '#type' => 'fieldset', |
110 | 110 | '#title' => t('Allowed values'), |
111 | - '#collapsible' => TRUE, |
|
112 | - '#collapsed' => TRUE, |
|
111 | + '#collapsible' => true, |
|
112 | + '#collapsed' => true, |
|
113 | 113 | ); |
114 | 114 | $form['allowed_values_fieldset']['allowed_values'] = array( |
115 | 115 | '#type' => 'textarea', |
116 | 116 | '#title' => t('Allowed values list'), |
117 | 117 | '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
118 | - '#required' => FALSE, |
|
118 | + '#required' => false, |
|
119 | 119 | '#rows' => 10, |
120 | 120 | '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
121 | 121 | ); |
122 | 122 | $form['allowed_values_fieldset']['advanced_options'] = array( |
123 | 123 | '#type' => 'fieldset', |
124 | 124 | '#title' => t('PHP code'), |
125 | - '#collapsible' => TRUE, |
|
125 | + '#collapsible' => true, |
|
126 | 126 | '#collapsed' => empty($field['allowed_values_php']), |
127 | 127 | ); |
128 | 128 | if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
@@ -154,19 +154,19 @@ discard block |
||
154 | 154 | case 'database columns': |
155 | 155 | if ($field['type'] == 'number_integer') { |
156 | 156 | return array( |
157 | - 'value' => array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE), |
|
157 | + 'value' => array('type' => 'int', 'not null' => false, 'sortable' => true), |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | if ($field['type'] == 'number_float') { |
161 | 161 | return array( |
162 | - 'value' => array('type' => 'float', 'not null' => FALSE, 'sortable' => TRUE), |
|
162 | + 'value' => array('type' => 'float', 'not null' => false, 'sortable' => true), |
|
163 | 163 | ); |
164 | 164 | } |
165 | 165 | if ($field['type'] == 'number_decimal') { |
166 | 166 | $precision = isset($field['precision']) ? $field['precision'] : 10; |
167 | 167 | $scale = isset($field['scale']) ? $field['scale'] : 2; |
168 | 168 | return array( |
169 | - 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => FALSE, 'sortable' => TRUE), |
|
169 | + 'value' => array('type' => 'numeric', 'precision' => $precision, 'scale' => $scale, 'not null' => false, 'sortable' => true), |
|
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | $copy = $data[$table_alias][$field['field_name'] .'_value']; |
182 | 182 | $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
183 | 183 | $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
184 | - $copy['filter']['numeric'] = TRUE; |
|
184 | + $copy['filter']['numeric'] = true; |
|
185 | 185 | unset($copy['field'], $copy['argument'], $copy['sort']); |
186 | 186 | $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
187 | 187 | // Argument: swap the handler to the 'many to one' operator |
188 | 188 | $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
189 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = TRUE; |
|
189 | + $data[$table_alias][$field['field_name'] .'_value']['argument']['numeric'] = true; |
|
190 | 190 | return $data; |
191 | 191 | } |
192 | 192 | break; |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | if (count($allowed_values)) { |
229 | 229 | // We cannot use array_key_exists() because allowed values are |
230 | 230 | // stored as strings, and we need to compare numeric equality. |
231 | - $valid = FALSE; |
|
231 | + $valid = false; |
|
232 | 232 | foreach ($allowed_values as $kay => $value) { |
233 | 233 | if ((float) $item['value'] == (float) $kay) { |
234 | - $valid = TRUE; |
|
234 | + $valid = true; |
|
235 | 235 | break; |
236 | 236 | } |
237 | 237 | } |
@@ -251,9 +251,9 @@ discard block |
||
251 | 251 | */ |
252 | 252 | function number_content_is_empty($item, $field) { |
253 | 253 | if (empty($item['value']) && (string)$item['value'] !== '0') { |
254 | - return TRUE; |
|
254 | + return true; |
|
255 | 255 | } |
256 | - return FALSE; |
|
256 | + return false; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | function number_elements() { |
380 | 380 | return array( |
381 | 381 | 'number' => array( |
382 | - '#input' => TRUE, |
|
382 | + '#input' => true, |
|
383 | 383 | '#columns' => array('value'), '#delta' => 0, |
384 | 384 | '#process' => array('number_process'), |
385 | 385 | ), |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | function number_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
421 | 421 | $element = array( |
422 | 422 | '#type' => $field['widget']['type'], |
423 | - '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL, |
|
423 | + '#default_value' => isset($items[$delta]) ? $items[$delta] : null, |
|
424 | 424 | ); |
425 | 425 | return $element; |
426 | 426 | } |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | * Implementation of hook_form_alter. |
11 | 11 | */ |
12 | 12 | function optionwidgets_form_alter(&$form, $form_state, $form_id) { |
13 | - // Provide additional help for the field settings form. |
|
14 | - if ($form_id == 'content_field_edit_form' && isset($form['widget'])) { |
|
13 | + // Provide additional help for the field settings form. |
|
14 | + if ($form_id == 'content_field_edit_form' && isset($form['widget'])) { |
|
15 | 15 | $widget_type = $form['#field']['widget']['type']; |
16 | 16 | $field_type = $form['#field']['type']; |
17 | 17 | $label = $form['#field']['widget']['label']; |
@@ -19,45 +19,45 @@ discard block |
||
19 | 19 | $output = '<p>'. t('Create a list of options as a list in <strong>Allowed values list</strong> or as an array in PHP code. These values will be the same for %field in all content types.', array('%field' => $label)) .'</p>'; |
20 | 20 | |
21 | 21 | if ($widget_type == 'optionwidgets_onoff') { |
22 | - $output .= '<p>'. t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.") .'</p>'; |
|
22 | + $output .= '<p>'. t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.") .'</p>'; |
|
23 | 23 | } |
24 | 24 | elseif ($widget_type == 'optionwidgets_buttons') { |
25 | - $output .= '<p>'. t("The 'checkboxes/radio buttons' widget will display checkboxes if the multiple values option is selected for this field, otherwise radios will be displayed.") .'</p>'; |
|
25 | + $output .= '<p>'. t("The 'checkboxes/radio buttons' widget will display checkboxes if the multiple values option is selected for this field, otherwise radios will be displayed.") .'</p>'; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | if (in_array($field_type, array('text', 'number_integer', 'number_float', 'number_decimal')) |
29 | 29 | && in_array($widget_type, array('optionwidgets_onoff', 'optionwidgets_buttons', 'optionwidgets_select'))) { |
30 | - $form['field']['allowed_values_fieldset']['#collapsed'] = FALSE; |
|
31 | - $form['field']['allowed_values_fieldset']['#description'] = $output; |
|
30 | + $form['field']['allowed_values_fieldset']['#collapsed'] = FALSE; |
|
31 | + $form['field']['allowed_values_fieldset']['#description'] = $output; |
|
32 | 32 | |
33 | - // If no 'allowed values' were set yet, add a remainder in the messages area. |
|
34 | - if (empty($form_state['post']) |
|
33 | + // If no 'allowed values' were set yet, add a remainder in the messages area. |
|
34 | + if (empty($form_state['post']) |
|
35 | 35 | && empty($form['field']['allowed_values_fieldset']['allowed_values']['#default_value']) |
36 | 36 | && empty($form['field']['allowed_values_fieldset']['advanced_options']['allowed_values_php']['#default_value'])) { |
37 | 37 | drupal_set_message(t("You need to specify the 'allowed values' for this field."), 'warning'); |
38 | - } |
|
38 | + } |
|
39 | + } |
|
39 | 40 | } |
40 | - } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Implementation of hook_theme(). |
45 | 45 | */ |
46 | 46 | function optionwidgets_theme() { |
47 | - return array( |
|
47 | + return array( |
|
48 | 48 | 'optionwidgets_select' => array( |
49 | - 'arguments' => array('element' => NULL), |
|
49 | + 'arguments' => array('element' => NULL), |
|
50 | 50 | ), |
51 | 51 | 'optionwidgets_buttons' => array( |
52 | - 'arguments' => array('element' => NULL), |
|
52 | + 'arguments' => array('element' => NULL), |
|
53 | 53 | ), |
54 | 54 | 'optionwidgets_onoff' => array( |
55 | - 'arguments' => array('element' => NULL), |
|
55 | + 'arguments' => array('element' => NULL), |
|
56 | 56 | ), |
57 | 57 | 'optionwidgets_none' => array( |
58 | - 'arguments' => array('widget_type' => NULL, 'field_name' => NULL, 'node_type' => NULL), |
|
59 | - ), |
|
60 | - ); |
|
58 | + 'arguments' => array('widget_type' => NULL, 'field_name' => NULL, 'node_type' => NULL), |
|
59 | + ), |
|
60 | + ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -75,32 +75,32 @@ discard block |
||
75 | 75 | */ |
76 | 76 | function optionwidgets_widget_info() { |
77 | 77 | |
78 | - return array( |
|
78 | + return array( |
|
79 | 79 | 'optionwidgets_select' => array( |
80 | - 'label' => t('Select list'), |
|
81 | - 'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'), |
|
82 | - 'multiple values' => CONTENT_HANDLE_MODULE, |
|
83 | - 'callbacks' => array( |
|
80 | + 'label' => t('Select list'), |
|
81 | + 'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'), |
|
82 | + 'multiple values' => CONTENT_HANDLE_MODULE, |
|
83 | + 'callbacks' => array( |
|
84 | 84 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
85 | - ), |
|
85 | + ), |
|
86 | 86 | ), |
87 | 87 | 'optionwidgets_buttons' => array( |
88 | - 'label' => t('Check boxes/radio buttons'), |
|
89 | - 'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'), |
|
90 | - 'multiple values' => CONTENT_HANDLE_MODULE, |
|
91 | - 'callbacks' => array( |
|
88 | + 'label' => t('Check boxes/radio buttons'), |
|
89 | + 'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'), |
|
90 | + 'multiple values' => CONTENT_HANDLE_MODULE, |
|
91 | + 'callbacks' => array( |
|
92 | 92 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
93 | - ), |
|
93 | + ), |
|
94 | 94 | ), |
95 | 95 | 'optionwidgets_onoff' => array( |
96 | - 'label' => t('Single on/off checkbox'), |
|
97 | - 'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'), |
|
98 | - 'multiple values' => CONTENT_HANDLE_MODULE, |
|
99 | - 'callbacks' => array( |
|
96 | + 'label' => t('Single on/off checkbox'), |
|
97 | + 'field types' => array('text', 'number_integer', 'number_decimal', 'number_float'), |
|
98 | + 'multiple values' => CONTENT_HANDLE_MODULE, |
|
99 | + 'callbacks' => array( |
|
100 | 100 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
101 | - ), |
|
101 | + ), |
|
102 | 102 | ), |
103 | - ); |
|
103 | + ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -113,22 +113,22 @@ discard block |
||
113 | 113 | * the same name as the hook_elements key. |
114 | 114 | */ |
115 | 115 | function optionwidgets_elements() { |
116 | - return array( |
|
116 | + return array( |
|
117 | 117 | 'optionwidgets_select' => array( |
118 | - '#input' => TRUE, |
|
119 | - '#columns' => array('value'), '#delta' => 0, |
|
120 | - '#process' => array('optionwidgets_select_process'), |
|
121 | - ), |
|
118 | + '#input' => TRUE, |
|
119 | + '#columns' => array('value'), '#delta' => 0, |
|
120 | + '#process' => array('optionwidgets_select_process'), |
|
121 | + ), |
|
122 | 122 | 'optionwidgets_buttons' => array( |
123 | - '#input' => TRUE, |
|
124 | - '#columns' => array('value'), '#delta' => 0, |
|
125 | - '#process' => array('optionwidgets_buttons_process'), |
|
126 | - ), |
|
123 | + '#input' => TRUE, |
|
124 | + '#columns' => array('value'), '#delta' => 0, |
|
125 | + '#process' => array('optionwidgets_buttons_process'), |
|
126 | + ), |
|
127 | 127 | 'optionwidgets_onoff' => array( |
128 | - '#input' => TRUE, |
|
129 | - '#columns' => array('value'), '#delta' => 0, |
|
130 | - '#process' => array('optionwidgets_onoff_process'), |
|
131 | - ), |
|
128 | + '#input' => TRUE, |
|
129 | + '#columns' => array('value'), '#delta' => 0, |
|
130 | + '#process' => array('optionwidgets_onoff_process'), |
|
131 | + ), |
|
132 | 132 | ); |
133 | 133 | } |
134 | 134 | |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | * the form item for a single element for this field |
165 | 165 | */ |
166 | 166 | function optionwidgets_widget(&$form, &$form_state, $field, $items, $delta = NULL) { |
167 | - $element = array( |
|
167 | + $element = array( |
|
168 | 168 | '#type' => $field['widget']['type'], |
169 | 169 | '#default_value' => !empty($items) ? $items : array(), |
170 | - ); |
|
171 | - return $element; |
|
170 | + ); |
|
171 | + return $element; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -180,17 +180,17 @@ discard block |
||
180 | 180 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
181 | 181 | */ |
182 | 182 | function optionwidgets_buttons_process($element, $edit, &$form_state, $form) { |
183 | - $field_name = $element['#field_name']; |
|
184 | - $field = $form['#field_info'][$field_name]; |
|
185 | - $field_key = $element['#columns'][0]; |
|
183 | + $field_name = $element['#field_name']; |
|
184 | + $field = $form['#field_info'][$field_name]; |
|
185 | + $field_key = $element['#columns'][0]; |
|
186 | 186 | |
187 | - // See if this element is in the database format or the transformed format, |
|
188 | - // and transform it if necessary. |
|
189 | - if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) { |
|
187 | + // See if this element is in the database format or the transformed format, |
|
188 | + // and transform it if necessary. |
|
189 | + if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) { |
|
190 | 190 | $element['#value'] = optionwidgets_data2form($element, $element['#default_value'], $field); |
191 | - } |
|
192 | - $options = optionwidgets_options($field); |
|
193 | - $element[$field_key] = array( |
|
191 | + } |
|
192 | + $options = optionwidgets_options($field); |
|
193 | + $element[$field_key] = array( |
|
194 | 194 | '#type' => $field['multiple'] ? 'checkboxes' : 'radios', |
195 | 195 | '#title' => $element['#title'], |
196 | 196 | '#description' => $element['#description'], |
@@ -198,19 +198,19 @@ discard block |
||
198 | 198 | '#multiple' => isset($element['#multiple']) ? $element['#multiple'] : $field['multiple'], |
199 | 199 | '#options' => $options, |
200 | 200 | '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL, |
201 | - ); |
|
201 | + ); |
|
202 | 202 | |
203 | - // Set #element_validate in a way that it will not wipe out other |
|
204 | - // validation functions already set by other modules. |
|
205 | - if (empty($element['#element_validate'])) { |
|
203 | + // Set #element_validate in a way that it will not wipe out other |
|
204 | + // validation functions already set by other modules. |
|
205 | + if (empty($element['#element_validate'])) { |
|
206 | 206 | $element['#element_validate'] = array(); |
207 | - } |
|
208 | - array_unshift($element['#element_validate'], 'optionwidgets_validate'); |
|
207 | + } |
|
208 | + array_unshift($element['#element_validate'], 'optionwidgets_validate'); |
|
209 | 209 | |
210 | - // Make sure field info will be available to the validator which |
|
211 | - // does not get the values in $form. |
|
212 | - $form_state['#field_info'][$field['field_name']] = $field; |
|
213 | - return $element; |
|
210 | + // Make sure field info will be available to the validator which |
|
211 | + // does not get the values in $form. |
|
212 | + $form_state['#field_info'][$field['field_name']] = $field; |
|
213 | + return $element; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -222,23 +222,23 @@ discard block |
||
222 | 222 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
223 | 223 | */ |
224 | 224 | function optionwidgets_select_process($element, $edit, &$form_state, $form) { |
225 | - $field_name = $element['#field_name']; |
|
226 | - $field = $form['#field_info'][$field_name]; |
|
227 | - $field_key = $element['#columns'][0]; |
|
225 | + $field_name = $element['#field_name']; |
|
226 | + $field = $form['#field_info'][$field_name]; |
|
227 | + $field_key = $element['#columns'][0]; |
|
228 | 228 | |
229 | - // See if this element is in the database format or the transformed format, |
|
230 | - // and transform it if necessary. |
|
231 | - if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) { |
|
229 | + // See if this element is in the database format or the transformed format, |
|
230 | + // and transform it if necessary. |
|
231 | + if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) { |
|
232 | 232 | $element['#value'] = optionwidgets_data2form($element, $element['#default_value'], $field); |
233 | - } |
|
233 | + } |
|
234 | 234 | |
235 | - $options = optionwidgets_options($field, FALSE); |
|
235 | + $options = optionwidgets_options($field, FALSE); |
|
236 | 236 | |
237 | - // For this specific widget, HTML should be filtered out and entities left unencoded. |
|
238 | - // See content_allowed_values / content_filter_xss / filter_xss. |
|
239 | - content_allowed_values_filter_html($options); |
|
237 | + // For this specific widget, HTML should be filtered out and entities left unencoded. |
|
238 | + // See content_allowed_values / content_filter_xss / filter_xss. |
|
239 | + content_allowed_values_filter_html($options); |
|
240 | 240 | |
241 | - $element[$field_key] = array( |
|
241 | + $element[$field_key] = array( |
|
242 | 242 | '#type' => 'select', |
243 | 243 | '#title' => $element['#title'], |
244 | 244 | '#description' => $element['#description'], |
@@ -246,24 +246,24 @@ discard block |
||
246 | 246 | '#multiple' => isset($element['#multiple']) ? $element['#multiple'] : $field['multiple'], |
247 | 247 | '#options' => $options, |
248 | 248 | '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL, |
249 | - ); |
|
249 | + ); |
|
250 | 250 | |
251 | - // Set #element_validate in a way that it will not wipe out other |
|
252 | - // validation functions already set by other modules. |
|
253 | - if (empty($element['#element_validate'])) { |
|
251 | + // Set #element_validate in a way that it will not wipe out other |
|
252 | + // validation functions already set by other modules. |
|
253 | + if (empty($element['#element_validate'])) { |
|
254 | 254 | $element['#element_validate'] = array(); |
255 | - } |
|
256 | - array_unshift($element['#element_validate'], 'optionwidgets_validate'); |
|
257 | - |
|
258 | - // Make sure field info will be available to the validator which |
|
259 | - // does not get the values in $form. |
|
260 | - |
|
261 | - // TODO for some reason putting the $field array into $form_state['storage'] |
|
262 | - // causes the node's hook_form_alter to be invoked twice, garbling the |
|
263 | - // results. Need to investigate why that is happening (a core bug?), but |
|
264 | - // in the meantime avoid using $form_state['storage'] to store anything. |
|
265 | - $form_state['#field_info'][$field['field_name']] = $field; |
|
266 | - return $element; |
|
255 | + } |
|
256 | + array_unshift($element['#element_validate'], 'optionwidgets_validate'); |
|
257 | + |
|
258 | + // Make sure field info will be available to the validator which |
|
259 | + // does not get the values in $form. |
|
260 | + |
|
261 | + // TODO for some reason putting the $field array into $form_state['storage'] |
|
262 | + // causes the node's hook_form_alter to be invoked twice, garbling the |
|
263 | + // results. Need to investigate why that is happening (a core bug?), but |
|
264 | + // in the meantime avoid using $form_state['storage'] to store anything. |
|
265 | + $form_state['#field_info'][$field['field_name']] = $field; |
|
266 | + return $element; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -275,64 +275,64 @@ discard block |
||
275 | 275 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
276 | 276 | */ |
277 | 277 | function optionwidgets_onoff_process($element, $edit, &$form_state, $form) { |
278 | - $field_name = $element['#field_name']; |
|
279 | - $field = $form['#field_info'][$field_name]; |
|
280 | - $field_key = $element['#columns'][0]; |
|
278 | + $field_name = $element['#field_name']; |
|
279 | + $field = $form['#field_info'][$field_name]; |
|
280 | + $field_key = $element['#columns'][0]; |
|
281 | 281 | |
282 | - // See if this element is in the database format or the transformed format, |
|
283 | - // and transform it if necessary. |
|
284 | - if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) { |
|
282 | + // See if this element is in the database format or the transformed format, |
|
283 | + // and transform it if necessary. |
|
284 | + if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) { |
|
285 | 285 | $element['#value'] = optionwidgets_data2form($element, $element['#default_value'], $field); |
286 | - } |
|
287 | - $options = optionwidgets_options($field); |
|
288 | - $keys = array_keys($options); |
|
289 | - $on_value = (!empty($keys) && isset($keys[1])) ? $keys[1] : NULL; |
|
290 | - $element[$field_key] = array( |
|
286 | + } |
|
287 | + $options = optionwidgets_options($field); |
|
288 | + $keys = array_keys($options); |
|
289 | + $on_value = (!empty($keys) && isset($keys[1])) ? $keys[1] : NULL; |
|
290 | + $element[$field_key] = array( |
|
291 | 291 | '#type' => 'checkbox', |
292 | 292 | '#title' => isset($options[$on_value]) ? $options[$on_value] : '', |
293 | 293 | '#description' => $element['#description'], |
294 | 294 | '#required' => isset($element['#required']) ? $element['#required'] : $field['required'], |
295 | 295 | '#default_value' => isset($element['#value'][$field_key][0]) ? $element['#value'][$field_key][0] == $on_value : FALSE, |
296 | 296 | '#return_value' => $on_value, |
297 | - ); |
|
297 | + ); |
|
298 | 298 | |
299 | - // Set #element_validate in a way that it will not wipe out other |
|
300 | - // validation functions already set by other modules. |
|
301 | - if (empty($element['#element_validate'])) { |
|
299 | + // Set #element_validate in a way that it will not wipe out other |
|
300 | + // validation functions already set by other modules. |
|
301 | + if (empty($element['#element_validate'])) { |
|
302 | 302 | $element['#element_validate'] = array(); |
303 | - } |
|
304 | - array_unshift($element['#element_validate'], 'optionwidgets_validate'); |
|
303 | + } |
|
304 | + array_unshift($element['#element_validate'], 'optionwidgets_validate'); |
|
305 | 305 | |
306 | - // Make sure field info will be available to the validator which |
|
307 | - // does not get the values in $form. |
|
308 | - $form_state['#field_info'][$field['field_name']] = $field; |
|
309 | - return $element; |
|
306 | + // Make sure field info will be available to the validator which |
|
307 | + // does not get the values in $form. |
|
308 | + $form_state['#field_info'][$field['field_name']] = $field; |
|
309 | + return $element; |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
313 | 313 | * FAPI function to validate optionwidgets element. |
314 | 314 | */ |
315 | 315 | function optionwidgets_validate($element, &$form_state) { |
316 | - // Transpose selections from field => delta to delta => field, |
|
317 | - // turning multiple selected options into multiple parent elements. |
|
318 | - // Immediate parent is the delta, need to get back to parent's parent |
|
319 | - // to create multiple elements. |
|
320 | - $field = $form_state['#field_info'][$element['#field_name']]; |
|
321 | - $items = optionwidgets_form2data($element, $field); |
|
322 | - form_set_value($element, $items, $form_state); |
|
323 | - |
|
324 | - // Check we don't exceed the allowed number of values. |
|
325 | - if ($field['multiple'] >= 2) { |
|
316 | + // Transpose selections from field => delta to delta => field, |
|
317 | + // turning multiple selected options into multiple parent elements. |
|
318 | + // Immediate parent is the delta, need to get back to parent's parent |
|
319 | + // to create multiple elements. |
|
320 | + $field = $form_state['#field_info'][$element['#field_name']]; |
|
321 | + $items = optionwidgets_form2data($element, $field); |
|
322 | + form_set_value($element, $items, $form_state); |
|
323 | + |
|
324 | + // Check we don't exceed the allowed number of values. |
|
325 | + if ($field['multiple'] >= 2) { |
|
326 | 326 | // Filter out 'none' value (if present, will always be in key 0) |
327 | 327 | $field_key = $element['#columns'][0]; |
328 | 328 | if (isset($items[0][$field_key]) && $items[0][$field_key] === '') { |
329 | - unset($items[0]); |
|
329 | + unset($items[0]); |
|
330 | 330 | } |
331 | 331 | if (count($items) > $field['multiple']) { |
332 | - $field_key = $element['#columns'][0]; |
|
333 | - form_error($element[$field_key], t('%name: this field cannot hold more than @count values.', array('%name' => t($field['widget']['label']), '@count' => $field['multiple']))); |
|
332 | + $field_key = $element['#columns'][0]; |
|
333 | + form_error($element[$field_key], t('%name: this field cannot hold more than @count values.', array('%name' => t($field['widget']['label']), '@count' => $field['multiple']))); |
|
334 | + } |
|
334 | 335 | } |
335 | - } |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -341,24 +341,24 @@ discard block |
||
341 | 341 | * transformation is needed. |
342 | 342 | */ |
343 | 343 | function optionwidgets_data2form($element, $items, $field) { |
344 | - $field_key = $element['#columns'][0]; |
|
345 | - $options = optionwidgets_options($field); |
|
344 | + $field_key = $element['#columns'][0]; |
|
345 | + $options = optionwidgets_options($field); |
|
346 | 346 | |
347 | - $items_transposed = content_transpose_array_rows_cols($items); |
|
348 | - $values = (isset($items_transposed[$field_key]) && is_array($items_transposed[$field_key])) ? $items_transposed[$field_key] : array(); |
|
349 | - $keys = array(); |
|
350 | - foreach ($values as $value) { |
|
347 | + $items_transposed = content_transpose_array_rows_cols($items); |
|
348 | + $values = (isset($items_transposed[$field_key]) && is_array($items_transposed[$field_key])) ? $items_transposed[$field_key] : array(); |
|
349 | + $keys = array(); |
|
350 | + foreach ($values as $value) { |
|
351 | 351 | $key = array_search($value, array_keys($options)); |
352 | 352 | if (isset($key)) { |
353 | - $keys[] = $value; |
|
353 | + $keys[] = $value; |
|
354 | + } |
|
354 | 355 | } |
355 | - } |
|
356 | - if ($field['multiple'] || $element['#type'] == 'optionwidgets_onoff') { |
|
356 | + if ($field['multiple'] || $element['#type'] == 'optionwidgets_onoff') { |
|
357 | 357 | return array($field_key => $keys); |
358 | - } |
|
359 | - else { |
|
358 | + } |
|
359 | + else { |
|
360 | 360 | return !empty($keys) ? array($field_key => $value) : array(); |
361 | - } |
|
361 | + } |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -367,22 +367,22 @@ discard block |
||
367 | 367 | * transformation is needed. |
368 | 368 | */ |
369 | 369 | function optionwidgets_form2data($element, $field) { |
370 | - $field_key = $element['#columns'][0]; |
|
371 | - $items = (array) $element[$field_key]['#value']; |
|
372 | - $options = optionwidgets_options($field); |
|
370 | + $field_key = $element['#columns'][0]; |
|
371 | + $items = (array) $element[$field_key]['#value']; |
|
372 | + $options = optionwidgets_options($field); |
|
373 | 373 | |
374 | - $values = array_values($items); |
|
374 | + $values = array_values($items); |
|
375 | 375 | |
376 | - if ($element['#type'] == 'optionwidgets_onoff' && ($values[0] === 0)) { |
|
376 | + if ($element['#type'] == 'optionwidgets_onoff' && ($values[0] === 0)) { |
|
377 | 377 | $keys = array_keys($options); |
378 | 378 | $values = array(array_key_exists(0, $keys) ? $keys[0] : NULL); |
379 | - } |
|
379 | + } |
|
380 | 380 | |
381 | - if (empty($values)) { |
|
381 | + if (empty($values)) { |
|
382 | 382 | $values[] = NULL; |
383 | - } |
|
384 | - $result = content_transpose_array_rows_cols(array($field_key => $values)); |
|
385 | - return $result; |
|
383 | + } |
|
384 | + $result = content_transpose_array_rows_cols(array($field_key => $values)); |
|
385 | + return $result; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -399,18 +399,18 @@ discard block |
||
399 | 399 | * when allowed values list is generated using PHP code. |
400 | 400 | */ |
401 | 401 | function optionwidgets_options($field, $flatten = TRUE) { |
402 | - $function = $field['module'] .'_allowed_values'; |
|
403 | - $options = function_exists($function) ? $function($field) : (array) content_allowed_values($field, $flatten); |
|
404 | - // Add an empty choice for : |
|
405 | - // - non required radios |
|
406 | - // - non required selects |
|
407 | - if (!$field['required']) { |
|
402 | + $function = $field['module'] .'_allowed_values'; |
|
403 | + $options = function_exists($function) ? $function($field) : (array) content_allowed_values($field, $flatten); |
|
404 | + // Add an empty choice for : |
|
405 | + // - non required radios |
|
406 | + // - non required selects |
|
407 | + if (!$field['required']) { |
|
408 | 408 | if ((in_array($field['widget']['type'], array('optionwidgets_buttons', 'nodereference_buttons', 'userreference_buttons')) && !$field['multiple']) |
409 | 409 | || (in_array($field['widget']['type'], array('optionwidgets_select', 'nodereference_select', 'userreference_select')))) { |
410 | - $options = array('' => theme('optionwidgets_none', $field)) + $options; |
|
410 | + $options = array('' => theme('optionwidgets_none', $field)) + $options; |
|
411 | + } |
|
411 | 412 | } |
412 | - } |
|
413 | - return $options; |
|
413 | + return $options; |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | * The default theme will display N/A for a radio list and blank for a select. |
419 | 419 | */ |
420 | 420 | function theme_optionwidgets_none($field) { |
421 | - switch ($field['widget']['type']) { |
|
421 | + switch ($field['widget']['type']) { |
|
422 | 422 | case 'optionwidgets_buttons': |
423 | 423 | case 'nodereference_buttons': |
424 | 424 | case 'userreference_buttons': |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | return t('- None -'); |
430 | 430 | default : |
431 | 431 | return ''; |
432 | - } |
|
432 | + } |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -444,13 +444,13 @@ discard block |
||
444 | 444 | * $element['#delta] is the position of this element in the group |
445 | 445 | */ |
446 | 446 | function theme_optionwidgets_select($element) { |
447 | - return $element['#children']; |
|
447 | + return $element['#children']; |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | function theme_optionwidgets_onoff($element) { |
451 | - return $element['#children']; |
|
451 | + return $element['#children']; |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | function theme_optionwidgets_buttons($element) { |
455 | - return $element['#children']; |
|
455 | + return $element['#children']; |
|
456 | 456 | } |
457 | 457 | \ No newline at end of file |
@@ -419,16 +419,16 @@ |
||
419 | 419 | */ |
420 | 420 | function theme_optionwidgets_none($field) { |
421 | 421 | switch ($field['widget']['type']) { |
422 | - case 'optionwidgets_buttons': |
|
423 | - case 'nodereference_buttons': |
|
424 | - case 'userreference_buttons': |
|
425 | - return t('N/A'); |
|
426 | - case 'optionwidgets_select': |
|
427 | - case 'nodereference_select': |
|
428 | - case 'userreference_select': |
|
429 | - return t('- None -'); |
|
430 | - default : |
|
431 | - return ''; |
|
422 | + case 'optionwidgets_buttons': |
|
423 | + case 'nodereference_buttons': |
|
424 | + case 'userreference_buttons': |
|
425 | + return t('N/A'); |
|
426 | + case 'optionwidgets_select': |
|
427 | + case 'nodereference_select': |
|
428 | + case 'userreference_select': |
|
429 | + return t('- None -'); |
|
430 | + default : |
|
431 | + return ''; |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | $field_type = $form['#field']['type']; |
17 | 17 | $label = $form['#field']['widget']['label']; |
18 | 18 | |
19 | - $output = '<p>'. t('Create a list of options as a list in <strong>Allowed values list</strong> or as an array in PHP code. These values will be the same for %field in all content types.', array('%field' => $label)) .'</p>'; |
|
19 | + $output = '<p>'.t('Create a list of options as a list in <strong>Allowed values list</strong> or as an array in PHP code. These values will be the same for %field in all content types.', array('%field' => $label)).'</p>'; |
|
20 | 20 | |
21 | 21 | if ($widget_type == 'optionwidgets_onoff') { |
22 | - $output .= '<p>'. t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.") .'</p>'; |
|
22 | + $output .= '<p>'.t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.").'</p>'; |
|
23 | 23 | } |
24 | 24 | elseif ($widget_type == 'optionwidgets_buttons') { |
25 | - $output .= '<p>'. t("The 'checkboxes/radio buttons' widget will display checkboxes if the multiple values option is selected for this field, otherwise radios will be displayed.") .'</p>'; |
|
25 | + $output .= '<p>'.t("The 'checkboxes/radio buttons' widget will display checkboxes if the multiple values option is selected for this field, otherwise radios will be displayed.").'</p>'; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | if (in_array($field_type, array('text', 'number_integer', 'number_float', 'number_decimal')) |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | unset($items[0]); |
330 | 330 | } |
331 | 331 | if (count($items) > $field['multiple']) { |
332 | - $field_key = $element['#columns'][0]; |
|
332 | + $field_key = $element['#columns'][0]; |
|
333 | 333 | form_error($element[$field_key], t('%name: this field cannot hold more than @count values.', array('%name' => t($field['widget']['label']), '@count' => $field['multiple']))); |
334 | 334 | } |
335 | 335 | } |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | */ |
369 | 369 | function optionwidgets_form2data($element, $field) { |
370 | 370 | $field_key = $element['#columns'][0]; |
371 | - $items = (array) $element[$field_key]['#value']; |
|
371 | + $items = (array)$element[$field_key]['#value']; |
|
372 | 372 | $options = optionwidgets_options($field); |
373 | 373 | |
374 | 374 | $values = array_values($items); |
@@ -399,8 +399,8 @@ discard block |
||
399 | 399 | * when allowed values list is generated using PHP code. |
400 | 400 | */ |
401 | 401 | function optionwidgets_options($field, $flatten = TRUE) { |
402 | - $function = $field['module'] .'_allowed_values'; |
|
403 | - $options = function_exists($function) ? $function($field) : (array) content_allowed_values($field, $flatten); |
|
402 | + $function = $field['module'].'_allowed_values'; |
|
403 | + $options = function_exists($function) ? $function($field) : (array)content_allowed_values($field, $flatten); |
|
404 | 404 | // Add an empty choice for : |
405 | 405 | // - non required radios |
406 | 406 | // - non required selects |
@@ -20,8 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | if ($widget_type == 'optionwidgets_onoff') { |
22 | 22 | $output .= '<p>'. t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.") .'</p>'; |
23 | - } |
|
24 | - elseif ($widget_type == 'optionwidgets_buttons') { |
|
23 | + } elseif ($widget_type == 'optionwidgets_buttons') { |
|
25 | 24 | $output .= '<p>'. t("The 'checkboxes/radio buttons' widget will display checkboxes if the multiple values option is selected for this field, otherwise radios will be displayed.") .'</p>'; |
26 | 25 | } |
27 | 26 | |
@@ -355,8 +354,7 @@ discard block |
||
355 | 354 | } |
356 | 355 | if ($field['multiple'] || $element['#type'] == 'optionwidgets_onoff') { |
357 | 356 | return array($field_key => $keys); |
358 | - } |
|
359 | - else { |
|
357 | + } else { |
|
360 | 358 | return !empty($keys) ? array($field_key => $value) : array(); |
361 | 359 | } |
362 | 360 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | if (in_array($field_type, array('text', 'number_integer', 'number_float', 'number_decimal')) |
29 | 29 | && in_array($widget_type, array('optionwidgets_onoff', 'optionwidgets_buttons', 'optionwidgets_select'))) { |
30 | - $form['field']['allowed_values_fieldset']['#collapsed'] = FALSE; |
|
30 | + $form['field']['allowed_values_fieldset']['#collapsed'] = false; |
|
31 | 31 | $form['field']['allowed_values_fieldset']['#description'] = $output; |
32 | 32 | |
33 | 33 | // If no 'allowed values' were set yet, add a remainder in the messages area. |
@@ -46,16 +46,16 @@ discard block |
||
46 | 46 | function optionwidgets_theme() { |
47 | 47 | return array( |
48 | 48 | 'optionwidgets_select' => array( |
49 | - 'arguments' => array('element' => NULL), |
|
49 | + 'arguments' => array('element' => null), |
|
50 | 50 | ), |
51 | 51 | 'optionwidgets_buttons' => array( |
52 | - 'arguments' => array('element' => NULL), |
|
52 | + 'arguments' => array('element' => null), |
|
53 | 53 | ), |
54 | 54 | 'optionwidgets_onoff' => array( |
55 | - 'arguments' => array('element' => NULL), |
|
55 | + 'arguments' => array('element' => null), |
|
56 | 56 | ), |
57 | 57 | 'optionwidgets_none' => array( |
58 | - 'arguments' => array('widget_type' => NULL, 'field_name' => NULL, 'node_type' => NULL), |
|
58 | + 'arguments' => array('widget_type' => null, 'field_name' => null, 'node_type' => null), |
|
59 | 59 | ), |
60 | 60 | ); |
61 | 61 | } |
@@ -115,17 +115,17 @@ discard block |
||
115 | 115 | function optionwidgets_elements() { |
116 | 116 | return array( |
117 | 117 | 'optionwidgets_select' => array( |
118 | - '#input' => TRUE, |
|
118 | + '#input' => true, |
|
119 | 119 | '#columns' => array('value'), '#delta' => 0, |
120 | 120 | '#process' => array('optionwidgets_select_process'), |
121 | 121 | ), |
122 | 122 | 'optionwidgets_buttons' => array( |
123 | - '#input' => TRUE, |
|
123 | + '#input' => true, |
|
124 | 124 | '#columns' => array('value'), '#delta' => 0, |
125 | 125 | '#process' => array('optionwidgets_buttons_process'), |
126 | 126 | ), |
127 | 127 | 'optionwidgets_onoff' => array( |
128 | - '#input' => TRUE, |
|
128 | + '#input' => true, |
|
129 | 129 | '#columns' => array('value'), '#delta' => 0, |
130 | 130 | '#process' => array('optionwidgets_onoff_process'), |
131 | 131 | ), |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @return |
164 | 164 | * the form item for a single element for this field |
165 | 165 | */ |
166 | -function optionwidgets_widget(&$form, &$form_state, $field, $items, $delta = NULL) { |
|
166 | +function optionwidgets_widget(&$form, &$form_state, $field, $items, $delta = null) { |
|
167 | 167 | $element = array( |
168 | 168 | '#type' => $field['widget']['type'], |
169 | 169 | '#default_value' => !empty($items) ? $items : array(), |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | '#required' => isset($element['#required']) ? $element['#required'] : $field['required'], |
198 | 198 | '#multiple' => isset($element['#multiple']) ? $element['#multiple'] : $field['multiple'], |
199 | 199 | '#options' => $options, |
200 | - '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL, |
|
200 | + '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : null, |
|
201 | 201 | ); |
202 | 202 | |
203 | 203 | // Set #element_validate in a way that it will not wipe out other |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | $element['#value'] = optionwidgets_data2form($element, $element['#default_value'], $field); |
233 | 233 | } |
234 | 234 | |
235 | - $options = optionwidgets_options($field, FALSE); |
|
235 | + $options = optionwidgets_options($field, false); |
|
236 | 236 | |
237 | 237 | // For this specific widget, HTML should be filtered out and entities left unencoded. |
238 | 238 | // See content_allowed_values / content_filter_xss / filter_xss. |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | '#required' => isset($element['#required']) ? $element['#required'] : $field['required'], |
246 | 246 | '#multiple' => isset($element['#multiple']) ? $element['#multiple'] : $field['multiple'], |
247 | 247 | '#options' => $options, |
248 | - '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL, |
|
248 | + '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : null, |
|
249 | 249 | ); |
250 | 250 | |
251 | 251 | // Set #element_validate in a way that it will not wipe out other |
@@ -286,13 +286,13 @@ discard block |
||
286 | 286 | } |
287 | 287 | $options = optionwidgets_options($field); |
288 | 288 | $keys = array_keys($options); |
289 | - $on_value = (!empty($keys) && isset($keys[1])) ? $keys[1] : NULL; |
|
289 | + $on_value = (!empty($keys) && isset($keys[1])) ? $keys[1] : null; |
|
290 | 290 | $element[$field_key] = array( |
291 | 291 | '#type' => 'checkbox', |
292 | 292 | '#title' => isset($options[$on_value]) ? $options[$on_value] : '', |
293 | 293 | '#description' => $element['#description'], |
294 | 294 | '#required' => isset($element['#required']) ? $element['#required'] : $field['required'], |
295 | - '#default_value' => isset($element['#value'][$field_key][0]) ? $element['#value'][$field_key][0] == $on_value : FALSE, |
|
295 | + '#default_value' => isset($element['#value'][$field_key][0]) ? $element['#value'][$field_key][0] == $on_value : false, |
|
296 | 296 | '#return_value' => $on_value, |
297 | 297 | ); |
298 | 298 | |
@@ -375,11 +375,11 @@ discard block |
||
375 | 375 | |
376 | 376 | if ($element['#type'] == 'optionwidgets_onoff' && ($values[0] === 0)) { |
377 | 377 | $keys = array_keys($options); |
378 | - $values = array(array_key_exists(0, $keys) ? $keys[0] : NULL); |
|
378 | + $values = array(array_key_exists(0, $keys) ? $keys[0] : null); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | if (empty($values)) { |
382 | - $values[] = NULL; |
|
382 | + $values[] = null; |
|
383 | 383 | } |
384 | 384 | $result = content_transpose_array_rows_cols(array($field_key => $values)); |
385 | 385 | return $result; |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | * FALSE can be used to support optgroups for select widgets |
399 | 399 | * when allowed values list is generated using PHP code. |
400 | 400 | */ |
401 | -function optionwidgets_options($field, $flatten = TRUE) { |
|
401 | +function optionwidgets_options($field, $flatten = true) { |
|
402 | 402 | $function = $field['module'] .'_allowed_values'; |
403 | 403 | $options = function_exists($function) ? $function($field) : (array) content_allowed_values($field, $flatten); |
404 | 404 | // Add an empty choice for : |
@@ -5,12 +5,12 @@ discard block |
||
5 | 5 | * Implementation of hook_perm(). |
6 | 6 | */ |
7 | 7 | function content_permissions_perm() { |
8 | - $perms = array(); |
|
9 | - foreach (content_fields() as $field) { |
|
8 | + $perms = array(); |
|
9 | + foreach (content_fields() as $field) { |
|
10 | 10 | $perms[] = 'edit '. $field['field_name']; |
11 | 11 | $perms[] = 'view '. $field['field_name']; |
12 | - } |
|
13 | - return $perms; |
|
12 | + } |
|
13 | + return $perms; |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | * @see content_access(). |
20 | 20 | */ |
21 | 21 | function content_permissions_field_access($op, $field, $account, $node = NULL) { |
22 | - switch ($op) { |
|
22 | + switch ($op) { |
|
23 | 23 | case 'view': |
24 | 24 | case 'edit': |
25 | 25 | return user_access($op .' '. $field['field_name'], $account); |
26 | - } |
|
27 | - return TRUE; |
|
26 | + } |
|
27 | + return TRUE; |
|
28 | 28 | } |
@@ -20,9 +20,9 @@ |
||
20 | 20 | */ |
21 | 21 | function content_permissions_field_access($op, $field, $account, $node = NULL) { |
22 | 22 | switch ($op) { |
23 | - case 'view': |
|
24 | - case 'edit': |
|
25 | - return user_access($op .' '. $field['field_name'], $account); |
|
23 | + case 'view': |
|
24 | + case 'edit': |
|
25 | + return user_access($op .' '. $field['field_name'], $account); |
|
26 | 26 | } |
27 | 27 | return TRUE; |
28 | 28 | } |
@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | function content_permissions_perm() { |
8 | 8 | $perms = array(); |
9 | 9 | foreach (content_fields() as $field) { |
10 | - $perms[] = 'edit '. $field['field_name']; |
|
11 | - $perms[] = 'view '. $field['field_name']; |
|
10 | + $perms[] = 'edit '.$field['field_name']; |
|
11 | + $perms[] = 'view '.$field['field_name']; |
|
12 | 12 | } |
13 | 13 | return $perms; |
14 | 14 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | switch ($op) { |
23 | 23 | case 'view': |
24 | 24 | case 'edit': |
25 | - return user_access($op .' '. $field['field_name'], $account); |
|
25 | + return user_access($op.' '.$field['field_name'], $account); |
|
26 | 26 | } |
27 | 27 | return TRUE; |
28 | 28 | } |
@@ -18,11 +18,11 @@ |
||
18 | 18 | * |
19 | 19 | * @see content_access(). |
20 | 20 | */ |
21 | -function content_permissions_field_access($op, $field, $account, $node = NULL) { |
|
21 | +function content_permissions_field_access($op, $field, $account, $node = null) { |
|
22 | 22 | switch ($op) { |
23 | 23 | case 'view': |
24 | 24 | case 'edit': |
25 | 25 | return user_access($op .' '. $field['field_name'], $account); |
26 | 26 | } |
27 | - return TRUE; |
|
27 | + return true; |
|
28 | 28 | } |
@@ -10,101 +10,101 @@ discard block |
||
10 | 10 | * Implementation of hook_theme(). |
11 | 11 | */ |
12 | 12 | function text_theme() { |
13 | - return array( |
|
13 | + return array( |
|
14 | 14 | 'text_textarea' => array( |
15 | - 'arguments' => array('element' => NULL), |
|
15 | + 'arguments' => array('element' => NULL), |
|
16 | 16 | ), |
17 | 17 | 'text_textfield' => array( |
18 | - 'arguments' => array('element' => NULL), |
|
18 | + 'arguments' => array('element' => NULL), |
|
19 | 19 | ), |
20 | 20 | 'text_formatter_default' => array( |
21 | - 'arguments' => array('element' => NULL), |
|
21 | + 'arguments' => array('element' => NULL), |
|
22 | 22 | ), |
23 | 23 | 'text_formatter_plain' => array( |
24 | - 'arguments' => array('element' => NULL), |
|
24 | + 'arguments' => array('element' => NULL), |
|
25 | 25 | ), |
26 | 26 | 'text_formatter_trimmed' => array( |
27 | - 'arguments' => array('element' => NULL), |
|
27 | + 'arguments' => array('element' => NULL), |
|
28 | 28 | ), |
29 | 29 | 'text_formatter_foo' => array( |
30 | - 'arguments' => array('element' => NULL), |
|
30 | + 'arguments' => array('element' => NULL), |
|
31 | 31 | ), |
32 | - ); |
|
32 | + ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Implementation of hook_field_info(). |
37 | 37 | */ |
38 | 38 | function text_field_info() { |
39 | - return array( |
|
39 | + return array( |
|
40 | 40 | 'text' => array( |
41 | - 'label' => t('Text'), |
|
42 | - 'description' => t('Store text in the database.'), |
|
41 | + 'label' => t('Text'), |
|
42 | + 'description' => t('Store text in the database.'), |
|
43 | 43 | // 'content_icon' => 'icon_content_text.png', |
44 | 44 | ), |
45 | - ); |
|
45 | + ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Implementation of hook_field_settings(). |
50 | 50 | */ |
51 | 51 | function text_field_settings($op, $field) { |
52 | - switch ($op) { |
|
52 | + switch ($op) { |
|
53 | 53 | case 'form': |
54 | 54 | $form = array(); |
55 | - $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)')); |
|
56 | - $form['text_processing'] = array( |
|
55 | + $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)')); |
|
56 | + $form['text_processing'] = array( |
|
57 | 57 | '#type' => 'radios', |
58 | 58 | '#title' => t('Text processing'), |
59 | 59 | '#default_value' => is_numeric($field['text_processing']) ? $field['text_processing'] : 0, |
60 | 60 | '#options' => $options, |
61 | - ); |
|
62 | - $form['max_length'] = array( |
|
61 | + ); |
|
62 | + $form['max_length'] = array( |
|
63 | 63 | '#type' => 'textfield', |
64 | 64 | '#title' => t('Maximum length'), |
65 | 65 | '#default_value' => is_numeric($field['max_length']) ? $field['max_length'] : '', |
66 | 66 | '#required' => FALSE, |
67 | 67 | '#element_validate' => array('_element_validate_integer_positive'), |
68 | 68 | '#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'), |
69 | - ); |
|
70 | - $form['allowed_values_fieldset'] = array( |
|
69 | + ); |
|
70 | + $form['allowed_values_fieldset'] = array( |
|
71 | 71 | '#type' => 'fieldset', |
72 | 72 | '#title' => t('Allowed values'), |
73 | 73 | '#collapsible' => TRUE, |
74 | 74 | '#collapsed' => TRUE, |
75 | - ); |
|
76 | - $form['allowed_values_fieldset']['allowed_values'] = array( |
|
75 | + ); |
|
76 | + $form['allowed_values_fieldset']['allowed_values'] = array( |
|
77 | 77 | '#type' => 'textarea', |
78 | 78 | '#title' => t('Allowed values list'), |
79 | 79 | '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
80 | 80 | '#required' => FALSE, |
81 | 81 | '#rows' => 10, |
82 | 82 | '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
83 | - ); |
|
84 | - $form['allowed_values_fieldset']['advanced_options'] = array( |
|
83 | + ); |
|
84 | + $form['allowed_values_fieldset']['advanced_options'] = array( |
|
85 | 85 | '#type' => 'fieldset', |
86 | 86 | '#title' => t('PHP code'), |
87 | 87 | '#collapsible' => TRUE, |
88 | 88 | '#collapsed' => empty($field['allowed_values_php']), |
89 | - ); |
|
90 | - if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
89 | + ); |
|
90 | + if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
91 | 91 | $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array( |
92 | - '#type' => 'textarea', |
|
93 | - '#title' => t('Code'), |
|
94 | - '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
95 | - '#rows' => 6, |
|
96 | - '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
92 | + '#type' => 'textarea', |
|
93 | + '#title' => t('Code'), |
|
94 | + '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
95 | + '#rows' => 6, |
|
96 | + '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
97 | 97 | ); |
98 | - } |
|
99 | - else { |
|
98 | + } |
|
99 | + else { |
|
100 | 100 | $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
101 | - '#type' => 'item', |
|
102 | - '#title' => t('Code'), |
|
103 | - '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
104 | - '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
101 | + '#type' => 'item', |
|
102 | + '#title' => t('Code'), |
|
103 | + '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
104 | + '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
105 | 105 | ); |
106 | - } |
|
107 | - return $form; |
|
106 | + } |
|
107 | + return $form; |
|
108 | 108 | |
109 | 109 | case 'save': |
110 | 110 | return array('text_processing', 'max_length', 'allowed_values', 'allowed_values_php'); |
@@ -112,18 +112,18 @@ discard block |
||
112 | 112 | case 'database columns': |
113 | 113 | if (empty($field['max_length']) || $field['max_length'] > 255) { |
114 | 114 | $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE); |
115 | - } |
|
116 | - else { |
|
115 | + } |
|
116 | + else { |
|
117 | 117 | $columns['value'] = array('type' => 'varchar', 'length' => $field['max_length'], 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE); |
118 | - } |
|
119 | - if (!empty($field['text_processing'])) { |
|
118 | + } |
|
119 | + if (!empty($field['text_processing'])) { |
|
120 | 120 | $columns['format'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'views' => FALSE); |
121 | - } |
|
122 | - return $columns; |
|
121 | + } |
|
122 | + return $columns; |
|
123 | 123 | |
124 | 124 | case 'views data': |
125 | 125 | $allowed_values = content_allowed_values($field); |
126 | - if (count($allowed_values)) { |
|
126 | + if (count($allowed_values)) { |
|
127 | 127 | $data = content_views_field_views_data($field); |
128 | 128 | $db_info = content_database_info($field); |
129 | 129 | $table_alias = content_views_tablename($field); |
@@ -137,106 +137,106 @@ discard block |
||
137 | 137 | // Argument : swap the handler to the 'many to one' operator. |
138 | 138 | $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
139 | 139 | return $data; |
140 | - } |
|
141 | - } |
|
140 | + } |
|
141 | + } |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | 145 | * Implementation of hook_field(). |
146 | 146 | */ |
147 | 147 | function text_field($op, &$node, $field, &$items, $teaser, $page) { |
148 | - switch ($op) { |
|
148 | + switch ($op) { |
|
149 | 149 | case 'validate': |
150 | 150 | $allowed_values = content_allowed_values($field); |
151 | - if (is_array($items)) { |
|
151 | + if (is_array($items)) { |
|
152 | 152 | foreach ($items as $delta => $item) { |
153 | - $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
154 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
155 | - if (!empty($item['value'])) { |
|
153 | + $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
154 | + if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
155 | + if (!empty($item['value'])) { |
|
156 | 156 | if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) { |
157 | - form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label'])))); |
|
157 | + form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label'])))); |
|
158 | 158 | } |
159 | 159 | if (!empty($field['max_length']) && drupal_strlen($item['value']) > $field['max_length']) { |
160 | - form_set_error($error_element, t('%name: the value may not be longer than %max characters.', array('%name' => $field['widget']['label'], '%max' => $field['max_length']))); |
|
160 | + form_set_error($error_element, t('%name: the value may not be longer than %max characters.', array('%name' => $field['widget']['label'], '%max' => $field['max_length']))); |
|
161 | + } |
|
161 | 162 | } |
162 | - } |
|
163 | 163 | } |
164 | - } |
|
165 | - return $items; |
|
164 | + } |
|
165 | + return $items; |
|
166 | 166 | |
167 | 167 | case 'sanitize': |
168 | 168 | foreach ($items as $delta => $item) { |
169 | 169 | if (!empty($field['text_processing'])) { |
170 | - $text = isset($item['value']) ? check_markup($item['value'], $item['format'], FALSE) : ''; |
|
170 | + $text = isset($item['value']) ? check_markup($item['value'], $item['format'], FALSE) : ''; |
|
171 | 171 | } |
172 | 172 | else { |
173 | - $text = isset($item['value']) ? check_plain($item['value']) : ''; |
|
173 | + $text = isset($item['value']) ? check_plain($item['value']) : ''; |
|
174 | 174 | } |
175 | 175 | $items[$delta]['safe'] = $text; |
176 | - } |
|
177 | - } |
|
176 | + } |
|
177 | + } |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Implementation of hook_content_is_empty(). |
182 | 182 | */ |
183 | 183 | function text_content_is_empty($item, $field) { |
184 | - if (empty($item['value']) && (string)$item['value'] !== '0') { |
|
184 | + if (empty($item['value']) && (string)$item['value'] !== '0') { |
|
185 | 185 | return TRUE; |
186 | - } |
|
187 | - return FALSE; |
|
186 | + } |
|
187 | + return FALSE; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * Implementation of hook_field_formatter_info(). |
192 | 192 | */ |
193 | 193 | function text_field_formatter_info() { |
194 | - return array( |
|
194 | + return array( |
|
195 | 195 | 'default' => array( |
196 | - 'label' => t('Default'), |
|
197 | - 'field types' => array('text'), |
|
198 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
196 | + 'label' => t('Default'), |
|
197 | + 'field types' => array('text'), |
|
198 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
199 | 199 | ), |
200 | 200 | 'plain' => array( |
201 | - 'label' => t('Plain text'), |
|
202 | - 'field types' => array('text'), |
|
203 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
201 | + 'label' => t('Plain text'), |
|
202 | + 'field types' => array('text'), |
|
203 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
204 | 204 | ), |
205 | 205 | 'trimmed' => array( |
206 | - 'label' => t('Trimmed'), |
|
207 | - 'field types' => array('text'), |
|
208 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
206 | + 'label' => t('Trimmed'), |
|
207 | + 'field types' => array('text'), |
|
208 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
209 | 209 | ), |
210 | - ); |
|
210 | + ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | 214 | * Theme function for 'default' text field formatter. |
215 | 215 | */ |
216 | 216 | function theme_text_formatter_default($element) { |
217 | - return ($allowed =_text_allowed_values($element)) ? $allowed : $element['#item']['safe']; |
|
217 | + return ($allowed =_text_allowed_values($element)) ? $allowed : $element['#item']['safe']; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
221 | 221 | * Theme function for 'plain' text field formatter. |
222 | 222 | */ |
223 | 223 | function theme_text_formatter_plain($element) { |
224 | - return ($allowed =_text_allowed_values($element)) ? $allowed : strip_tags($element['#item']['safe']); |
|
224 | + return ($allowed =_text_allowed_values($element)) ? $allowed : strip_tags($element['#item']['safe']); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
228 | 228 | * Theme function for 'trimmed' text field formatter. |
229 | 229 | */ |
230 | 230 | function theme_text_formatter_trimmed($element) { |
231 | - $field = content_fields($element['#field_name'], $element['#type_name']); |
|
232 | - return ($allowed =_text_allowed_values($element)) ? $allowed : node_teaser($element['#item']['safe'], $field['text_processing'] ? $element['#item']['format'] : NULL); |
|
231 | + $field = content_fields($element['#field_name'], $element['#type_name']); |
|
232 | + return ($allowed =_text_allowed_values($element)) ? $allowed : node_teaser($element['#item']['safe'], $field['text_processing'] ? $element['#item']['format'] : NULL); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | function _text_allowed_values($element) { |
236 | - $field = content_fields($element['#field_name'], $element['#type_name']); |
|
237 | - if (($allowed_values = content_allowed_values($field)) && isset($allowed_values[$element['#item']['value']])) { |
|
236 | + $field = content_fields($element['#field_name'], $element['#type_name']); |
|
237 | + if (($allowed_values = content_allowed_values($field)) && isset($allowed_values[$element['#item']['value']])) { |
|
238 | 238 | return $allowed_values[$element['#item']['value']]; |
239 | - } |
|
239 | + } |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -251,24 +251,24 @@ discard block |
||
251 | 251 | * differently. |
252 | 252 | */ |
253 | 253 | function text_widget_info() { |
254 | - return array( |
|
254 | + return array( |
|
255 | 255 | 'text_textfield' => array( |
256 | - 'label' => t('Text field'), |
|
257 | - 'field types' => array('text'), |
|
258 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
259 | - 'callbacks' => array( |
|
256 | + 'label' => t('Text field'), |
|
257 | + 'field types' => array('text'), |
|
258 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
259 | + 'callbacks' => array( |
|
260 | 260 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
261 | - ), |
|
261 | + ), |
|
262 | 262 | ), |
263 | 263 | 'text_textarea' => array( |
264 | - 'label' => t('Text area (multiple rows)'), |
|
265 | - 'field types' => array('text'), |
|
266 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
267 | - 'callbacks' => array( |
|
264 | + 'label' => t('Text area (multiple rows)'), |
|
265 | + 'field types' => array('text'), |
|
266 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
267 | + 'callbacks' => array( |
|
268 | 268 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
269 | - ), |
|
269 | + ), |
|
270 | 270 | ), |
271 | - ); |
|
271 | + ); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -284,56 +284,56 @@ discard block |
||
284 | 284 | * (see nodereference and userreference). |
285 | 285 | */ |
286 | 286 | function text_elements() { |
287 | - return array( |
|
287 | + return array( |
|
288 | 288 | 'text_textfield' => array( |
289 | - '#input' => TRUE, |
|
290 | - '#columns' => array('value'), '#delta' => 0, |
|
291 | - '#process' => array('text_textfield_process'), |
|
292 | - '#autocomplete_path' => FALSE, |
|
289 | + '#input' => TRUE, |
|
290 | + '#columns' => array('value'), '#delta' => 0, |
|
291 | + '#process' => array('text_textfield_process'), |
|
292 | + '#autocomplete_path' => FALSE, |
|
293 | 293 | ), |
294 | 294 | 'text_textarea' => array( |
295 | - '#input' => TRUE, |
|
296 | - '#columns' => array('value', 'format'), '#delta' => 0, |
|
297 | - '#process' => array('text_textarea_process'), |
|
298 | - '#filter_value' => FILTER_FORMAT_DEFAULT, |
|
295 | + '#input' => TRUE, |
|
296 | + '#columns' => array('value', 'format'), '#delta' => 0, |
|
297 | + '#process' => array('text_textarea_process'), |
|
298 | + '#filter_value' => FILTER_FORMAT_DEFAULT, |
|
299 | 299 | ), |
300 | - ); |
|
300 | + ); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
304 | 304 | * Implementation of hook_widget_settings(). |
305 | 305 | */ |
306 | 306 | function text_widget_settings($op, $widget) { |
307 | - switch ($op) { |
|
307 | + switch ($op) { |
|
308 | 308 | case 'form': |
309 | 309 | $form = array(); |
310 | - $rows = (isset($widget['rows']) && is_numeric($widget['rows'])) ? $widget['rows'] : 5; |
|
311 | - $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
312 | - if ($widget['type'] == 'text_textfield') { |
|
310 | + $rows = (isset($widget['rows']) && is_numeric($widget['rows'])) ? $widget['rows'] : 5; |
|
311 | + $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
312 | + if ($widget['type'] == 'text_textfield') { |
|
313 | 313 | $form['rows'] = array('#type' => 'hidden', '#value' => $rows); |
314 | 314 | $form['size'] = array( |
315 | - '#type' => 'textfield', |
|
316 | - '#title' => t('Size of textfield'), |
|
317 | - '#default_value' => $size, |
|
318 | - '#element_validate' => array('_element_validate_integer_positive'), |
|
319 | - '#required' => TRUE, |
|
315 | + '#type' => 'textfield', |
|
316 | + '#title' => t('Size of textfield'), |
|
317 | + '#default_value' => $size, |
|
318 | + '#element_validate' => array('_element_validate_integer_positive'), |
|
319 | + '#required' => TRUE, |
|
320 | 320 | ); |
321 | - } |
|
322 | - else { |
|
321 | + } |
|
322 | + else { |
|
323 | 323 | $form['rows'] = array( |
324 | - '#type' => 'textfield', |
|
325 | - '#title' => t('Rows'), |
|
326 | - '#default_value' => $rows, |
|
327 | - '#element_validate' => array('_element_validate_integer_positive'), |
|
328 | - '#required' => TRUE, |
|
324 | + '#type' => 'textfield', |
|
325 | + '#title' => t('Rows'), |
|
326 | + '#default_value' => $rows, |
|
327 | + '#element_validate' => array('_element_validate_integer_positive'), |
|
328 | + '#required' => TRUE, |
|
329 | 329 | ); |
330 | 330 | $form['size'] = array('#type' => 'hidden', '#value' => $size); |
331 | - } |
|
332 | - return $form; |
|
331 | + } |
|
332 | + return $form; |
|
333 | 333 | |
334 | 334 | case 'save': |
335 | 335 | return array('rows', 'size'); |
336 | - } |
|
336 | + } |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -368,11 +368,11 @@ discard block |
||
368 | 368 | * the form item for a single element for this field |
369 | 369 | */ |
370 | 370 | function text_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
371 | - $element = array( |
|
371 | + $element = array( |
|
372 | 372 | '#type' => $field['widget']['type'], |
373 | 373 | '#default_value' => isset($items[$delta]) ? $items[$delta] : '', |
374 | - ); |
|
375 | - return $element; |
|
374 | + ); |
|
375 | + return $element; |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
@@ -384,10 +384,10 @@ discard block |
||
384 | 384 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
385 | 385 | */ |
386 | 386 | function text_textfield_process($element, $edit, $form_state, $form) { |
387 | - $field = $form['#field_info'][$element['#field_name']]; |
|
388 | - $field_key = $element['#columns'][0]; |
|
389 | - $delta = $element['#delta']; |
|
390 | - $element[$field_key] = array( |
|
387 | + $field = $form['#field_info'][$element['#field_name']]; |
|
388 | + $field_key = $element['#columns'][0]; |
|
389 | + $delta = $element['#delta']; |
|
390 | + $element[$field_key] = array( |
|
391 | 391 | '#type' => 'textfield', |
392 | 392 | '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL, |
393 | 393 | '#autocomplete_path' => $element['#autocomplete_path'], |
@@ -402,24 +402,24 @@ discard block |
||
402 | 402 | '#type_name' => $element['#type_name'], |
403 | 403 | '#delta' => $element['#delta'], |
404 | 404 | '#columns' => $element['#columns'], |
405 | - ); |
|
405 | + ); |
|
406 | 406 | |
407 | - $element[$field_key]['#maxlength'] = !empty($field['max_length']) ? $field['max_length'] : NULL; |
|
407 | + $element[$field_key]['#maxlength'] = !empty($field['max_length']) ? $field['max_length'] : NULL; |
|
408 | 408 | |
409 | - if (!empty($field['text_processing'])) { |
|
409 | + if (!empty($field['text_processing'])) { |
|
410 | 410 | $filter_key = $element['#columns'][1]; |
411 | 411 | $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT; |
412 | 412 | $parents = array_merge($element['#parents'] , array($filter_key)); |
413 | 413 | $element[$filter_key] = filter_form($format, 1, $parents); |
414 | - } |
|
414 | + } |
|
415 | 415 | |
416 | - // Used so that hook_field('validate') knows where to flag an error. |
|
417 | - $element['_error_element'] = array( |
|
416 | + // Used so that hook_field('validate') knows where to flag an error. |
|
417 | + $element['_error_element'] = array( |
|
418 | 418 | '#type' => 'value', |
419 | 419 | '#value' => implode('][', array_merge($element['#parents'], array($field_key))), |
420 | - ); |
|
420 | + ); |
|
421 | 421 | |
422 | - return $element; |
|
422 | + return $element; |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -431,9 +431,9 @@ discard block |
||
431 | 431 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
432 | 432 | */ |
433 | 433 | function text_textarea_process($element, $edit, $form_state, $form) { |
434 | - $field = $form['#field_info'][$element['#field_name']]; |
|
435 | - $field_key = $element['#columns'][0]; |
|
436 | - $element[$field_key] = array( |
|
434 | + $field = $form['#field_info'][$element['#field_name']]; |
|
435 | + $field_key = $element['#columns'][0]; |
|
436 | + $element[$field_key] = array( |
|
437 | 437 | '#type' => 'textarea', |
438 | 438 | '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL, |
439 | 439 | '#rows' => !empty($field['widget']['rows']) ? $field['widget']['rows'] : 10, |
@@ -447,22 +447,22 @@ discard block |
||
447 | 447 | '#type_name' => $element['#type_name'], |
448 | 448 | '#delta' => $element['#delta'], |
449 | 449 | '#columns' => $element['#columns'], |
450 | - ); |
|
450 | + ); |
|
451 | 451 | |
452 | - if (!empty($field['text_processing'])) { |
|
452 | + if (!empty($field['text_processing'])) { |
|
453 | 453 | $filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format'; |
454 | 454 | $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT; |
455 | 455 | $parents = array_merge($element['#parents'] , array($filter_key)); |
456 | 456 | $element[$filter_key] = filter_form($format, 1, $parents); |
457 | - } |
|
457 | + } |
|
458 | 458 | |
459 | - // Used so that hook_field('validate') knows where to flag an error. |
|
460 | - $element['_error_element'] = array( |
|
459 | + // Used so that hook_field('validate') knows where to flag an error. |
|
460 | + $element['_error_element'] = array( |
|
461 | 461 | '#type' => 'value', |
462 | 462 | '#value' => implode('][', array_merge($element['#parents'], array($field_key))), |
463 | - ); |
|
463 | + ); |
|
464 | 464 | |
465 | - return $element; |
|
465 | + return $element; |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -477,9 +477,9 @@ discard block |
||
477 | 477 | * $element['#delta] is the position of this element in the group |
478 | 478 | */ |
479 | 479 | function theme_text_textfield($element) { |
480 | - return $element['#children']; |
|
480 | + return $element['#children']; |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | function theme_text_textarea($element) { |
484 | - return $element['#children']; |
|
484 | + return $element['#children']; |
|
485 | 485 | } |
@@ -50,94 +50,94 @@ discard block |
||
50 | 50 | */ |
51 | 51 | function text_field_settings($op, $field) { |
52 | 52 | switch ($op) { |
53 | - case 'form': |
|
54 | - $form = array(); |
|
55 | - $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)')); |
|
56 | - $form['text_processing'] = array( |
|
57 | - '#type' => 'radios', |
|
58 | - '#title' => t('Text processing'), |
|
59 | - '#default_value' => is_numeric($field['text_processing']) ? $field['text_processing'] : 0, |
|
60 | - '#options' => $options, |
|
61 | - ); |
|
62 | - $form['max_length'] = array( |
|
63 | - '#type' => 'textfield', |
|
64 | - '#title' => t('Maximum length'), |
|
65 | - '#default_value' => is_numeric($field['max_length']) ? $field['max_length'] : '', |
|
66 | - '#required' => FALSE, |
|
67 | - '#element_validate' => array('_element_validate_integer_positive'), |
|
68 | - '#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'), |
|
69 | - ); |
|
70 | - $form['allowed_values_fieldset'] = array( |
|
71 | - '#type' => 'fieldset', |
|
72 | - '#title' => t('Allowed values'), |
|
73 | - '#collapsible' => TRUE, |
|
74 | - '#collapsed' => TRUE, |
|
75 | - ); |
|
76 | - $form['allowed_values_fieldset']['allowed_values'] = array( |
|
53 | + case 'form': |
|
54 | + $form = array(); |
|
55 | + $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)')); |
|
56 | + $form['text_processing'] = array( |
|
57 | + '#type' => 'radios', |
|
58 | + '#title' => t('Text processing'), |
|
59 | + '#default_value' => is_numeric($field['text_processing']) ? $field['text_processing'] : 0, |
|
60 | + '#options' => $options, |
|
61 | + ); |
|
62 | + $form['max_length'] = array( |
|
63 | + '#type' => 'textfield', |
|
64 | + '#title' => t('Maximum length'), |
|
65 | + '#default_value' => is_numeric($field['max_length']) ? $field['max_length'] : '', |
|
66 | + '#required' => FALSE, |
|
67 | + '#element_validate' => array('_element_validate_integer_positive'), |
|
68 | + '#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'), |
|
69 | + ); |
|
70 | + $form['allowed_values_fieldset'] = array( |
|
71 | + '#type' => 'fieldset', |
|
72 | + '#title' => t('Allowed values'), |
|
73 | + '#collapsible' => TRUE, |
|
74 | + '#collapsed' => TRUE, |
|
75 | + ); |
|
76 | + $form['allowed_values_fieldset']['allowed_values'] = array( |
|
77 | + '#type' => 'textarea', |
|
78 | + '#title' => t('Allowed values list'), |
|
79 | + '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
|
80 | + '#required' => FALSE, |
|
81 | + '#rows' => 10, |
|
82 | + '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
|
83 | + ); |
|
84 | + $form['allowed_values_fieldset']['advanced_options'] = array( |
|
85 | + '#type' => 'fieldset', |
|
86 | + '#title' => t('PHP code'), |
|
87 | + '#collapsible' => TRUE, |
|
88 | + '#collapsed' => empty($field['allowed_values_php']), |
|
89 | + ); |
|
90 | + if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
91 | + $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array( |
|
77 | 92 | '#type' => 'textarea', |
78 | - '#title' => t('Allowed values list'), |
|
79 | - '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
|
80 | - '#required' => FALSE, |
|
81 | - '#rows' => 10, |
|
82 | - '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
|
93 | + '#title' => t('Code'), |
|
94 | + '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
95 | + '#rows' => 6, |
|
96 | + '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
83 | 97 | ); |
84 | - $form['allowed_values_fieldset']['advanced_options'] = array( |
|
85 | - '#type' => 'fieldset', |
|
86 | - '#title' => t('PHP code'), |
|
87 | - '#collapsible' => TRUE, |
|
88 | - '#collapsed' => empty($field['allowed_values_php']), |
|
98 | + } |
|
99 | + else { |
|
100 | + $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
|
101 | + '#type' => 'item', |
|
102 | + '#title' => t('Code'), |
|
103 | + '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
104 | + '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
89 | 105 | ); |
90 | - if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
|
91 | - $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array( |
|
92 | - '#type' => 'textarea', |
|
93 | - '#title' => t('Code'), |
|
94 | - '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '', |
|
95 | - '#rows' => 6, |
|
96 | - '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
|
97 | - ); |
|
98 | - } |
|
99 | - else { |
|
100 | - $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
|
101 | - '#type' => 'item', |
|
102 | - '#title' => t('Code'), |
|
103 | - '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
104 | - '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
|
105 | - ); |
|
106 | - } |
|
107 | - return $form; |
|
108 | - |
|
109 | - case 'save': |
|
110 | - return array('text_processing', 'max_length', 'allowed_values', 'allowed_values_php'); |
|
111 | - |
|
112 | - case 'database columns': |
|
113 | - if (empty($field['max_length']) || $field['max_length'] > 255) { |
|
114 | - $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE); |
|
115 | - } |
|
116 | - else { |
|
117 | - $columns['value'] = array('type' => 'varchar', 'length' => $field['max_length'], 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE); |
|
118 | - } |
|
119 | - if (!empty($field['text_processing'])) { |
|
120 | - $columns['format'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'views' => FALSE); |
|
121 | - } |
|
122 | - return $columns; |
|
123 | - |
|
124 | - case 'views data': |
|
125 | - $allowed_values = content_allowed_values($field); |
|
126 | - if (count($allowed_values)) { |
|
127 | - $data = content_views_field_views_data($field); |
|
128 | - $db_info = content_database_info($field); |
|
129 | - $table_alias = content_views_tablename($field); |
|
130 | - |
|
131 | - // Filter: Add a 'many to one' filter. |
|
132 | - $copy = $data[$table_alias][$field['field_name'] .'_value']; |
|
133 | - $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
|
134 | - $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
135 | - unset($copy['field'], $copy['argument'], $copy['sort']); |
|
136 | - $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
|
137 | - // Argument : swap the handler to the 'many to one' operator. |
|
138 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
139 | - return $data; |
|
140 | - } |
|
106 | + } |
|
107 | + return $form; |
|
108 | + |
|
109 | + case 'save': |
|
110 | + return array('text_processing', 'max_length', 'allowed_values', 'allowed_values_php'); |
|
111 | + |
|
112 | + case 'database columns': |
|
113 | + if (empty($field['max_length']) || $field['max_length'] > 255) { |
|
114 | + $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE); |
|
115 | + } |
|
116 | + else { |
|
117 | + $columns['value'] = array('type' => 'varchar', 'length' => $field['max_length'], 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE); |
|
118 | + } |
|
119 | + if (!empty($field['text_processing'])) { |
|
120 | + $columns['format'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'views' => FALSE); |
|
121 | + } |
|
122 | + return $columns; |
|
123 | + |
|
124 | + case 'views data': |
|
125 | + $allowed_values = content_allowed_values($field); |
|
126 | + if (count($allowed_values)) { |
|
127 | + $data = content_views_field_views_data($field); |
|
128 | + $db_info = content_database_info($field); |
|
129 | + $table_alias = content_views_tablename($field); |
|
130 | + |
|
131 | + // Filter: Add a 'many to one' filter. |
|
132 | + $copy = $data[$table_alias][$field['field_name'] .'_value']; |
|
133 | + $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
|
134 | + $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
135 | + unset($copy['field'], $copy['argument'], $copy['sort']); |
|
136 | + $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
|
137 | + // Argument : swap the handler to the 'many to one' operator. |
|
138 | + $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
139 | + return $data; |
|
140 | + } |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
@@ -146,34 +146,34 @@ discard block |
||
146 | 146 | */ |
147 | 147 | function text_field($op, &$node, $field, &$items, $teaser, $page) { |
148 | 148 | switch ($op) { |
149 | - case 'validate': |
|
150 | - $allowed_values = content_allowed_values($field); |
|
151 | - if (is_array($items)) { |
|
152 | - foreach ($items as $delta => $item) { |
|
153 | - $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
154 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
155 | - if (!empty($item['value'])) { |
|
156 | - if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) { |
|
157 | - form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label'])))); |
|
158 | - } |
|
159 | - if (!empty($field['max_length']) && drupal_strlen($item['value']) > $field['max_length']) { |
|
160 | - form_set_error($error_element, t('%name: the value may not be longer than %max characters.', array('%name' => $field['widget']['label'], '%max' => $field['max_length']))); |
|
161 | - } |
|
149 | + case 'validate': |
|
150 | + $allowed_values = content_allowed_values($field); |
|
151 | + if (is_array($items)) { |
|
152 | + foreach ($items as $delta => $item) { |
|
153 | + $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
154 | + if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
155 | + if (!empty($item['value'])) { |
|
156 | + if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) { |
|
157 | + form_set_error($error_element, t('%name: illegal value.', array('%name' => t($field['widget']['label'])))); |
|
158 | + } |
|
159 | + if (!empty($field['max_length']) && drupal_strlen($item['value']) > $field['max_length']) { |
|
160 | + form_set_error($error_element, t('%name: the value may not be longer than %max characters.', array('%name' => $field['widget']['label'], '%max' => $field['max_length']))); |
|
162 | 161 | } |
163 | 162 | } |
164 | 163 | } |
165 | - return $items; |
|
164 | + } |
|
165 | + return $items; |
|
166 | 166 | |
167 | - case 'sanitize': |
|
168 | - foreach ($items as $delta => $item) { |
|
169 | - if (!empty($field['text_processing'])) { |
|
170 | - $text = isset($item['value']) ? check_markup($item['value'], $item['format'], FALSE) : ''; |
|
171 | - } |
|
172 | - else { |
|
173 | - $text = isset($item['value']) ? check_plain($item['value']) : ''; |
|
174 | - } |
|
175 | - $items[$delta]['safe'] = $text; |
|
167 | + case 'sanitize': |
|
168 | + foreach ($items as $delta => $item) { |
|
169 | + if (!empty($field['text_processing'])) { |
|
170 | + $text = isset($item['value']) ? check_markup($item['value'], $item['format'], FALSE) : ''; |
|
171 | + } |
|
172 | + else { |
|
173 | + $text = isset($item['value']) ? check_plain($item['value']) : ''; |
|
176 | 174 | } |
175 | + $items[$delta]['safe'] = $text; |
|
176 | + } |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -305,34 +305,34 @@ discard block |
||
305 | 305 | */ |
306 | 306 | function text_widget_settings($op, $widget) { |
307 | 307 | switch ($op) { |
308 | - case 'form': |
|
309 | - $form = array(); |
|
310 | - $rows = (isset($widget['rows']) && is_numeric($widget['rows'])) ? $widget['rows'] : 5; |
|
311 | - $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
312 | - if ($widget['type'] == 'text_textfield') { |
|
313 | - $form['rows'] = array('#type' => 'hidden', '#value' => $rows); |
|
314 | - $form['size'] = array( |
|
315 | - '#type' => 'textfield', |
|
316 | - '#title' => t('Size of textfield'), |
|
317 | - '#default_value' => $size, |
|
318 | - '#element_validate' => array('_element_validate_integer_positive'), |
|
319 | - '#required' => TRUE, |
|
320 | - ); |
|
321 | - } |
|
322 | - else { |
|
323 | - $form['rows'] = array( |
|
324 | - '#type' => 'textfield', |
|
325 | - '#title' => t('Rows'), |
|
326 | - '#default_value' => $rows, |
|
327 | - '#element_validate' => array('_element_validate_integer_positive'), |
|
328 | - '#required' => TRUE, |
|
329 | - ); |
|
330 | - $form['size'] = array('#type' => 'hidden', '#value' => $size); |
|
331 | - } |
|
332 | - return $form; |
|
308 | + case 'form': |
|
309 | + $form = array(); |
|
310 | + $rows = (isset($widget['rows']) && is_numeric($widget['rows'])) ? $widget['rows'] : 5; |
|
311 | + $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
312 | + if ($widget['type'] == 'text_textfield') { |
|
313 | + $form['rows'] = array('#type' => 'hidden', '#value' => $rows); |
|
314 | + $form['size'] = array( |
|
315 | + '#type' => 'textfield', |
|
316 | + '#title' => t('Size of textfield'), |
|
317 | + '#default_value' => $size, |
|
318 | + '#element_validate' => array('_element_validate_integer_positive'), |
|
319 | + '#required' => TRUE, |
|
320 | + ); |
|
321 | + } |
|
322 | + else { |
|
323 | + $form['rows'] = array( |
|
324 | + '#type' => 'textfield', |
|
325 | + '#title' => t('Rows'), |
|
326 | + '#default_value' => $rows, |
|
327 | + '#element_validate' => array('_element_validate_integer_positive'), |
|
328 | + '#required' => TRUE, |
|
329 | + ); |
|
330 | + $form['size'] = array('#type' => 'hidden', '#value' => $size); |
|
331 | + } |
|
332 | + return $form; |
|
333 | 333 | |
334 | - case 'save': |
|
335 | - return array('rows', 'size'); |
|
334 | + case 'save': |
|
335 | + return array('rows', 'size'); |
|
336 | 336 | } |
337 | 337 | } |
338 | 338 |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
101 | 101 | '#type' => 'item', |
102 | 102 | '#title' => t('Code'), |
103 | - '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('<none>'), |
|
103 | + '#value' => !empty($field['allowed_values_php']) ? '<code>'.check_plain($field['allowed_values_php']).'</code>' : t('<none>'), |
|
104 | 104 | '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'), |
105 | 105 | ); |
106 | 106 | } |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | $table_alias = content_views_tablename($field); |
130 | 130 | |
131 | 131 | // Filter: Add a 'many to one' filter. |
132 | - $copy = $data[$table_alias][$field['field_name'] .'_value']; |
|
132 | + $copy = $data[$table_alias][$field['field_name'].'_value']; |
|
133 | 133 | $copy['title'] = t('@label (!name) - Allowed values', array('@label' => t($field['widget']['label']), '!name' => $field['field_name'])); |
134 | 134 | $copy['filter']['handler'] = 'content_handler_filter_many_to_one'; |
135 | 135 | unset($copy['field'], $copy['argument'], $copy['sort']); |
136 | - $data[$table_alias][$field['field_name'] .'_value_many_to_one'] = $copy; |
|
136 | + $data[$table_alias][$field['field_name'].'_value_many_to_one'] = $copy; |
|
137 | 137 | // Argument : swap the handler to the 'many to one' operator. |
138 | - $data[$table_alias][$field['field_name'] .'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
138 | + $data[$table_alias][$field['field_name'].'_value']['argument']['handler'] = 'content_handler_argument_many_to_one'; |
|
139 | 139 | return $data; |
140 | 140 | } |
141 | 141 | } |
@@ -214,14 +214,14 @@ discard block |
||
214 | 214 | * Theme function for 'default' text field formatter. |
215 | 215 | */ |
216 | 216 | function theme_text_formatter_default($element) { |
217 | - return ($allowed =_text_allowed_values($element)) ? $allowed : $element['#item']['safe']; |
|
217 | + return ($allowed = _text_allowed_values($element)) ? $allowed : $element['#item']['safe']; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
221 | 221 | * Theme function for 'plain' text field formatter. |
222 | 222 | */ |
223 | 223 | function theme_text_formatter_plain($element) { |
224 | - return ($allowed =_text_allowed_values($element)) ? $allowed : strip_tags($element['#item']['safe']); |
|
224 | + return ($allowed = _text_allowed_values($element)) ? $allowed : strip_tags($element['#item']['safe']); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | */ |
230 | 230 | function theme_text_formatter_trimmed($element) { |
231 | 231 | $field = content_fields($element['#field_name'], $element['#type_name']); |
232 | - return ($allowed =_text_allowed_values($element)) ? $allowed : node_teaser($element['#item']['safe'], $field['text_processing'] ? $element['#item']['format'] : NULL); |
|
232 | + return ($allowed = _text_allowed_values($element)) ? $allowed : node_teaser($element['#item']['safe'], $field['text_processing'] ? $element['#item']['format'] : NULL); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | function _text_allowed_values($element) { |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | if (!empty($field['text_processing'])) { |
410 | 410 | $filter_key = $element['#columns'][1]; |
411 | 411 | $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT; |
412 | - $parents = array_merge($element['#parents'] , array($filter_key)); |
|
412 | + $parents = array_merge($element['#parents'], array($filter_key)); |
|
413 | 413 | $element[$filter_key] = filter_form($format, 1, $parents); |
414 | 414 | } |
415 | 415 | |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | */ |
433 | 433 | function text_textarea_process($element, $edit, $form_state, $form) { |
434 | 434 | $field = $form['#field_info'][$element['#field_name']]; |
435 | - $field_key = $element['#columns'][0]; |
|
435 | + $field_key = $element['#columns'][0]; |
|
436 | 436 | $element[$field_key] = array( |
437 | 437 | '#type' => 'textarea', |
438 | 438 | '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL, |
@@ -450,9 +450,9 @@ discard block |
||
450 | 450 | ); |
451 | 451 | |
452 | 452 | if (!empty($field['text_processing'])) { |
453 | - $filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format'; |
|
453 | + $filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format'; |
|
454 | 454 | $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT; |
455 | - $parents = array_merge($element['#parents'] , array($filter_key)); |
|
455 | + $parents = array_merge($element['#parents'], array($filter_key)); |
|
456 | 456 | $element[$filter_key] = filter_form($format, 1, $parents); |
457 | 457 | } |
458 | 458 |
@@ -95,8 +95,7 @@ discard block |
||
95 | 95 | '#rows' => 6, |
96 | 96 | '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'), |
97 | 97 | ); |
98 | - } |
|
99 | - else { |
|
98 | + } else { |
|
100 | 99 | $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array( |
101 | 100 | '#type' => 'item', |
102 | 101 | '#title' => t('Code'), |
@@ -112,8 +111,7 @@ discard block |
||
112 | 111 | case 'database columns': |
113 | 112 | if (empty($field['max_length']) || $field['max_length'] > 255) { |
114 | 113 | $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE); |
115 | - } |
|
116 | - else { |
|
114 | + } else { |
|
117 | 115 | $columns['value'] = array('type' => 'varchar', 'length' => $field['max_length'], 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE); |
118 | 116 | } |
119 | 117 | if (!empty($field['text_processing'])) { |
@@ -168,8 +166,7 @@ discard block |
||
168 | 166 | foreach ($items as $delta => $item) { |
169 | 167 | if (!empty($field['text_processing'])) { |
170 | 168 | $text = isset($item['value']) ? check_markup($item['value'], $item['format'], FALSE) : ''; |
171 | - } |
|
172 | - else { |
|
169 | + } else { |
|
173 | 170 | $text = isset($item['value']) ? check_plain($item['value']) : ''; |
174 | 171 | } |
175 | 172 | $items[$delta]['safe'] = $text; |
@@ -318,8 +315,7 @@ discard block |
||
318 | 315 | '#element_validate' => array('_element_validate_integer_positive'), |
319 | 316 | '#required' => TRUE, |
320 | 317 | ); |
321 | - } |
|
322 | - else { |
|
318 | + } else { |
|
323 | 319 | $form['rows'] = array( |
324 | 320 | '#type' => 'textfield', |
325 | 321 | '#title' => t('Rows'), |
@@ -12,22 +12,22 @@ discard block |
||
12 | 12 | function text_theme() { |
13 | 13 | return array( |
14 | 14 | 'text_textarea' => array( |
15 | - 'arguments' => array('element' => NULL), |
|
15 | + 'arguments' => array('element' => null), |
|
16 | 16 | ), |
17 | 17 | 'text_textfield' => array( |
18 | - 'arguments' => array('element' => NULL), |
|
18 | + 'arguments' => array('element' => null), |
|
19 | 19 | ), |
20 | 20 | 'text_formatter_default' => array( |
21 | - 'arguments' => array('element' => NULL), |
|
21 | + 'arguments' => array('element' => null), |
|
22 | 22 | ), |
23 | 23 | 'text_formatter_plain' => array( |
24 | - 'arguments' => array('element' => NULL), |
|
24 | + 'arguments' => array('element' => null), |
|
25 | 25 | ), |
26 | 26 | 'text_formatter_trimmed' => array( |
27 | - 'arguments' => array('element' => NULL), |
|
27 | + 'arguments' => array('element' => null), |
|
28 | 28 | ), |
29 | 29 | 'text_formatter_foo' => array( |
30 | - 'arguments' => array('element' => NULL), |
|
30 | + 'arguments' => array('element' => null), |
|
31 | 31 | ), |
32 | 32 | ); |
33 | 33 | } |
@@ -63,28 +63,28 @@ discard block |
||
63 | 63 | '#type' => 'textfield', |
64 | 64 | '#title' => t('Maximum length'), |
65 | 65 | '#default_value' => is_numeric($field['max_length']) ? $field['max_length'] : '', |
66 | - '#required' => FALSE, |
|
66 | + '#required' => false, |
|
67 | 67 | '#element_validate' => array('_element_validate_integer_positive'), |
68 | 68 | '#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'), |
69 | 69 | ); |
70 | 70 | $form['allowed_values_fieldset'] = array( |
71 | 71 | '#type' => 'fieldset', |
72 | 72 | '#title' => t('Allowed values'), |
73 | - '#collapsible' => TRUE, |
|
74 | - '#collapsed' => TRUE, |
|
73 | + '#collapsible' => true, |
|
74 | + '#collapsed' => true, |
|
75 | 75 | ); |
76 | 76 | $form['allowed_values_fieldset']['allowed_values'] = array( |
77 | 77 | '#type' => 'textarea', |
78 | 78 | '#title' => t('Allowed values list'), |
79 | 79 | '#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '', |
80 | - '#required' => FALSE, |
|
80 | + '#required' => false, |
|
81 | 81 | '#rows' => 10, |
82 | 82 | '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array('%type' => $field['type'], '@tags' => _content_filter_xss_display_allowed_tags())), |
83 | 83 | ); |
84 | 84 | $form['allowed_values_fieldset']['advanced_options'] = array( |
85 | 85 | '#type' => 'fieldset', |
86 | 86 | '#title' => t('PHP code'), |
87 | - '#collapsible' => TRUE, |
|
87 | + '#collapsible' => true, |
|
88 | 88 | '#collapsed' => empty($field['allowed_values_php']), |
89 | 89 | ); |
90 | 90 | if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | |
112 | 112 | case 'database columns': |
113 | 113 | if (empty($field['max_length']) || $field['max_length'] > 255) { |
114 | - $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE); |
|
114 | + $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => false, 'sortable' => true, 'views' => true); |
|
115 | 115 | } |
116 | 116 | else { |
117 | - $columns['value'] = array('type' => 'varchar', 'length' => $field['max_length'], 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE); |
|
117 | + $columns['value'] = array('type' => 'varchar', 'length' => $field['max_length'], 'not null' => false, 'sortable' => true, 'views' => true); |
|
118 | 118 | } |
119 | 119 | if (!empty($field['text_processing'])) { |
120 | - $columns['format'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'views' => FALSE); |
|
120 | + $columns['format'] = array('type' => 'int', 'unsigned' => true, 'not null' => false, 'views' => false); |
|
121 | 121 | } |
122 | 122 | return $columns; |
123 | 123 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | case 'sanitize': |
168 | 168 | foreach ($items as $delta => $item) { |
169 | 169 | if (!empty($field['text_processing'])) { |
170 | - $text = isset($item['value']) ? check_markup($item['value'], $item['format'], FALSE) : ''; |
|
170 | + $text = isset($item['value']) ? check_markup($item['value'], $item['format'], false) : ''; |
|
171 | 171 | } |
172 | 172 | else { |
173 | 173 | $text = isset($item['value']) ? check_plain($item['value']) : ''; |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | */ |
183 | 183 | function text_content_is_empty($item, $field) { |
184 | 184 | if (empty($item['value']) && (string)$item['value'] !== '0') { |
185 | - return TRUE; |
|
185 | + return true; |
|
186 | 186 | } |
187 | - return FALSE; |
|
187 | + return false; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | */ |
230 | 230 | function theme_text_formatter_trimmed($element) { |
231 | 231 | $field = content_fields($element['#field_name'], $element['#type_name']); |
232 | - return ($allowed =_text_allowed_values($element)) ? $allowed : node_teaser($element['#item']['safe'], $field['text_processing'] ? $element['#item']['format'] : NULL); |
|
232 | + return ($allowed =_text_allowed_values($element)) ? $allowed : node_teaser($element['#item']['safe'], $field['text_processing'] ? $element['#item']['format'] : null); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | function _text_allowed_values($element) { |
@@ -286,13 +286,13 @@ discard block |
||
286 | 286 | function text_elements() { |
287 | 287 | return array( |
288 | 288 | 'text_textfield' => array( |
289 | - '#input' => TRUE, |
|
289 | + '#input' => true, |
|
290 | 290 | '#columns' => array('value'), '#delta' => 0, |
291 | 291 | '#process' => array('text_textfield_process'), |
292 | - '#autocomplete_path' => FALSE, |
|
292 | + '#autocomplete_path' => false, |
|
293 | 293 | ), |
294 | 294 | 'text_textarea' => array( |
295 | - '#input' => TRUE, |
|
295 | + '#input' => true, |
|
296 | 296 | '#columns' => array('value', 'format'), '#delta' => 0, |
297 | 297 | '#process' => array('text_textarea_process'), |
298 | 298 | '#filter_value' => FILTER_FORMAT_DEFAULT, |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | '#title' => t('Size of textfield'), |
317 | 317 | '#default_value' => $size, |
318 | 318 | '#element_validate' => array('_element_validate_integer_positive'), |
319 | - '#required' => TRUE, |
|
319 | + '#required' => true, |
|
320 | 320 | ); |
321 | 321 | } |
322 | 322 | else { |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | '#title' => t('Rows'), |
326 | 326 | '#default_value' => $rows, |
327 | 327 | '#element_validate' => array('_element_validate_integer_positive'), |
328 | - '#required' => TRUE, |
|
328 | + '#required' => true, |
|
329 | 329 | ); |
330 | 330 | $form['size'] = array('#type' => 'hidden', '#value' => $size); |
331 | 331 | } |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | $delta = $element['#delta']; |
390 | 390 | $element[$field_key] = array( |
391 | 391 | '#type' => 'textfield', |
392 | - '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL, |
|
392 | + '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : null, |
|
393 | 393 | '#autocomplete_path' => $element['#autocomplete_path'], |
394 | 394 | '#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 60, |
395 | 395 | '#attributes' => array('class' => 'text'), |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | '#columns' => $element['#columns'], |
405 | 405 | ); |
406 | 406 | |
407 | - $element[$field_key]['#maxlength'] = !empty($field['max_length']) ? $field['max_length'] : NULL; |
|
407 | + $element[$field_key]['#maxlength'] = !empty($field['max_length']) ? $field['max_length'] : null; |
|
408 | 408 | |
409 | 409 | if (!empty($field['text_processing'])) { |
410 | 410 | $filter_key = $element['#columns'][1]; |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | $field_key = $element['#columns'][0]; |
436 | 436 | $element[$field_key] = array( |
437 | 437 | '#type' => 'textarea', |
438 | - '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL, |
|
438 | + '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : null, |
|
439 | 439 | '#rows' => !empty($field['widget']['rows']) ? $field['widget']['rows'] : 10, |
440 | 440 | '#weight' => 0, |
441 | 441 | // The following values were set by the content module and need |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * Implementation of hook_ctools_relationships(). |
11 | 11 | */ |
12 | 12 | function userreference_user_from_userref_ctools_relationships() { |
13 | - return array( |
|
13 | + return array( |
|
14 | 14 | 'title' => t('User from reference'), |
15 | 15 | 'keyword' => 'userreference', |
16 | 16 | 'description' => t('Adds a user from a user reference in a node context; if multiple users are referenced, this will get the first referenced user only.'), |
@@ -18,48 +18,48 @@ discard block |
||
18 | 18 | 'context' => 'userreference_user_from_userref_context', |
19 | 19 | 'settings form' => 'userreference_user_from_userref_settings_form', |
20 | 20 | 'settings form validate' => 'userreference_user_from_userref_settings_form_validate', |
21 | - ); |
|
21 | + ); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Return a new ctools context based on an existing context. |
26 | 26 | */ |
27 | 27 | function userreference_user_from_userref_context($context, $conf) { |
28 | - // If unset it wants a generic, unfilled context, which is just NULL. |
|
29 | - if (empty($context->data)) { |
|
28 | + // If unset it wants a generic, unfilled context, which is just NULL. |
|
29 | + if (empty($context->data)) { |
|
30 | 30 | return ctools_context_create_empty('user', NULL); |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - // Prevent whitescreens on stale data. |
|
34 | - if (empty($conf)) { |
|
33 | + // Prevent whitescreens on stale data. |
|
34 | + if (empty($conf)) { |
|
35 | 35 | return ctools_context_create_empty('user', NULL); |
36 | - } |
|
36 | + } |
|
37 | 37 | |
38 | - if (isset($context->data->{$conf['field_name']}[0]['uid']) && ($uid = $context->data->{$conf['field_name']}[0]['uid'])) { |
|
38 | + if (isset($context->data->{$conf['field_name']}[0]['uid']) && ($uid = $context->data->{$conf['field_name']}[0]['uid'])) { |
|
39 | 39 | if ($account = user_load(array('uid' => $uid))) { |
40 | - return ctools_context_create('user', $account); |
|
40 | + return ctools_context_create('user', $account); |
|
41 | + } |
|
41 | 42 | } |
42 | - } |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Settings form for the ctools relationship. |
47 | 47 | */ |
48 | 48 | function userreference_user_from_userref_settings_form($conf) { |
49 | - $options = array(); |
|
50 | - foreach (content_fields() as $field) { |
|
49 | + $options = array(); |
|
50 | + foreach (content_fields() as $field) { |
|
51 | 51 | if ($field['type'] == 'userreference') { |
52 | - $options[$field['field_name']] = t($field['widget']['label']); |
|
52 | + $options[$field['field_name']] = t($field['widget']['label']); |
|
53 | + } |
|
53 | 54 | } |
54 | - } |
|
55 | - $form['field_name'] = array( |
|
55 | + $form['field_name'] = array( |
|
56 | 56 | '#title' => t('User reference field'), |
57 | 57 | '#type' => 'select', |
58 | 58 | '#options' => $options, |
59 | 59 | '#default_value' => isset($conf['field_name']) ? $conf['field_name'] : '', |
60 | 60 | '#prefix' => '<div class="clear-block">', |
61 | 61 | '#suffix' => '</div>', |
62 | - ); |
|
62 | + ); |
|
63 | 63 | |
64 | - return $form; |
|
64 | + return $form; |
|
65 | 65 | } |
@@ -27,12 +27,12 @@ |
||
27 | 27 | function userreference_user_from_userref_context($context, $conf) { |
28 | 28 | // If unset it wants a generic, unfilled context, which is just NULL. |
29 | 29 | if (empty($context->data)) { |
30 | - return ctools_context_create_empty('user', NULL); |
|
30 | + return ctools_context_create_empty('user', null); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | // Prevent whitescreens on stale data. |
34 | 34 | if (empty($conf)) { |
35 | - return ctools_context_create_empty('user', NULL); |
|
35 | + return ctools_context_create_empty('user', null); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | if (isset($context->data->{$conf['field_name']}[0]['uid']) && ($uid = $context->data->{$conf['field_name']}[0]['uid'])) { |