@@ -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'])) { |
@@ -10,39 +10,39 @@ discard block |
||
10 | 10 | * Implementation of hook_rules_action_info() |
11 | 11 | */ |
12 | 12 | function userreference_rules_action_info() { |
13 | - $info = array(); |
|
14 | - $info['userreference_rules_action_load'] = array( |
|
13 | + $info = array(); |
|
14 | + $info['userreference_rules_action_load'] = array( |
|
15 | 15 | 'label' => t('Load a referenced user'), |
16 | 16 | 'arguments' => array( |
17 | - 'node' => array( |
|
17 | + 'node' => array( |
|
18 | 18 | 'type' => 'node', |
19 | 19 | 'label' => t('Content containing the user reference field'), |
20 | - ), |
|
20 | + ), |
|
21 | 21 | ), |
22 | 22 | 'new variables' => array( |
23 | - 'referenced_user' => array( |
|
23 | + 'referenced_user' => array( |
|
24 | 24 | 'type' => 'user', |
25 | 25 | 'label' => t('Referenced user'), |
26 | - ), |
|
26 | + ), |
|
27 | 27 | ), |
28 | 28 | 'module' => 'CCK', |
29 | 29 | 'help' => t('Note that if the field has multiple values, only the first user will be loaded.'), |
30 | - ); |
|
31 | - return $info; |
|
30 | + ); |
|
31 | + return $info; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | function userreference_rules_action_load($node, $settings) { |
35 | - $uid = $node->{$settings['field']}[0]['uid']; |
|
36 | - if (isset($uid)) { |
|
35 | + $uid = $node->{$settings['field']}[0]['uid']; |
|
36 | + if (isset($uid)) { |
|
37 | 37 | $user = user_load(array('uid' => $uid)); |
38 | 38 | return array('referenced_user' => $user); |
39 | - } |
|
39 | + } |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | function userreference_rules_action_load_form($settings, &$form) { |
43 | - $settings += array('field' => ''); |
|
44 | - $options = content_rules_get_field_names_by_type('userreference'); |
|
45 | - $form['settings']['field'] = array( |
|
43 | + $settings += array('field' => ''); |
|
44 | + $options = content_rules_get_field_names_by_type('userreference'); |
|
45 | + $form['settings']['field'] = array( |
|
46 | 46 | '#type' => 'select', |
47 | 47 | '#title' => t('Field'), |
48 | 48 | '#default_value' => $settings['field'], |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | '#required' => TRUE, |
51 | 51 | '#disabled' => empty($options), |
52 | 52 | '#description' => empty($options) ? t('There are no userreference fields defined.') : '', |
53 | - ); |
|
53 | + ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -58,5 +58,5 @@ discard block |
||
58 | 58 | * "workflow_ng_action_load_referenced_user" to the equivalent rules action. |
59 | 59 | */ |
60 | 60 | function workflow_ng_action_load_referenced_user_upgrade(&$element) { |
61 | - $element['#name'] = 'userreference_rules_action_load'; |
|
61 | + $element['#name'] = 'userreference_rules_action_load'; |
|
62 | 62 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | '#title' => t('Field'), |
48 | 48 | '#default_value' => $settings['field'], |
49 | 49 | '#options' => $options, |
50 | - '#required' => TRUE, |
|
50 | + '#required' => true, |
|
51 | 51 | '#disabled' => empty($options), |
52 | 52 | '#description' => empty($options) ? t('There are no userreference fields defined.') : '', |
53 | 53 | ); |
@@ -6,43 +6,43 @@ discard block |
||
6 | 6 | * Theme preprocess function for content-admin-field-overview-form.tpl.php. |
7 | 7 | */ |
8 | 8 | function template_preprocess_content_field_overview_form(&$vars) { |
9 | - $form = &$vars['form']; |
|
9 | + $form = &$vars['form']; |
|
10 | 10 | |
11 | - $vars['help'] = theme('advanced_help_topic', 'content', 'manage-fields') . t('Add fields and groups to the content type, and arrange them on content display and input forms.'); |
|
12 | - if (module_exists('fieldgroup')) { |
|
11 | + $vars['help'] = theme('advanced_help_topic', 'content', 'manage-fields') . t('Add fields and groups to the content type, and arrange them on content display and input forms.'); |
|
12 | + if (module_exists('fieldgroup')) { |
|
13 | 13 | $vars['help'] .= '<br/>'. t('You can add a field to a group by dragging it below and to the right of the group.'); |
14 | - } |
|
15 | - if (!module_exists('advanced_help')) { |
|
14 | + } |
|
15 | + if (!module_exists('advanced_help')) { |
|
16 | 16 | $vars['help'] .= '<br/>' . t('Note: Installing the <a href="!adv_help">Advanced help</a> module will let you access more and better help.', array('!adv_help' => 'http://drupal.org/project/advanced_help')); |
17 | - } |
|
17 | + } |
|
18 | 18 | |
19 | - $order = _content_overview_order($form, $form['#field_rows'], $form['#group_rows']); |
|
20 | - $rows = array(); |
|
19 | + $order = _content_overview_order($form, $form['#field_rows'], $form['#group_rows']); |
|
20 | + $rows = array(); |
|
21 | 21 | |
22 | - // Identify the 'new item' keys in the form, they look like |
|
23 | - // _add_new_field, add_new_group. |
|
24 | - $keys = array_keys($form); |
|
25 | - $add_rows = array(); |
|
26 | - foreach ($keys as $key) { |
|
22 | + // Identify the 'new item' keys in the form, they look like |
|
23 | + // _add_new_field, add_new_group. |
|
24 | + $keys = array_keys($form); |
|
25 | + $add_rows = array(); |
|
26 | + foreach ($keys as $key) { |
|
27 | 27 | if (substr($key, 0, 4) == '_add') { |
28 | - $add_rows[] = $key; |
|
28 | + $add_rows[] = $key; |
|
29 | + } |
|
29 | 30 | } |
30 | - } |
|
31 | - while ($order) { |
|
31 | + while ($order) { |
|
32 | 32 | $key = reset($order); |
33 | 33 | $element = &$form[$key]; |
34 | 34 | |
35 | 35 | // Only display the 'Add' separator if the 'add' rows are still |
36 | 36 | // at the end of the table. |
37 | 37 | if (!isset($added_separator)) { |
38 | - $remaining_rows = array_diff($order, $add_rows); |
|
39 | - if (empty($remaining_rows) && empty($element['#depth'])) { |
|
38 | + $remaining_rows = array_diff($order, $add_rows); |
|
39 | + if (empty($remaining_rows) && empty($element['#depth'])) { |
|
40 | 40 | $row = new stdClass(); |
41 | 41 | $row->row_type = 'separator'; |
42 | 42 | $row->class = 'tabledrag-leaf region'; |
43 | 43 | $rows[] = $row; |
44 | 44 | $added_separator = TRUE; |
45 | - } |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | $row = new stdClass(); |
@@ -53,18 +53,18 @@ discard block |
||
53 | 53 | $element['hidden_name']['#attributes']['class'] = 'field-name'; |
54 | 54 | // Add target classes for the update selects behavior. |
55 | 55 | switch ($element['#row_type']) { |
56 | - case 'add_new_field': |
|
56 | + case 'add_new_field': |
|
57 | 57 | $element['type']['#attributes']['class'] = 'content-field-type-select'; |
58 | 58 | $element['widget_type']['#attributes']['class'] = 'content-widget-type-select'; |
59 | 59 | break; |
60 | - case 'add_existing_field': |
|
60 | + case 'add_existing_field': |
|
61 | 61 | $element['field_name']['#attributes']['class'] = 'content-field-select'; |
62 | 62 | $element['widget_type']['#attributes']['class'] = 'content-widget-type-select'; |
63 | 63 | $element['label']['#attributes']['class'] = 'content-label-textfield'; |
64 | 64 | break; |
65 | 65 | } |
66 | 66 | foreach (element_children($element) as $child) { |
67 | - $row->{$child} = drupal_render($element[$child]); |
|
67 | + $row->{$child} = drupal_render($element[$child]); |
|
68 | 68 | } |
69 | 69 | $row->label_class = 'label-'. strtr($element['#row_type'], '_', '-'); |
70 | 70 | $row->row_type = $element['#row_type']; |
@@ -77,69 +77,69 @@ discard block |
||
77 | 77 | |
78 | 78 | $rows[] = $row; |
79 | 79 | array_shift($order); |
80 | - } |
|
81 | - $vars['rows'] = $rows; |
|
82 | - $vars['submit'] = drupal_render($form); |
|
80 | + } |
|
81 | + $vars['rows'] = $rows; |
|
82 | + $vars['submit'] = drupal_render($form); |
|
83 | 83 | |
84 | - // Add tabledrag behavior. |
|
84 | + // Add tabledrag behavior. |
|
85 | 85 | // drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', FALSE, 1); |
86 | - drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', TRUE, 1); |
|
86 | + drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', TRUE, 1); |
|
87 | 87 | // drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight', NULL, NULL, FALSE); |
88 | - drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight'); |
|
88 | + drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight'); |
|
89 | 89 | |
90 | - // Add settings for the update selects behavior. |
|
91 | - $js_fields = array(); |
|
92 | - foreach (array_keys(content_existing_field_options($form['#type_name'])) as $field_name) { |
|
90 | + // Add settings for the update selects behavior. |
|
91 | + $js_fields = array(); |
|
92 | + foreach (array_keys(content_existing_field_options($form['#type_name'])) as $field_name) { |
|
93 | 93 | $field = content_fields($field_name); |
94 | 94 | $js_fields[$field_name] = array('label' => $field['widget']['label'], 'type' => $field['type'], 'widget' => $field['widget']['type']); |
95 | - } |
|
96 | - drupal_add_js(array('contentWidgetTypes' => content_widget_type_options(), 'contentFields' => $js_fields), 'setting'); |
|
97 | - drupal_add_js(drupal_get_path('module', 'content') .'/content.js'); |
|
95 | + } |
|
96 | + drupal_add_js(array('contentWidgetTypes' => content_widget_type_options(), 'contentFields' => $js_fields), 'setting'); |
|
97 | + drupal_add_js(drupal_get_path('module', 'content') .'/content.js'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Theme preprocess function for content-admin-display-overview-form.tpl.php. |
102 | 102 | */ |
103 | 103 | function template_preprocess_content_display_overview_form(&$vars) { |
104 | - $form = &$vars['form']; |
|
104 | + $form = &$vars['form']; |
|
105 | 105 | |
106 | - $contexts_selector = $form['#contexts']; |
|
107 | - $vars['basic'] = $contexts_selector == 'basic'; |
|
108 | - $vars['contexts'] = content_build_modes($contexts_selector); |
|
106 | + $contexts_selector = $form['#contexts']; |
|
107 | + $vars['basic'] = $contexts_selector == 'basic'; |
|
108 | + $vars['contexts'] = content_build_modes($contexts_selector); |
|
109 | 109 | |
110 | - if ($contexts_selector == 'basic') { |
|
110 | + if ($contexts_selector == 'basic') { |
|
111 | 111 | $help = t("Configure how this content type's fields and field labels should be displayed when it's viewed in teaser and full-page mode."); |
112 | - } |
|
113 | - else { |
|
112 | + } |
|
113 | + else { |
|
114 | 114 | $help = t("Configure how this content type's fields should be displayed when it's rendered in the following contexts."); |
115 | - } |
|
116 | - $help .= ' '. t("Use the 'Exclude' checkbox to exclude an item from the !content value passed to the node template.", array('!content' => '$content')); |
|
117 | - $vars['help'] = $help; |
|
115 | + } |
|
116 | + $help .= ' '. t("Use the 'Exclude' checkbox to exclude an item from the !content value passed to the node template.", array('!content' => '$content')); |
|
117 | + $vars['help'] = $help; |
|
118 | 118 | |
119 | - $order = _content_overview_order($form, $form['#fields'], $form['#groups']); |
|
120 | - if (empty($order)) { |
|
119 | + $order = _content_overview_order($form, $form['#fields'], $form['#groups']); |
|
120 | + if (empty($order)) { |
|
121 | 121 | $vars['rows'] = array(); |
122 | 122 | $vars['submit'] = ''; |
123 | 123 | return; |
124 | - } |
|
124 | + } |
|
125 | 125 | |
126 | - $rows = array(); |
|
127 | - foreach ($order as $key) { |
|
126 | + $rows = array(); |
|
127 | + foreach ($order as $key) { |
|
128 | 128 | $element = &$form[$key]; |
129 | 129 | $row = new stdClass(); |
130 | 130 | foreach (element_children($element) as $child) { |
131 | - if (!array_key_exists('exclude', $element[$child])) { |
|
131 | + if (!array_key_exists('exclude', $element[$child])) { |
|
132 | 132 | $row->{$child} = drupal_render($element[$child]); |
133 | - } |
|
134 | - else { |
|
133 | + } |
|
134 | + else { |
|
135 | 135 | $row->{$child}->format = drupal_render($element[$child]['format']); |
136 | 136 | $row->{$child}->exclude = drupal_render($element[$child]['exclude']); |
137 | - } |
|
137 | + } |
|
138 | 138 | } |
139 | 139 | $row->label_class = in_array($key, $form['#groups']) ? 'label-group' : 'label-field'; |
140 | 140 | $row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0); |
141 | 141 | $rows[] = $row; |
142 | - } |
|
143 | - $vars['rows'] = $rows; |
|
144 | - $vars['submit'] = drupal_render($form); |
|
142 | + } |
|
143 | + $vars['rows'] = $rows; |
|
144 | + $vars['submit'] = drupal_render($form); |
|
145 | 145 | } |
146 | 146 | \ No newline at end of file |
@@ -53,15 +53,15 @@ |
||
53 | 53 | $element['hidden_name']['#attributes']['class'] = 'field-name'; |
54 | 54 | // Add target classes for the update selects behavior. |
55 | 55 | switch ($element['#row_type']) { |
56 | - case 'add_new_field': |
|
57 | - $element['type']['#attributes']['class'] = 'content-field-type-select'; |
|
58 | - $element['widget_type']['#attributes']['class'] = 'content-widget-type-select'; |
|
59 | - break; |
|
60 | - case 'add_existing_field': |
|
61 | - $element['field_name']['#attributes']['class'] = 'content-field-select'; |
|
62 | - $element['widget_type']['#attributes']['class'] = 'content-widget-type-select'; |
|
63 | - $element['label']['#attributes']['class'] = 'content-label-textfield'; |
|
64 | - break; |
|
56 | + case 'add_new_field': |
|
57 | + $element['type']['#attributes']['class'] = 'content-field-type-select'; |
|
58 | + $element['widget_type']['#attributes']['class'] = 'content-widget-type-select'; |
|
59 | + break; |
|
60 | + case 'add_existing_field': |
|
61 | + $element['field_name']['#attributes']['class'] = 'content-field-select'; |
|
62 | + $element['widget_type']['#attributes']['class'] = 'content-widget-type-select'; |
|
63 | + $element['label']['#attributes']['class'] = 'content-label-textfield'; |
|
64 | + break; |
|
65 | 65 | } |
66 | 66 | foreach (element_children($element) as $child) { |
67 | 67 | $row->{$child} = drupal_render($element[$child]); |
@@ -8,12 +8,12 @@ discard block |
||
8 | 8 | function template_preprocess_content_field_overview_form(&$vars) { |
9 | 9 | $form = &$vars['form']; |
10 | 10 | |
11 | - $vars['help'] = theme('advanced_help_topic', 'content', 'manage-fields') . t('Add fields and groups to the content type, and arrange them on content display and input forms.'); |
|
11 | + $vars['help'] = theme('advanced_help_topic', 'content', 'manage-fields').t('Add fields and groups to the content type, and arrange them on content display and input forms.'); |
|
12 | 12 | if (module_exists('fieldgroup')) { |
13 | - $vars['help'] .= '<br/>'. t('You can add a field to a group by dragging it below and to the right of the group.'); |
|
13 | + $vars['help'] .= '<br/>'.t('You can add a field to a group by dragging it below and to the right of the group.'); |
|
14 | 14 | } |
15 | 15 | if (!module_exists('advanced_help')) { |
16 | - $vars['help'] .= '<br/>' . t('Note: Installing the <a href="!adv_help">Advanced help</a> module will let you access more and better help.', array('!adv_help' => 'http://drupal.org/project/advanced_help')); |
|
16 | + $vars['help'] .= '<br/>'.t('Note: Installing the <a href="!adv_help">Advanced help</a> module will let you access more and better help.', array('!adv_help' => 'http://drupal.org/project/advanced_help')); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | $order = _content_overview_order($form, $form['#field_rows'], $form['#group_rows']); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | foreach (element_children($element) as $child) { |
67 | 67 | $row->{$child} = drupal_render($element[$child]); |
68 | 68 | } |
69 | - $row->label_class = 'label-'. strtr($element['#row_type'], '_', '-'); |
|
69 | + $row->label_class = 'label-'.strtr($element['#row_type'], '_', '-'); |
|
70 | 70 | $row->row_type = $element['#row_type']; |
71 | 71 | $row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0); |
72 | 72 | $row->class = 'draggable'; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $js_fields[$field_name] = array('label' => $field['widget']['label'], 'type' => $field['type'], 'widget' => $field['widget']['type']); |
95 | 95 | } |
96 | 96 | drupal_add_js(array('contentWidgetTypes' => content_widget_type_options(), 'contentFields' => $js_fields), 'setting'); |
97 | - drupal_add_js(drupal_get_path('module', 'content') .'/content.js'); |
|
97 | + drupal_add_js(drupal_get_path('module', 'content').'/content.js'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | else { |
114 | 114 | $help = t("Configure how this content type's fields should be displayed when it's rendered in the following contexts."); |
115 | 115 | } |
116 | - $help .= ' '. t("Use the 'Exclude' checkbox to exclude an item from the !content value passed to the node template.", array('!content' => '$content')); |
|
116 | + $help .= ' '.t("Use the 'Exclude' checkbox to exclude an item from the !content value passed to the node template.", array('!content' => '$content')); |
|
117 | 117 | $vars['help'] = $help; |
118 | 118 | |
119 | 119 | $order = _content_overview_order($form, $form['#fields'], $form['#groups']); |
@@ -109,8 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | if ($contexts_selector == 'basic') { |
111 | 111 | $help = t("Configure how this content type's fields and field labels should be displayed when it's viewed in teaser and full-page mode."); |
112 | - } |
|
113 | - else { |
|
112 | + } else { |
|
114 | 113 | $help = t("Configure how this content type's fields should be displayed when it's rendered in the following contexts."); |
115 | 114 | } |
116 | 115 | $help .= ' '. t("Use the 'Exclude' checkbox to exclude an item from the !content value passed to the node template.", array('!content' => '$content')); |
@@ -130,8 +129,7 @@ discard block |
||
130 | 129 | foreach (element_children($element) as $child) { |
131 | 130 | if (!array_key_exists('exclude', $element[$child])) { |
132 | 131 | $row->{$child} = drupal_render($element[$child]); |
133 | - } |
|
134 | - else { |
|
132 | + } else { |
|
135 | 133 | $row->{$child}->format = drupal_render($element[$child]['format']); |
136 | 134 | $row->{$child}->exclude = drupal_render($element[$child]['exclude']); |
137 | 135 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $row->row_type = 'separator'; |
42 | 42 | $row->class = 'tabledrag-leaf region'; |
43 | 43 | $rows[] = $row; |
44 | - $added_separator = TRUE; |
|
44 | + $added_separator = true; |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | // Add tabledrag behavior. |
85 | 85 | // drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', FALSE, 1); |
86 | - drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', TRUE, 1); |
|
86 | + drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', true, 1); |
|
87 | 87 | // drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight', NULL, NULL, FALSE); |
88 | 88 | drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight'); |
89 | 89 |