@@ -7,36 +7,36 @@ |
||
7 | 7 | * for field-specific subclasses to use if they need to. |
8 | 8 | */ |
9 | 9 | class content_handler_filter_many_to_one extends views_handler_filter_many_to_one { |
10 | - var $content_field; |
|
10 | + var $content_field; |
|
11 | 11 | |
12 | - function construct() { |
|
12 | + function construct() { |
|
13 | 13 | parent::construct(); |
14 | 14 | $this->content_field = content_fields($this->definition['content_field_name']); |
15 | 15 | $this->additional_fields = $this->definition['additional fields']; |
16 | 16 | $field = $this->content_field; |
17 | 17 | $this->value_title = $field['widget']['label']; |
18 | - } |
|
18 | + } |
|
19 | 19 | |
20 | - function get_value_options() { |
|
20 | + function get_value_options() { |
|
21 | 21 | $this->value_options = $this->allowed_values(); |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - // Get allowed values from hook_allowed_values(), if any, |
|
25 | - // or from content_allowed_values(); |
|
26 | - function allowed_values() { |
|
24 | + // Get allowed values from hook_allowed_values(), if any, |
|
25 | + // or from content_allowed_values(); |
|
26 | + function allowed_values() { |
|
27 | 27 | $field = $this->content_field; |
28 | 28 | $function = $field['module'] .'_allowed_values'; |
29 | 29 | if ($this->value_form_type == 'select') { |
30 | - // Select elements accept multidimensional arrays to support optgroups. |
|
31 | - $options = function_exists($function) ? $function($field) : content_allowed_values($field, FALSE); |
|
32 | - // For selects, HTML should be filtered out and entities left unencoded. |
|
33 | - // See content_allowed_values / content_filter_xss / filter_xss. |
|
34 | - content_allowed_values_filter_html($options); |
|
30 | + // Select elements accept multidimensional arrays to support optgroups. |
|
31 | + $options = function_exists($function) ? $function($field) : content_allowed_values($field, FALSE); |
|
32 | + // For selects, HTML should be filtered out and entities left unencoded. |
|
33 | + // See content_allowed_values / content_filter_xss / filter_xss. |
|
34 | + content_allowed_values_filter_html($options); |
|
35 | 35 | } |
36 | 36 | else { |
37 | - $options = function_exists($function) ? $function($field) : content_allowed_values($field); |
|
37 | + $options = function_exists($function) ? $function($field) : content_allowed_values($field); |
|
38 | 38 | } |
39 | 39 | return (array) $options; |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | // or from content_allowed_values(); |
26 | 26 | function allowed_values() { |
27 | 27 | $field = $this->content_field; |
28 | - $function = $field['module'] .'_allowed_values'; |
|
28 | + $function = $field['module'].'_allowed_values'; |
|
29 | 29 | if ($this->value_form_type == 'select') { |
30 | 30 | // Select elements accept multidimensional arrays to support optgroups. |
31 | 31 | $options = function_exists($function) ? $function($field) : content_allowed_values($field, FALSE); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | else { |
37 | 37 | $options = function_exists($function) ? $function($field) : content_allowed_values($field); |
38 | 38 | } |
39 | - return (array) $options; |
|
39 | + return (array)$options; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -32,8 +32,7 @@ |
||
32 | 32 | // For selects, HTML should be filtered out and entities left unencoded. |
33 | 33 | // See content_allowed_values / content_filter_xss / filter_xss. |
34 | 34 | content_allowed_values_filter_html($options); |
35 | - } |
|
36 | - else { |
|
35 | + } else { |
|
37 | 36 | $options = function_exists($function) ? $function($field) : content_allowed_values($field); |
38 | 37 | } |
39 | 38 | return (array) $options; |
@@ -28,7 +28,7 @@ |
||
28 | 28 | $function = $field['module'] .'_allowed_values'; |
29 | 29 | if ($this->value_form_type == 'select') { |
30 | 30 | // Select elements accept multidimensional arrays to support optgroups. |
31 | - $options = function_exists($function) ? $function($field) : content_allowed_values($field, FALSE); |
|
31 | + $options = function_exists($function) ? $function($field) : content_allowed_values($field, false); |
|
32 | 32 | // For selects, HTML should be filtered out and entities left unencoded. |
33 | 33 | // See content_allowed_values / content_filter_xss / filter_xss. |
34 | 34 | content_allowed_values_filter_html($options); |
@@ -7,12 +7,12 @@ |
||
7 | 7 | * for field-specific subclasses to use if they need to. |
8 | 8 | */ |
9 | 9 | class content_handler_argument extends views_handler_argument { |
10 | - var $content_field; |
|
10 | + var $content_field; |
|
11 | 11 | |
12 | - function construct() { |
|
12 | + function construct() { |
|
13 | 13 | parent::construct(); |
14 | 14 | |
15 | 15 | $this->content_field = content_fields($this->definition['content_field_name']); |
16 | 16 | $this->additional_fields = $this->definition['additional fields']; |
17 | - } |
|
17 | + } |
|
18 | 18 | } |
19 | 19 | \ No newline at end of file |
@@ -6,43 +6,43 @@ |
||
6 | 6 | * Handler for 'content_handler_argument_many_to_one' style. |
7 | 7 | */ |
8 | 8 | class content_handler_argument_many_to_one extends views_handler_argument_many_to_one { |
9 | - var $content_field; |
|
9 | + var $content_field; |
|
10 | 10 | |
11 | - function construct() { |
|
11 | + function construct() { |
|
12 | 12 | parent::construct(); |
13 | 13 | |
14 | 14 | $this->content_field = content_fields($this->definition['content_field_name']); |
15 | 15 | $this->additional_fields = $this->definition['additional fields']; |
16 | - } |
|
16 | + } |
|
17 | 17 | |
18 | - function summary_name($data) { |
|
18 | + function summary_name($data) { |
|
19 | 19 | $options = $this->allowed_values(); |
20 | 20 | $value = $data->{$this->name_alias}; |
21 | 21 | if (isset($options[$value])) { |
22 | - $value = $options[$value]; |
|
22 | + $value = $options[$value]; |
|
23 | 23 | } |
24 | 24 | else { |
25 | - $value = parent::summary_name($data); |
|
25 | + $value = parent::summary_name($data); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | return $value; |
29 | - } |
|
29 | + } |
|
30 | 30 | |
31 | - function title_query() { |
|
31 | + function title_query() { |
|
32 | 32 | $options = $this->allowed_values(); |
33 | 33 | $values = $this->value; |
34 | 34 | foreach ($values as $key => $value) { |
35 | - if (isset($options[$value])) { |
|
35 | + if (isset($options[$value])) { |
|
36 | 36 | $values[$key] = $options[$value]; |
37 | - } |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | return $values; |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - function allowed_values() { |
|
42 | + function allowed_values() { |
|
43 | 43 | $field = $this->content_field; |
44 | 44 | $function = $field['module'] .'_allowed_values'; |
45 | 45 | $options = function_exists($function) ? $function($field) : content_allowed_values($field); |
46 | 46 | return (array) $options; |
47 | - } |
|
47 | + } |
|
48 | 48 | } |
49 | 49 | \ No newline at end of file |
@@ -41,8 +41,8 @@ |
||
41 | 41 | |
42 | 42 | function allowed_values() { |
43 | 43 | $field = $this->content_field; |
44 | - $function = $field['module'] .'_allowed_values'; |
|
44 | + $function = $field['module'].'_allowed_values'; |
|
45 | 45 | $options = function_exists($function) ? $function($field) : content_allowed_values($field); |
46 | - return (array) $options; |
|
46 | + return (array)$options; |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | \ No newline at end of file |
@@ -20,8 +20,7 @@ |
||
20 | 20 | $value = $data->{$this->name_alias}; |
21 | 21 | if (isset($options[$value])) { |
22 | 22 | $value = $options[$value]; |
23 | - } |
|
24 | - else { |
|
23 | + } else { |
|
25 | 24 | $value = parent::summary_name($data); |
26 | 25 | } |
27 | 26 |
@@ -7,11 +7,11 @@ |
||
7 | 7 | * for field-specific subclasses to use if they need to. |
8 | 8 | */ |
9 | 9 | class content_handler_filter_numeric extends views_handler_filter_numeric { |
10 | - var $content_field; |
|
10 | + var $content_field; |
|
11 | 11 | |
12 | - function construct() { |
|
12 | + function construct() { |
|
13 | 13 | parent::construct(); |
14 | 14 | $this->content_field = content_fields($this->definition['content_field_name']); |
15 | 15 | $this->additional_fields = $this->definition['additional fields']; |
16 | - } |
|
16 | + } |
|
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -10,17 +10,17 @@ |
||
10 | 10 | // Ensure compatibility with Views pre 2.4, where the |
11 | 11 | // views_handler_filter_float class lived in views_handler_filter_numeric.inc. |
12 | 12 | if (!class_exists('views_handler_filter_float')) { |
13 | - // Manually include the parent class. |
|
14 | - $definition = views_fetch_handler_data('views_handler_filter_numeric'); |
|
15 | - views_include_handler($definition, 'handler'); |
|
13 | + // Manually include the parent class. |
|
14 | + $definition = views_fetch_handler_data('views_handler_filter_numeric'); |
|
15 | + views_include_handler($definition, 'handler'); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | class content_handler_filter_float extends views_handler_filter_float { |
19 | - var $content_field; |
|
19 | + var $content_field; |
|
20 | 20 | |
21 | - function construct() { |
|
21 | + function construct() { |
|
22 | 22 | parent::construct(); |
23 | 23 | $this->content_field = content_fields($this->definition['content_field_name']); |
24 | 24 | $this->additional_fields = $this->definition['additional fields']; |
25 | - } |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | \ No newline at end of file |
@@ -9,129 +9,129 @@ discard block |
||
9 | 9 | * field and formatter handling can extend this class. |
10 | 10 | */ |
11 | 11 | class content_handler_field_multiple extends content_handler_field { |
12 | - var $defer_query; |
|
12 | + var $defer_query; |
|
13 | 13 | |
14 | - function init(&$view, $options) { |
|
14 | + function init(&$view, $options) { |
|
15 | 15 | $field = $this->content_field; |
16 | 16 | parent::init($view, $options); |
17 | 17 | |
18 | 18 | $this->defer_query = !empty($options['multiple']['group']) && $field['multiple']; |
19 | 19 | |
20 | 20 | if ($this->defer_query) { |
21 | - // Grouped field: ditch the existing additional_fields (field columns + delta). |
|
22 | - // In the main query we'll only need: |
|
23 | - // - vid, which will be used to retrieve the actual values in pre_render, |
|
24 | - // - node type and nid, which wil be used in the pseudo-node used when |
|
25 | - // rendering. |
|
26 | - $this->additional_fields = array( |
|
21 | + // Grouped field: ditch the existing additional_fields (field columns + delta). |
|
22 | + // In the main query we'll only need: |
|
23 | + // - vid, which will be used to retrieve the actual values in pre_render, |
|
24 | + // - node type and nid, which wil be used in the pseudo-node used when |
|
25 | + // rendering. |
|
26 | + $this->additional_fields = array( |
|
27 | 27 | 'type' => array('table' => 'node', 'field' => 'type'), |
28 | 28 | 'nid' => array('table' => 'node', 'field' => 'nid'), |
29 | - ); |
|
30 | - if ($view->base_table == 'node_revisions') { |
|
29 | + ); |
|
30 | + if ($view->base_table == 'node_revisions') { |
|
31 | 31 | $this->additional_fields['vid'] = array('table' => 'node_revisions', 'field' => 'vid'); |
32 | - } |
|
33 | - else { |
|
32 | + } |
|
33 | + else { |
|
34 | 34 | $this->additional_fields['vid'] = array('table' => 'node', 'field' => 'vid'); |
35 | - } |
|
35 | + } |
|
36 | + } |
|
36 | 37 | } |
37 | - } |
|
38 | 38 | |
39 | - function option_definition() { |
|
39 | + function option_definition() { |
|
40 | 40 | $options = parent::option_definition(); |
41 | 41 | |
42 | 42 | $options['multiple'] = array( |
43 | - 'contains' => array( |
|
43 | + 'contains' => array( |
|
44 | 44 | 'group' => array('default' => TRUE), |
45 | 45 | 'multiple_number' => array('default' => ''), |
46 | 46 | 'multiple_from' => array('default' => ''), |
47 | 47 | 'multiple_reversed' => array('default' => FALSE), |
48 | - ), |
|
48 | + ), |
|
49 | 49 | ); |
50 | 50 | |
51 | 51 | return $options; |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Provide 'group multiple values' option. |
|
56 | - */ |
|
57 | - function options_form(&$form, &$form_state) { |
|
54 | + /** |
|
55 | + * Provide 'group multiple values' option. |
|
56 | + */ |
|
57 | + function options_form(&$form, &$form_state) { |
|
58 | 58 | parent::options_form($form, $form_state); |
59 | 59 | |
60 | 60 | $field = $this->content_field; |
61 | 61 | $options = $this->options; |
62 | 62 | |
63 | 63 | $form['multiple'] = array( |
64 | - '#access' => $field['multiple'], |
|
65 | - '#weight' => 1, |
|
64 | + '#access' => $field['multiple'], |
|
65 | + '#weight' => 1, |
|
66 | 66 | ); |
67 | 67 | $form['multiple']['group'] = array( |
68 | - '#title' => t('Group multiple values'), |
|
69 | - '#type' => 'checkbox', |
|
70 | - '#default_value' => $options['multiple']['group'], |
|
71 | - '#description' => t('If unchecked, each item in the field will create a new row, which may appear to cause duplicates. This setting is not compatible with click-sorting in table displays.'), |
|
68 | + '#title' => t('Group multiple values'), |
|
69 | + '#type' => 'checkbox', |
|
70 | + '#default_value' => $options['multiple']['group'], |
|
71 | + '#description' => t('If unchecked, each item in the field will create a new row, which may appear to cause duplicates. This setting is not compatible with click-sorting in table displays.'), |
|
72 | 72 | ); |
73 | 73 | // Make the string translatable by keeping it as a whole rather than |
74 | 74 | // translating prefix and suffix separately. |
75 | 75 | list($prefix, $suffix) = explode('@count', t('Show @count value(s)')); |
76 | 76 | $form['multiple']['multiple_number'] = array( |
77 | - '#type' => 'textfield', |
|
78 | - '#size' => 5, |
|
79 | - '#field_prefix' => $prefix, |
|
80 | - '#field_suffix' => $suffix, |
|
81 | - '#default_value' => $options['multiple']['multiple_number'], |
|
82 | - '#prefix' => '<div class="container-inline">', |
|
83 | - '#process' => array('views_process_dependency'), |
|
84 | - '#dependency' => array('edit-options-multiple-group' => array(TRUE)), |
|
77 | + '#type' => 'textfield', |
|
78 | + '#size' => 5, |
|
79 | + '#field_prefix' => $prefix, |
|
80 | + '#field_suffix' => $suffix, |
|
81 | + '#default_value' => $options['multiple']['multiple_number'], |
|
82 | + '#prefix' => '<div class="container-inline">', |
|
83 | + '#process' => array('views_process_dependency'), |
|
84 | + '#dependency' => array('edit-options-multiple-group' => array(TRUE)), |
|
85 | 85 | ); |
86 | 86 | list($prefix, $suffix) = explode('@count', t('starting from @count')); |
87 | 87 | $form['multiple']['multiple_from'] = array( |
88 | - '#type' => 'textfield', |
|
89 | - '#size' => 5, |
|
90 | - '#field_prefix' => $prefix, |
|
91 | - '#field_suffix' => $suffix, |
|
92 | - '#default_value' => $options['multiple']['multiple_from'], |
|
93 | - '#process' => array('views_process_dependency'), |
|
94 | - '#dependency' => array('edit-options-multiple-group' => array(TRUE)), |
|
95 | - '#description' => t('(first item is 0)'), |
|
88 | + '#type' => 'textfield', |
|
89 | + '#size' => 5, |
|
90 | + '#field_prefix' => $prefix, |
|
91 | + '#field_suffix' => $suffix, |
|
92 | + '#default_value' => $options['multiple']['multiple_from'], |
|
93 | + '#process' => array('views_process_dependency'), |
|
94 | + '#dependency' => array('edit-options-multiple-group' => array(TRUE)), |
|
95 | + '#description' => t('(first item is 0)'), |
|
96 | 96 | ); |
97 | 97 | $form['multiple']['multiple_reversed'] = array( |
98 | - '#title' => t('Reversed'), |
|
99 | - '#type' => 'checkbox', |
|
100 | - '#default_value' => $options['multiple']['multiple_reversed'], |
|
101 | - '#suffix' => '</div>', |
|
102 | - '#process' => array('views_process_dependency'), |
|
103 | - '#dependency' => array('edit-options-multiple-group' => array(TRUE)), |
|
104 | - '#description' => t('(start from last values)'), |
|
98 | + '#title' => t('Reversed'), |
|
99 | + '#type' => 'checkbox', |
|
100 | + '#default_value' => $options['multiple']['multiple_reversed'], |
|
101 | + '#suffix' => '</div>', |
|
102 | + '#process' => array('views_process_dependency'), |
|
103 | + '#dependency' => array('edit-options-multiple-group' => array(TRUE)), |
|
104 | + '#description' => t('(start from last values)'), |
|
105 | 105 | ); |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Determine if this field is click sortable. |
|
110 | - */ |
|
111 | - function click_sortable() { |
|
108 | + /** |
|
109 | + * Determine if this field is click sortable. |
|
110 | + */ |
|
111 | + function click_sortable() { |
|
112 | 112 | $field = $this->content_field; |
113 | 113 | $options = $this->options; |
114 | 114 | |
115 | 115 | // Grouped fields are not click-sortable. |
116 | 116 | return !empty($this->definition['click sortable']) && !$this->defer_query; |
117 | - } |
|
117 | + } |
|
118 | 118 | |
119 | - function query() { |
|
119 | + function query() { |
|
120 | 120 | // If this is not a grouped field, use the generic query(). |
121 | 121 | if (!$this->defer_query) { |
122 | - return parent::query(); |
|
122 | + return parent::query(); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // Grouped field: do NOT call ensure_my_table, only add additional fields. |
126 | 126 | $this->add_additional_fields(); |
127 | 127 | $this->field_alias = $this->aliases['vid']; |
128 | - } |
|
128 | + } |
|
129 | 129 | |
130 | - function pre_render(&$values) { |
|
130 | + function pre_render(&$values) { |
|
131 | 131 | // If there are no values to render (displaying a summary, or query returned no results), |
132 | 132 | // or if this is not a grouped field, do nothing specific. |
133 | 133 | if (isset($this->view->build_info['summary']) || empty($values) || !$this->defer_query) { |
134 | - return parent::pre_render($values); |
|
134 | + return parent::pre_render($values); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | $field = $this->content_field; |
@@ -143,82 +143,82 @@ discard block |
||
143 | 143 | $vids = array(); |
144 | 144 | $this->field_values = array(); |
145 | 145 | foreach ($values as $result) { |
146 | - if (isset($result->{$this->field_alias})) { |
|
146 | + if (isset($result->{$this->field_alias})) { |
|
147 | 147 | $vids[] = $result->{$this->field_alias}; |
148 | - } |
|
148 | + } |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | // It may happend that the multiple values field is related to a non |
152 | 152 | // required relation for which no node data related to the field being |
153 | 153 | // processed here is available. |
154 | 154 | if (empty($vids)) { |
155 | - return parent::pre_render($values); |
|
155 | + return parent::pre_render($values); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // List columns to retrieve. |
159 | 159 | $alias = content_views_tablename($field); |
160 | 160 | // Prefix aliases with '_' to avoid clashing with field columns names. |
161 | 161 | $query_columns = array( |
162 | - 'vid AS _vid', |
|
163 | - "delta as _delta", |
|
164 | - // nid is needed to generate the links for 'link to node' option. |
|
165 | - 'nid AS _nid', |
|
162 | + 'vid AS _vid', |
|
163 | + "delta as _delta", |
|
164 | + // nid is needed to generate the links for 'link to node' option. |
|
165 | + 'nid AS _nid', |
|
166 | 166 | ); |
167 | 167 | // The actual field columns. |
168 | 168 | foreach ($db_info['columns'] as $column => $attributes) { |
169 | - $query_columns[] = "$attributes[column] AS $column"; |
|
169 | + $query_columns[] = "$attributes[column] AS $column"; |
|
170 | 170 | } |
171 | 171 | $query = 'SELECT '. implode(', ', $query_columns) . |
172 | - ' FROM {'. $db_info['table'] ."}". |
|
173 | - " WHERE vid IN (". implode(',', $vids) .')'. |
|
174 | - " ORDER BY _nid ASC, _delta ". ($options['multiple']['multiple_reversed'] ? 'DESC' : 'ASC'); |
|
172 | + ' FROM {'. $db_info['table'] ."}". |
|
173 | + " WHERE vid IN (". implode(',', $vids) .')'. |
|
174 | + " ORDER BY _nid ASC, _delta ". ($options['multiple']['multiple_reversed'] ? 'DESC' : 'ASC'); |
|
175 | 175 | $result = db_query($query); |
176 | 176 | |
177 | 177 | while ($item = db_fetch_array($result)) { |
178 | - // Clean up the $item from vid and delta. We keep nid for now. |
|
179 | - $vid = $item['_vid']; |
|
180 | - unset($item['_vid']); |
|
181 | - $delta = !empty($item['_delta']) ? $item['_delta'] : 0; |
|
182 | - $item['#delta'] = $item['_delta']; |
|
183 | - unset($item['_delta']); |
|
184 | - $this->field_values[$vid][$delta] = $item; |
|
178 | + // Clean up the $item from vid and delta. We keep nid for now. |
|
179 | + $vid = $item['_vid']; |
|
180 | + unset($item['_vid']); |
|
181 | + $delta = !empty($item['_delta']) ? $item['_delta'] : 0; |
|
182 | + $item['#delta'] = $item['_delta']; |
|
183 | + unset($item['_delta']); |
|
184 | + $this->field_values[$vid][$delta] = $item; |
|
185 | 185 | } |
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Return DIV or SPAN based upon the field's element type. |
|
190 | - * |
|
191 | - * Fields rendered with the 'group multiple' option use <div> markers, |
|
192 | - * and thus shouldn't be wrapped in a <span>. |
|
193 | - */ |
|
194 | - function element_type($none_supported = FALSE, $default_empty = FALSE) { |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Return DIV or SPAN based upon the field's element type. |
|
190 | + * |
|
191 | + * Fields rendered with the 'group multiple' option use <div> markers, |
|
192 | + * and thus shouldn't be wrapped in a <span>. |
|
193 | + */ |
|
194 | + function element_type($none_supported = FALSE, $default_empty = FALSE) { |
|
195 | 195 | // If this is not a grouped field, use the parent method. |
196 | 196 | if (!$this->defer_query) { |
197 | - return parent::element_type($none_supported, $default_empty); |
|
197 | + return parent::element_type($none_supported, $default_empty); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | // The 'element_type' property denotes Views 3.x ('semantic views' |
201 | 201 | // functionnality). If the property is set, and not set to '' ("default"), |
202 | 202 | // let the generic method handle the output. |
203 | 203 | if (isset($this->options['element_type']) && $this->options['element_type'] !== '') { |
204 | - return parent::element_type($none_supported, $default_empty); |
|
204 | + return parent::element_type($none_supported, $default_empty); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | if ($default_empty) { |
208 | - return ''; |
|
208 | + return ''; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | if (isset($this->definition['element type'])) { |
212 | - return $this->definition['element type']; |
|
212 | + return $this->definition['element type']; |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return 'div'; |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - function render($values) { |
|
218 | + function render($values) { |
|
219 | 219 | // If this is not a grouped field, use content_handler_field::render(). |
220 | 220 | if (!$this->defer_query) { |
221 | - return parent::render($values); |
|
221 | + return parent::render($values); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | // We're down to a single node here, so we can retrieve the actual field |
@@ -228,95 +228,95 @@ discard block |
||
228 | 228 | // If the field does not appear in the node type, then we have no value |
229 | 229 | // to display, and can just return. |
230 | 230 | if (empty($field)) { |
231 | - return ''; |
|
231 | + return ''; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | $options = $this->options; |
235 | 235 | |
236 | 236 | $vid = $values->{$this->field_alias}; |
237 | 237 | if (isset($this->field_values[$vid])) { |
238 | - // Gather items, respecting the 'Display n values starting from m' settings. |
|
239 | - $count_skipped = 0; |
|
240 | - $items = array(); |
|
241 | - foreach ($this->field_values[$vid] as $item) { |
|
238 | + // Gather items, respecting the 'Display n values starting from m' settings. |
|
239 | + $count_skipped = 0; |
|
240 | + $items = array(); |
|
241 | + foreach ($this->field_values[$vid] as $item) { |
|
242 | 242 | if (empty($options['multiple']['multiple_from']) || ($count_skipped >= $options['multiple']['multiple_from'])) { |
243 | - if (empty($options['multiple']['multiple_number']) || (count($items) < $options['multiple']['multiple_number'])) { |
|
243 | + if (empty($options['multiple']['multiple_number']) || (count($items) < $options['multiple']['multiple_number'])) { |
|
244 | 244 | // Grab the nid - needed for render_link(). |
245 | 245 | $nid = $item['_nid']; |
246 | 246 | unset($item['_nid']); |
247 | 247 | $items[] = $item; |
248 | - } |
|
249 | - else { |
|
248 | + } |
|
249 | + else { |
|
250 | 250 | break; |
251 | - } |
|
251 | + } |
|
252 | 252 | } |
253 | 253 | $count_skipped++; |
254 | - } |
|
255 | - |
|
256 | - // Build a pseudo-node from the retrieved values. |
|
257 | - $node = drupal_clone($values); |
|
258 | - // content_format and formatters will need a 'type'. |
|
259 | - $node->type = $values->{$this->aliases['type']}; |
|
260 | - $node->nid = $values->{$this->aliases['nid']}; |
|
261 | - $node->vid = $values->{$this->aliases['vid']}; |
|
262 | - |
|
263 | - // Some formatters need to behave differently depending on the build_mode |
|
264 | - // (for instance: preview), so we provide one. |
|
265 | - $node->build_mode = NODE_BUILD_NORMAL; |
|
266 | - |
|
267 | - // Render items. |
|
268 | - $formatter_name = $options['format']; |
|
269 | - if ($items && ($formatter = _content_get_formatter($formatter_name, $field['type']))) { |
|
254 | + } |
|
255 | + |
|
256 | + // Build a pseudo-node from the retrieved values. |
|
257 | + $node = drupal_clone($values); |
|
258 | + // content_format and formatters will need a 'type'. |
|
259 | + $node->type = $values->{$this->aliases['type']}; |
|
260 | + $node->nid = $values->{$this->aliases['nid']}; |
|
261 | + $node->vid = $values->{$this->aliases['vid']}; |
|
262 | + |
|
263 | + // Some formatters need to behave differently depending on the build_mode |
|
264 | + // (for instance: preview), so we provide one. |
|
265 | + $node->build_mode = NODE_BUILD_NORMAL; |
|
266 | + |
|
267 | + // Render items. |
|
268 | + $formatter_name = $options['format']; |
|
269 | + if ($items && ($formatter = _content_get_formatter($formatter_name, $field['type']))) { |
|
270 | 270 | $rendered = array(); |
271 | 271 | if (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE) { |
272 | - // Single-value formatter. |
|
273 | - foreach ($items as $item) { |
|
272 | + // Single-value formatter. |
|
273 | + foreach ($items as $item) { |
|
274 | 274 | $output = content_format($field, $item, $formatter_name, $node); |
275 | 275 | if (!empty($output)) { |
276 | - $rendered[] = $this->render_link($output, (object) array('nid' => $nid)); |
|
276 | + $rendered[] = $this->render_link($output, (object) array('nid' => $nid)); |
|
277 | + } |
|
277 | 278 | } |
278 | - } |
|
279 | 279 | } |
280 | 280 | else { |
281 | - // Multiple values formatter. |
|
282 | - $output = content_format($field, $items, $formatter_name, $values); |
|
283 | - if (!empty($output)) { |
|
281 | + // Multiple values formatter. |
|
282 | + $output = content_format($field, $items, $formatter_name, $values); |
|
283 | + if (!empty($output)) { |
|
284 | 284 | $rendered[] = $this->render_link($output, (object) array('nid' => $nid)); |
285 | - } |
|
285 | + } |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | if (count($rendered) > 1) { |
289 | - // TODO: could we use generic field display ? |
|
290 | - return theme('content_view_multiple_field', $rendered, $field, $values); |
|
289 | + // TODO: could we use generic field display ? |
|
290 | + return theme('content_view_multiple_field', $rendered, $field, $values); |
|
291 | 291 | } |
292 | 292 | elseif ($rendered) { |
293 | - return $rendered[0]; |
|
293 | + return $rendered[0]; |
|
294 | + } |
|
294 | 295 | } |
295 | - } |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | return ''; |
299 | - } |
|
299 | + } |
|
300 | 300 | |
301 | - function render_link($data, $values) { |
|
301 | + function render_link($data, $values) { |
|
302 | 302 | if (!$this->defer_query) { |
303 | - return parent::render_link($data, $values); |
|
303 | + return parent::render_link($data, $values); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | if (!empty($this->options['link_to_node']) && $data !== NULL && $data !== '') { |
307 | - if (method_exists('render_as_link', 'views_handler_field')) { |
|
307 | + if (method_exists('render_as_link', 'views_handler_field')) { |
|
308 | 308 | // Views 2.3+ |
309 | 309 | $this->options['alter']['make_link'] = TRUE; |
310 | 310 | $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']}; |
311 | - } |
|
312 | - else { |
|
311 | + } |
|
312 | + else { |
|
313 | 313 | // Views up to 2.2 |
314 | 314 | return l($data, "node/" . $values->nid, array('html' => TRUE)); |
315 | - } |
|
315 | + } |
|
316 | 316 | } |
317 | 317 | else { |
318 | - return $data; |
|
318 | + return $data; |
|
319 | + } |
|
319 | 320 | } |
320 | - } |
|
321 | 321 | |
322 | 322 | } |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | foreach ($db_info['columns'] as $column => $attributes) { |
169 | 169 | $query_columns[] = "$attributes[column] AS $column"; |
170 | 170 | } |
171 | - $query = 'SELECT '. implode(', ', $query_columns) . |
|
172 | - ' FROM {'. $db_info['table'] ."}". |
|
173 | - " WHERE vid IN (". implode(',', $vids) .')'. |
|
174 | - " ORDER BY _nid ASC, _delta ". ($options['multiple']['multiple_reversed'] ? 'DESC' : 'ASC'); |
|
171 | + $query = 'SELECT '.implode(', ', $query_columns). |
|
172 | + ' FROM {'.$db_info['table']."}". |
|
173 | + " WHERE vid IN (".implode(',', $vids).')'. |
|
174 | + " ORDER BY _nid ASC, _delta ".($options['multiple']['multiple_reversed'] ? 'DESC' : 'ASC'); |
|
175 | 175 | $result = db_query($query); |
176 | 176 | |
177 | 177 | while ($item = db_fetch_array($result)) { |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | foreach ($items as $item) { |
274 | 274 | $output = content_format($field, $item, $formatter_name, $node); |
275 | 275 | if (!empty($output)) { |
276 | - $rendered[] = $this->render_link($output, (object) array('nid' => $nid)); |
|
276 | + $rendered[] = $this->render_link($output, (object)array('nid' => $nid)); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | // Multiple values formatter. |
282 | 282 | $output = content_format($field, $items, $formatter_name, $values); |
283 | 283 | if (!empty($output)) { |
284 | - $rendered[] = $this->render_link($output, (object) array('nid' => $nid)); |
|
284 | + $rendered[] = $this->render_link($output, (object)array('nid' => $nid)); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
@@ -307,11 +307,11 @@ discard block |
||
307 | 307 | if (method_exists('render_as_link', 'views_handler_field')) { |
308 | 308 | // Views 2.3+ |
309 | 309 | $this->options['alter']['make_link'] = TRUE; |
310 | - $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']}; |
|
310 | + $this->options['alter']['path'] = "node/".$values->{$this->aliases['nid']}; |
|
311 | 311 | } |
312 | 312 | else { |
313 | 313 | // Views up to 2.2 |
314 | - return l($data, "node/" . $values->nid, array('html' => TRUE)); |
|
314 | + return l($data, "node/".$values->nid, array('html' => TRUE)); |
|
315 | 315 | } |
316 | 316 | } |
317 | 317 | else { |
@@ -29,8 +29,7 @@ discard block |
||
29 | 29 | ); |
30 | 30 | if ($view->base_table == 'node_revisions') { |
31 | 31 | $this->additional_fields['vid'] = array('table' => 'node_revisions', 'field' => 'vid'); |
32 | - } |
|
33 | - else { |
|
32 | + } else { |
|
34 | 33 | $this->additional_fields['vid'] = array('table' => 'node', 'field' => 'vid'); |
35 | 34 | } |
36 | 35 | } |
@@ -245,8 +244,7 @@ discard block |
||
245 | 244 | $nid = $item['_nid']; |
246 | 245 | unset($item['_nid']); |
247 | 246 | $items[] = $item; |
248 | - } |
|
249 | - else { |
|
247 | + } else { |
|
250 | 248 | break; |
251 | 249 | } |
252 | 250 | } |
@@ -276,8 +274,7 @@ discard block |
||
276 | 274 | $rendered[] = $this->render_link($output, (object) array('nid' => $nid)); |
277 | 275 | } |
278 | 276 | } |
279 | - } |
|
280 | - else { |
|
277 | + } else { |
|
281 | 278 | // Multiple values formatter. |
282 | 279 | $output = content_format($field, $items, $formatter_name, $values); |
283 | 280 | if (!empty($output)) { |
@@ -288,8 +285,7 @@ discard block |
||
288 | 285 | if (count($rendered) > 1) { |
289 | 286 | // TODO: could we use generic field display ? |
290 | 287 | return theme('content_view_multiple_field', $rendered, $field, $values); |
291 | - } |
|
292 | - elseif ($rendered) { |
|
288 | + } elseif ($rendered) { |
|
293 | 289 | return $rendered[0]; |
294 | 290 | } |
295 | 291 | } |
@@ -308,13 +304,11 @@ discard block |
||
308 | 304 | // Views 2.3+ |
309 | 305 | $this->options['alter']['make_link'] = TRUE; |
310 | 306 | $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']}; |
311 | - } |
|
312 | - else { |
|
307 | + } else { |
|
313 | 308 | // Views up to 2.2 |
314 | 309 | return l($data, "node/" . $values->nid, array('html' => TRUE)); |
315 | 310 | } |
316 | - } |
|
317 | - else { |
|
311 | + } else { |
|
318 | 312 | return $data; |
319 | 313 | } |
320 | 314 | } |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | |
42 | 42 | $options['multiple'] = array( |
43 | 43 | 'contains' => array( |
44 | - 'group' => array('default' => TRUE), |
|
44 | + 'group' => array('default' => true), |
|
45 | 45 | 'multiple_number' => array('default' => ''), |
46 | 46 | 'multiple_from' => array('default' => ''), |
47 | - 'multiple_reversed' => array('default' => FALSE), |
|
47 | + 'multiple_reversed' => array('default' => false), |
|
48 | 48 | ), |
49 | 49 | ); |
50 | 50 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | '#default_value' => $options['multiple']['multiple_number'], |
82 | 82 | '#prefix' => '<div class="container-inline">', |
83 | 83 | '#process' => array('views_process_dependency'), |
84 | - '#dependency' => array('edit-options-multiple-group' => array(TRUE)), |
|
84 | + '#dependency' => array('edit-options-multiple-group' => array(true)), |
|
85 | 85 | ); |
86 | 86 | list($prefix, $suffix) = explode('@count', t('starting from @count')); |
87 | 87 | $form['multiple']['multiple_from'] = array( |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | '#field_suffix' => $suffix, |
92 | 92 | '#default_value' => $options['multiple']['multiple_from'], |
93 | 93 | '#process' => array('views_process_dependency'), |
94 | - '#dependency' => array('edit-options-multiple-group' => array(TRUE)), |
|
94 | + '#dependency' => array('edit-options-multiple-group' => array(true)), |
|
95 | 95 | '#description' => t('(first item is 0)'), |
96 | 96 | ); |
97 | 97 | $form['multiple']['multiple_reversed'] = array( |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | '#default_value' => $options['multiple']['multiple_reversed'], |
101 | 101 | '#suffix' => '</div>', |
102 | 102 | '#process' => array('views_process_dependency'), |
103 | - '#dependency' => array('edit-options-multiple-group' => array(TRUE)), |
|
103 | + '#dependency' => array('edit-options-multiple-group' => array(true)), |
|
104 | 104 | '#description' => t('(start from last values)'), |
105 | 105 | ); |
106 | 106 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * Fields rendered with the 'group multiple' option use <div> markers, |
192 | 192 | * and thus shouldn't be wrapped in a <span>. |
193 | 193 | */ |
194 | - function element_type($none_supported = FALSE, $default_empty = FALSE) { |
|
194 | + function element_type($none_supported = false, $default_empty = false) { |
|
195 | 195 | // If this is not a grouped field, use the parent method. |
196 | 196 | if (!$this->defer_query) { |
197 | 197 | return parent::element_type($none_supported, $default_empty); |
@@ -303,15 +303,15 @@ discard block |
||
303 | 303 | return parent::render_link($data, $values); |
304 | 304 | } |
305 | 305 | |
306 | - if (!empty($this->options['link_to_node']) && $data !== NULL && $data !== '') { |
|
306 | + if (!empty($this->options['link_to_node']) && $data !== null && $data !== '') { |
|
307 | 307 | if (method_exists('render_as_link', 'views_handler_field')) { |
308 | 308 | // Views 2.3+ |
309 | - $this->options['alter']['make_link'] = TRUE; |
|
309 | + $this->options['alter']['make_link'] = true; |
|
310 | 310 | $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']}; |
311 | 311 | } |
312 | 312 | else { |
313 | 313 | // Views up to 2.2 |
314 | - return l($data, "node/" . $values->nid, array('html' => TRUE)); |
|
314 | + return l($data, "node/" . $values->nid, array('html' => true)); |
|
315 | 315 | } |
316 | 316 | } |
317 | 317 | else { |
@@ -6,38 +6,38 @@ |
||
6 | 6 | * Handler for 'content_simple' display. |
7 | 7 | */ |
8 | 8 | class content_plugin_display_simple extends views_plugin_display { |
9 | - function execute() { |
|
9 | + function execute() { |
|
10 | 10 | return $this->view->render($this->display->id); |
11 | - } |
|
11 | + } |
|
12 | 12 | |
13 | - function render() { |
|
13 | + function render() { |
|
14 | 14 | return !empty($this->view->result) || !empty($this->view->style_plugin->definition['even empty']) ? $this->view->style_plugin->render($this->view->result) : ''; |
15 | - } |
|
15 | + } |
|
16 | 16 | |
17 | - function uses_exposed() { |
|
17 | + function uses_exposed() { |
|
18 | 18 | return FALSE; |
19 | - } |
|
19 | + } |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class content_plugin_display_references extends content_plugin_display_simple { |
23 | - function query() { |
|
23 | + function query() { |
|
24 | 24 | $options = $this->get_option('content_options'); |
25 | 25 | |
26 | 26 | if ($options['string'] !== '') { |
27 | - $like = $GLOBALS["db_type"] == 'pgsql' ? "ILIKE" : "LIKE"; |
|
28 | - $match_clauses = array( |
|
27 | + $like = $GLOBALS["db_type"] == 'pgsql' ? "ILIKE" : "LIKE"; |
|
28 | + $match_clauses = array( |
|
29 | 29 | 'contains' => "$like '%%%s%%'", |
30 | 30 | 'equals' => "= '%s'", |
31 | 31 | 'starts_with' => "$like '%s%%'", |
32 | - ); |
|
33 | - $clause = isset($match_clauses[$options['match']]) ? $match_clauses[$options['match']] : $match_clauses['contains']; |
|
34 | - $alias = $this->view->query->ensure_table($options['table']); |
|
35 | - $this->view->query->add_where(NULL, "$alias.$options[field_string] $clause", $options['string']); |
|
32 | + ); |
|
33 | + $clause = isset($match_clauses[$options['match']]) ? $match_clauses[$options['match']] : $match_clauses['contains']; |
|
34 | + $alias = $this->view->query->ensure_table($options['table']); |
|
35 | + $this->view->query->add_where(NULL, "$alias.$options[field_string] $clause", $options['string']); |
|
36 | 36 | } |
37 | 37 | elseif ($options['ids']) { |
38 | - $alias = $this->view->query->ensure_table($options['table']); |
|
39 | - $this->view->query->add_where(NULL, "$alias.$options[field_id] IN (" . db_placeholders($options['ids']) . ')', $options['ids']); |
|
38 | + $alias = $this->view->query->ensure_table($options['table']); |
|
39 | + $this->view->query->add_where(NULL, "$alias.$options[field_id] IN (" . db_placeholders($options['ids']) . ')', $options['ids']); |
|
40 | + } |
|
40 | 41 | } |
41 | - } |
|
42 | 42 | } |
43 | 43 |
@@ -36,7 +36,7 @@ |
||
36 | 36 | } |
37 | 37 | elseif ($options['ids']) { |
38 | 38 | $alias = $this->view->query->ensure_table($options['table']); |
39 | - $this->view->query->add_where(NULL, "$alias.$options[field_id] IN (" . db_placeholders($options['ids']) . ')', $options['ids']); |
|
39 | + $this->view->query->add_where(NULL, "$alias.$options[field_id] IN (".db_placeholders($options['ids']).')', $options['ids']); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | } |
@@ -33,8 +33,7 @@ |
||
33 | 33 | $clause = isset($match_clauses[$options['match']]) ? $match_clauses[$options['match']] : $match_clauses['contains']; |
34 | 34 | $alias = $this->view->query->ensure_table($options['table']); |
35 | 35 | $this->view->query->add_where(NULL, "$alias.$options[field_string] $clause", $options['string']); |
36 | - } |
|
37 | - elseif ($options['ids']) { |
|
36 | + } elseif ($options['ids']) { |
|
38 | 37 | $alias = $this->view->query->ensure_table($options['table']); |
39 | 38 | $this->view->query->add_where(NULL, "$alias.$options[field_id] IN (" . db_placeholders($options['ids']) . ')', $options['ids']); |
40 | 39 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | function uses_exposed() { |
18 | - return FALSE; |
|
18 | + return false; |
|
19 | 19 | } |
20 | 20 | } |
21 | 21 | |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | ); |
33 | 33 | $clause = isset($match_clauses[$options['match']]) ? $match_clauses[$options['match']] : $match_clauses['contains']; |
34 | 34 | $alias = $this->view->query->ensure_table($options['table']); |
35 | - $this->view->query->add_where(NULL, "$alias.$options[field_string] $clause", $options['string']); |
|
35 | + $this->view->query->add_where(null, "$alias.$options[field_string] $clause", $options['string']); |
|
36 | 36 | } |
37 | 37 | elseif ($options['ids']) { |
38 | 38 | $alias = $this->view->query->ensure_table($options['table']); |
39 | - $this->view->query->add_where(NULL, "$alias.$options[field_id] IN (" . db_placeholders($options['ids']) . ')', $options['ids']); |
|
39 | + $this->view->query->add_where(null, "$alias.$options[field_id] IN (" . db_placeholders($options['ids']) . ')', $options['ids']); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | } |
@@ -11,27 +11,27 @@ discard block |
||
11 | 11 | * content_handler_field_multiple. |
12 | 12 | */ |
13 | 13 | class content_handler_field extends views_handler_field_node { |
14 | - var $content_field; |
|
14 | + var $content_field; |
|
15 | 15 | |
16 | - function construct() { |
|
16 | + function construct() { |
|
17 | 17 | parent::construct(); |
18 | 18 | $this->content_field = content_fields($this->definition['content_field_name']); |
19 | - } |
|
19 | + } |
|
20 | 20 | |
21 | - function init(&$view, $options) { |
|
21 | + function init(&$view, $options) { |
|
22 | 22 | $field = $this->content_field; |
23 | 23 | parent::init($view, $options); |
24 | 24 | if ($field['multiple']) { |
25 | - $this->additional_fields['delta'] = 'delta'; |
|
25 | + $this->additional_fields['delta'] = 'delta'; |
|
26 | 26 | } |
27 | 27 | // Make sure we grab enough information to build a pseudo-node with enough |
28 | 28 | // credentials at render-time. |
29 | 29 | $this->additional_fields['type'] = array('table' => 'node', 'field' => 'type'); |
30 | 30 | $this->additional_fields['nid'] = array('table' => 'node', 'field' => 'nid'); |
31 | 31 | $this->additional_fields['vid'] = array('table' => 'node', 'field' => 'vid'); |
32 | - } |
|
32 | + } |
|
33 | 33 | |
34 | - function option_definition() { |
|
34 | + function option_definition() { |
|
35 | 35 | $options = parent::option_definition(); |
36 | 36 | $field = $this->content_field; |
37 | 37 | |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | $options['format'] = array('default' => 'default'); |
42 | 42 | |
43 | 43 | return $options; |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Provide formatter option. |
|
48 | - */ |
|
49 | - function options_form(&$form, &$form_state) { |
|
46 | + /** |
|
47 | + * Provide formatter option. |
|
48 | + */ |
|
49 | + function options_form(&$form, &$form_state) { |
|
50 | 50 | parent::options_form($form, $form_state); |
51 | 51 | // TODO: do we want the 'link to node' checkbox ? |
52 | 52 | // That's usually formatters business... |
@@ -55,102 +55,102 @@ discard block |
||
55 | 55 | $options = $this->options; |
56 | 56 | |
57 | 57 | $form['label_type'] = array( |
58 | - '#title' => t('Label'), |
|
59 | - '#type' => 'radios', |
|
60 | - '#options' => array( |
|
58 | + '#title' => t('Label'), |
|
59 | + '#type' => 'radios', |
|
60 | + '#options' => array( |
|
61 | 61 | 'none' => t('None'), |
62 | 62 | 'widget' => t('Widget label (@label)', array('@label' => $field['widget']['label'])), |
63 | 63 | 'custom' => t('Custom'), |
64 | - ), |
|
65 | - '#default_value' => $options['label_type'], |
|
66 | - '#weight' => 2, |
|
64 | + ), |
|
65 | + '#default_value' => $options['label_type'], |
|
66 | + '#weight' => 2, |
|
67 | 67 | ); |
68 | 68 | $form['label'] = array( |
69 | - '#title' => t('Custom label'), |
|
70 | - '#type' => 'textfield', |
|
71 | - '#default_value' => $options['label'], |
|
72 | - '#process' => array('views_process_dependency'), |
|
73 | - '#dependency' => array('radio:options[label_type]' => array('custom')), |
|
74 | - '#weight' => 3, |
|
75 | - ); |
|
69 | + '#title' => t('Custom label'), |
|
70 | + '#type' => 'textfield', |
|
71 | + '#default_value' => $options['label'], |
|
72 | + '#process' => array('views_process_dependency'), |
|
73 | + '#dependency' => array('radio:options[label_type]' => array('custom')), |
|
74 | + '#weight' => 3, |
|
75 | + ); |
|
76 | 76 | |
77 | 77 | $field_types = _content_field_types(); |
78 | 78 | $formatters = array(); |
79 | 79 | if (is_array($field_types[$field['type']]['formatters'])) { |
80 | - foreach ($field_types[$field['type']]['formatters'] as $name => $info) { |
|
80 | + foreach ($field_types[$field['type']]['formatters'] as $name => $info) { |
|
81 | 81 | $formatters[$name] = $info['label']; |
82 | - } |
|
82 | + } |
|
83 | 83 | } |
84 | 84 | $form['format'] = array( |
85 | - '#title' => t('Format'), |
|
86 | - '#type' => 'select', |
|
87 | - '#options' => $formatters, |
|
88 | - '#required' => TRUE, |
|
89 | - '#default_value' => $options['format'], |
|
90 | - '#weight' => 4, |
|
85 | + '#title' => t('Format'), |
|
86 | + '#type' => 'select', |
|
87 | + '#options' => $formatters, |
|
88 | + '#required' => TRUE, |
|
89 | + '#default_value' => $options['format'], |
|
90 | + '#weight' => 4, |
|
91 | 91 | ); |
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Make sure some value is stored as a label. |
|
97 | - * |
|
98 | - * Don't use t(), since Views' views_handler_field already has |
|
99 | - * $this->options['label'] marked as a translatable field. |
|
100 | - * |
|
101 | - * @see http://drupal.org/node/285470 |
|
102 | - */ |
|
103 | - function options_submit($form, &$form_state) { |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Make sure some value is stored as a label. |
|
97 | + * |
|
98 | + * Don't use t(), since Views' views_handler_field already has |
|
99 | + * $this->options['label'] marked as a translatable field. |
|
100 | + * |
|
101 | + * @see http://drupal.org/node/285470 |
|
102 | + */ |
|
103 | + function options_submit($form, &$form_state) { |
|
104 | 104 | switch ($form_state['values']['options']['label_type']) { |
105 | - case 'none': |
|
105 | + case 'none': |
|
106 | 106 | $form_state['values']['options']['label'] = ''; |
107 | 107 | break; |
108 | - case 'widget': |
|
108 | + case 'widget': |
|
109 | 109 | $form_state['values']['options']['label'] = $this->content_field['widget']['label']; |
110 | 110 | break; |
111 | 111 | } |
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @TODO |
|
116 | - * Now that we save the label in the submit process above we could |
|
117 | - * get rid of this function. Leave it here for now to be sure the |
|
118 | - * label works for fields that haven't been updated since this |
|
119 | - * change was made, since $this->options['label'] will be missing a |
|
120 | - * value until it is updated in the view. |
|
121 | - * |
|
122 | - * Don't use t(), since Views' views_handler_field already has |
|
123 | - * $this->options['label'] marked as a translatable field. |
|
124 | - */ |
|
125 | - function label() { |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @TODO |
|
116 | + * Now that we save the label in the submit process above we could |
|
117 | + * get rid of this function. Leave it here for now to be sure the |
|
118 | + * label works for fields that haven't been updated since this |
|
119 | + * change was made, since $this->options['label'] will be missing a |
|
120 | + * value until it is updated in the view. |
|
121 | + * |
|
122 | + * Don't use t(), since Views' views_handler_field already has |
|
123 | + * $this->options['label'] marked as a translatable field. |
|
124 | + */ |
|
125 | + function label() { |
|
126 | 126 | $field = $this->content_field; |
127 | 127 | switch ($this->options['label_type']) { |
128 | - case 'none': |
|
128 | + case 'none': |
|
129 | 129 | return ''; |
130 | - case 'widget': |
|
130 | + case 'widget': |
|
131 | 131 | return $field['widget']['label']; |
132 | - default: |
|
132 | + default: |
|
133 | 133 | return $this->options['label']; |
134 | 134 | } |
135 | - } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Return DIV or SPAN based upon the field's element type. |
|
139 | - */ |
|
140 | - function element_type($none_supported = FALSE, $default_empty = FALSE) { |
|
137 | + /** |
|
138 | + * Return DIV or SPAN based upon the field's element type. |
|
139 | + */ |
|
140 | + function element_type($none_supported = FALSE, $default_empty = FALSE) { |
|
141 | 141 | // The 'element_type' property denotes Views 3.x ('semantic views' |
142 | 142 | // functionnality). If the property is set, and not set to '' ("default"), |
143 | 143 | // let the generic method handle the output. |
144 | 144 | if (isset($this->options['element_type']) && $this->options['element_type'] !== '') { |
145 | - return parent::element_type($none_supported, $default_empty); |
|
145 | + return parent::element_type($none_supported, $default_empty); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | if ($default_empty) { |
149 | - return ''; |
|
149 | + return ''; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | if (isset($this->definition['element type'])) { |
153 | - return $this->definition['element type']; |
|
153 | + return $this->definition['element type']; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | // TODO Figure out exactly when to return a div or a <span>. Any field |
@@ -159,28 +159,28 @@ discard block |
||
159 | 159 | // Earl says we need to be sure that other fields we don't know |
160 | 160 | // about won't end up wrapping a span around a block-level element. |
161 | 161 | if ($this->content_field['widget']['type'] == 'text_textarea') { |
162 | - return 'div'; |
|
162 | + return 'div'; |
|
163 | 163 | } |
164 | 164 | else { |
165 | - return 'span'; |
|
165 | + return 'span'; |
|
166 | + } |
|
166 | 167 | } |
167 | - } |
|
168 | 168 | |
169 | - function options_validate($form, &$form_state) { } |
|
169 | + function options_validate($form, &$form_state) { } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Provide text for the administrative summary |
|
173 | - */ |
|
174 | - function admin_summary() { |
|
171 | + /** |
|
172 | + * Provide text for the administrative summary |
|
173 | + */ |
|
174 | + function admin_summary() { |
|
175 | 175 | // Display the formatter name. |
176 | 176 | $field = $this->content_field; |
177 | 177 | $field_types = _content_field_types(); |
178 | 178 | if (isset($field_types[$field['type']]['formatters'][$this->options['format']])) { |
179 | - return t($field_types[$field['type']]['formatters'][$this->options['format']]['label']); |
|
179 | + return t($field_types[$field['type']]['formatters'][$this->options['format']]['label']); |
|
180 | + } |
|
180 | 181 | } |
181 | - } |
|
182 | 182 | |
183 | - function render($values) { |
|
183 | + function render($values) { |
|
184 | 184 | // We're down to a single node here, so we can retrieve the actual field |
185 | 185 | // definition for the node type being considered. |
186 | 186 | $field = content_fields($this->content_field['field_name'], $values->{$this->aliases['type']}); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | // If the field does not appear in the node type, then we have no value |
189 | 189 | // to display, and can just return. |
190 | 190 | if (empty($field)) { |
191 | - return ''; |
|
191 | + return ''; |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | $options = $this->options; |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | |
206 | 206 | $item = array(); |
207 | 207 | foreach ($db_info['columns'] as $column => $attributes) { |
208 | - $item[$column] = $values->{$this->aliases[$attributes['column']]}; |
|
208 | + $item[$column] = $values->{$this->aliases[$attributes['column']]}; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | $item['#delta'] = $field['multiple'] ? $values->{$this->aliases['delta']} : 0; |
@@ -213,17 +213,17 @@ discard block |
||
213 | 213 | // Render items. |
214 | 214 | $formatter_name = $options['format']; |
215 | 215 | if ($formatter = _content_get_formatter($formatter_name, $field['type'])) { |
216 | - if (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE) { |
|
216 | + if (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE) { |
|
217 | 217 | // Single-value formatter. |
218 | 218 | $output = content_format($field, $item, $formatter_name, $node); |
219 | - } |
|
220 | - else { |
|
219 | + } |
|
220 | + else { |
|
221 | 221 | // Multiple values formatter - we actually have only one value to display. |
222 | 222 | $output = content_format($field, array($item), $formatter_name, $node); |
223 | - } |
|
224 | - return $this->render_link($output, $values); |
|
223 | + } |
|
224 | + return $this->render_link($output, $values); |
|
225 | 225 | } |
226 | 226 | return ''; |
227 | - } |
|
227 | + } |
|
228 | 228 | |
229 | 229 | } |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function options_submit($form, &$form_state) { |
104 | 104 | switch ($form_state['values']['options']['label_type']) { |
105 | - case 'none': |
|
106 | - $form_state['values']['options']['label'] = ''; |
|
107 | - break; |
|
108 | - case 'widget': |
|
109 | - $form_state['values']['options']['label'] = $this->content_field['widget']['label']; |
|
110 | - break; |
|
105 | + case 'none': |
|
106 | + $form_state['values']['options']['label'] = ''; |
|
107 | + break; |
|
108 | + case 'widget': |
|
109 | + $form_state['values']['options']['label'] = $this->content_field['widget']['label']; |
|
110 | + break; |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | function label() { |
126 | 126 | $field = $this->content_field; |
127 | 127 | switch ($this->options['label_type']) { |
128 | - case 'none': |
|
129 | - return ''; |
|
130 | - case 'widget': |
|
131 | - return $field['widget']['label']; |
|
132 | - default: |
|
133 | - return $this->options['label']; |
|
128 | + case 'none': |
|
129 | + return ''; |
|
130 | + case 'widget': |
|
131 | + return $field['widget']['label']; |
|
132 | + default: |
|
133 | + return $this->options['label']; |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 |
@@ -208,7 +208,7 @@ |
||
208 | 208 | $item[$column] = $values->{$this->aliases[$attributes['column']]}; |
209 | 209 | } |
210 | 210 | |
211 | - $item['#delta'] = $field['multiple'] ? $values->{$this->aliases['delta']} : 0; |
|
211 | + $item['#delta'] = $field['multiple'] ? $values->{$this->aliases['delta']} : 0; |
|
212 | 212 | |
213 | 213 | // Render items. |
214 | 214 | $formatter_name = $options['format']; |
@@ -160,8 +160,7 @@ discard block |
||
160 | 160 | // about won't end up wrapping a span around a block-level element. |
161 | 161 | if ($this->content_field['widget']['type'] == 'text_textarea') { |
162 | 162 | return 'div'; |
163 | - } |
|
164 | - else { |
|
163 | + } else { |
|
165 | 164 | return 'span'; |
166 | 165 | } |
167 | 166 | } |
@@ -216,8 +215,7 @@ discard block |
||
216 | 215 | if (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE) { |
217 | 216 | // Single-value formatter. |
218 | 217 | $output = content_format($field, $item, $formatter_name, $node); |
219 | - } |
|
220 | - else { |
|
218 | + } else { |
|
221 | 219 | // Multiple values formatter - we actually have only one value to display. |
222 | 220 | $output = content_format($field, array($item), $formatter_name, $node); |
223 | 221 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $field = $this->content_field; |
37 | 37 | |
38 | 38 | // Override views_handler_field_node's default label |
39 | - $options['label'] = array('default' => '', 'translatable' => TRUE); |
|
39 | + $options['label'] = array('default' => '', 'translatable' => true); |
|
40 | 40 | $options['label_type'] = array('default' => 'widget'); |
41 | 41 | $options['format'] = array('default' => 'default'); |
42 | 42 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | '#title' => t('Format'), |
86 | 86 | '#type' => 'select', |
87 | 87 | '#options' => $formatters, |
88 | - '#required' => TRUE, |
|
88 | + '#required' => true, |
|
89 | 89 | '#default_value' => $options['format'], |
90 | 90 | '#weight' => 4, |
91 | 91 | ); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * Return DIV or SPAN based upon the field's element type. |
139 | 139 | */ |
140 | - function element_type($none_supported = FALSE, $default_empty = FALSE) { |
|
140 | + function element_type($none_supported = false, $default_empty = false) { |
|
141 | 141 | // The 'element_type' property denotes Views 3.x ('semantic views' |
142 | 142 | // functionnality). If the property is set, and not set to '' ("default"), |
143 | 143 | // let the generic method handle the output. |
@@ -11,68 +11,68 @@ discard block |
||
11 | 11 | * Menu callback; replacement for node_overview_types(). |
12 | 12 | */ |
13 | 13 | function content_types_overview() { |
14 | - $types = node_get_types(); |
|
15 | - $names = node_get_types('names'); |
|
16 | - $header = array(t('Name'), t('Type'), t('Description'), array('data' => t('Operations'), 'colspan' => '4'),); |
|
17 | - $rows = array(); |
|
14 | + $types = node_get_types(); |
|
15 | + $names = node_get_types('names'); |
|
16 | + $header = array(t('Name'), t('Type'), t('Description'), array('data' => t('Operations'), 'colspan' => '4'),); |
|
17 | + $rows = array(); |
|
18 | 18 | |
19 | - foreach ($names as $key => $name) { |
|
19 | + foreach ($names as $key => $name) { |
|
20 | 20 | $type = $types[$key]; |
21 | 21 | if (node_hook($type, 'form')) { |
22 | - $type_url_str = str_replace('_', '-', $type->type); |
|
23 | - $row = array( |
|
22 | + $type_url_str = str_replace('_', '-', $type->type); |
|
23 | + $row = array( |
|
24 | 24 | check_plain($name), |
25 | 25 | check_plain($type->type), |
26 | - ); |
|
27 | - // Make the description smaller |
|
28 | - $row[] = array('data' => filter_xss_admin($type->description), 'class' => 'description'); |
|
29 | - // Set the edit column. |
|
30 | - $row[] = array('data' => l(t('edit'), 'admin/content/node-type/'. $type_url_str)); |
|
31 | - // Set links for managing fields. |
|
32 | - // TODO: a hook to allow other content modules to add more stuff? |
|
33 | - $row[] = array('data' => l(t('manage fields'), 'admin/content/node-type/'. $type_url_str .'/fields')); |
|
34 | - // Set the delete column. |
|
35 | - if ($type->custom) { |
|
26 | + ); |
|
27 | + // Make the description smaller |
|
28 | + $row[] = array('data' => filter_xss_admin($type->description), 'class' => 'description'); |
|
29 | + // Set the edit column. |
|
30 | + $row[] = array('data' => l(t('edit'), 'admin/content/node-type/'. $type_url_str)); |
|
31 | + // Set links for managing fields. |
|
32 | + // TODO: a hook to allow other content modules to add more stuff? |
|
33 | + $row[] = array('data' => l(t('manage fields'), 'admin/content/node-type/'. $type_url_str .'/fields')); |
|
34 | + // Set the delete column. |
|
35 | + if ($type->custom) { |
|
36 | 36 | $row[] = array('data' => l(t('delete'), 'admin/content/node-type/'. $type_url_str .'/delete')); |
37 | - } |
|
38 | - else { |
|
37 | + } |
|
38 | + else { |
|
39 | 39 | $row[] = array('data' => ''); |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - $rows[] = $row; |
|
42 | + $rows[] = $row; |
|
43 | + } |
|
43 | 44 | } |
44 | - } |
|
45 | 45 | |
46 | - // Allow external modules alter the table headers and rows. |
|
47 | - foreach (module_implements('content_types_overview_alter') as $module) { |
|
46 | + // Allow external modules alter the table headers and rows. |
|
47 | + foreach (module_implements('content_types_overview_alter') as $module) { |
|
48 | 48 | $function = $module .'_content_types_overview_alter'; |
49 | 49 | $function($header, $rows); |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - if (empty($rows)) { |
|
52 | + if (empty($rows)) { |
|
53 | 53 | $rows[] = array(array('data' => t('No content types available.'), 'colspan' => '7', 'class' => 'message')); |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - return theme('table', $header, $rows) .theme('content_overview_links'); |
|
56 | + return theme('table', $header, $rows) .theme('content_overview_links'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function theme_content_overview_links() { |
60 | - return '<div class="content-overview-links">'. l(t('» Add a new content type'), 'admin/content/types/add') .'</div>'; |
|
60 | + return '<div class="content-overview-links">'. l(t('» Add a new content type'), 'admin/content/types/add') .'</div>'; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Menu callback; lists all defined fields for quick reference. |
65 | 65 | */ |
66 | 66 | function content_fields_list() { |
67 | - $fields = content_fields(); |
|
68 | - $field_types = _content_field_types(); |
|
67 | + $fields = content_fields(); |
|
68 | + $field_types = _content_field_types(); |
|
69 | 69 | |
70 | - // Sort fields by field name. |
|
71 | - ksort($fields); |
|
70 | + // Sort fields by field name. |
|
71 | + ksort($fields); |
|
72 | 72 | |
73 | - $header = array(t('Field name'), t('Field type'), t('Used in')); |
|
74 | - $rows = array(); |
|
75 | - foreach ($fields as $field) { |
|
73 | + $header = array(t('Field name'), t('Field type'), t('Used in')); |
|
74 | + $rows = array(); |
|
75 | + foreach ($fields as $field) { |
|
76 | 76 | $row = array(); |
77 | 77 | $row[] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field['field_name'])) : $field['field_name']; |
78 | 78 | $row[] = t($field_types[$field['type']]['label']); |
@@ -85,40 +85,40 @@ discard block |
||
85 | 85 | "AND nfi.widget_active = 1 ". |
86 | 86 | "ORDER BY nt.name ASC", $field['field_name']); |
87 | 87 | while ($type = db_fetch_array($result)) { |
88 | - $content_type = content_types($type['type']); |
|
89 | - $types[] = l($type['name'], 'admin/content/node-type/'. $content_type['url_str'] .'/fields'); |
|
88 | + $content_type = content_types($type['type']); |
|
89 | + $types[] = l($type['name'], 'admin/content/node-type/'. $content_type['url_str'] .'/fields'); |
|
90 | 90 | } |
91 | 91 | $row[] = implode(', ', $types); |
92 | 92 | |
93 | 93 | $rows[] = array('data' => $row, 'class' => $field['locked'] ? 'menu-disabled' : ''); |
94 | - } |
|
95 | - if (empty($rows)) { |
|
94 | + } |
|
95 | + if (empty($rows)) { |
|
96 | 96 | $output = t('No fields have been defined for any content type yet.'); |
97 | - } |
|
98 | - else { |
|
97 | + } |
|
98 | + else { |
|
99 | 99 | $output = theme('table', $header, $rows); |
100 | - } |
|
101 | - return $output; |
|
100 | + } |
|
101 | + return $output; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * Helper function to display a message about inactive fields. |
106 | 106 | */ |
107 | 107 | function content_inactive_message($type_name) { |
108 | - $inactive_fields = content_inactive_fields($type_name); |
|
109 | - if (!empty($inactive_fields)) { |
|
108 | + $inactive_fields = content_inactive_fields($type_name); |
|
109 | + if (!empty($inactive_fields)) { |
|
110 | 110 | $field_types = _content_field_types(); |
111 | 111 | $widget_types = _content_widget_types($type_name); |
112 | 112 | drupal_set_message(t('This content type has inactive fields. Inactive fields are not included in lists of available fields until their modules are enabled.'), 'error'); |
113 | 113 | foreach ($inactive_fields as $field_name => $field) { |
114 | - drupal_set_message(t('!field (!field_name) is an inactive !field_type field that uses a !widget_type widget.', array( |
|
115 | - '!field' => $field['widget']['label'], |
|
116 | - '!field_name' => $field['field_name'], |
|
117 | - '!field_type' => array_key_exists($field['type'], $field_types) ? $field_types[$field['type']]['label'] : $field['type'], |
|
118 | - '!widget_type' => array_key_exists($field['widget']['type'], $widget_types) ? $widget_types[$field['widget']['type']]['label'] : $field['widget']['type'], |
|
119 | - ))); |
|
120 | - } |
|
121 | - } |
|
114 | + drupal_set_message(t('!field (!field_name) is an inactive !field_type field that uses a !widget_type widget.', array( |
|
115 | + '!field' => $field['widget']['label'], |
|
116 | + '!field_name' => $field['field_name'], |
|
117 | + '!field_type' => array_key_exists($field['type'], $field_types) ? $field_types[$field['type']]['label'] : $field['type'], |
|
118 | + '!widget_type' => array_key_exists($field['widget']['type'], $widget_types) ? $widget_types[$field['widget']['type']]['label'] : $field['widget']['type'], |
|
119 | + ))); |
|
120 | + } |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -129,34 +129,34 @@ discard block |
||
129 | 129 | */ |
130 | 130 | function content_field_overview_form(&$form_state, $type_name) { |
131 | 131 | |
132 | - content_inactive_message($type_name); |
|
132 | + content_inactive_message($type_name); |
|
133 | 133 | |
134 | - // When displaying the form, make sure the list of fields |
|
135 | - // is up-to-date. |
|
136 | - if (empty($form_state['post'])) { |
|
134 | + // When displaying the form, make sure the list of fields |
|
135 | + // is up-to-date. |
|
136 | + if (empty($form_state['post'])) { |
|
137 | 137 | content_clear_type_cache(); |
138 | - } |
|
138 | + } |
|
139 | 139 | |
140 | - // Gather type information. |
|
141 | - $type = content_types($type_name); |
|
142 | - $fields = $type['fields']; |
|
143 | - $field_types = _content_field_types(); |
|
140 | + // Gather type information. |
|
141 | + $type = content_types($type_name); |
|
142 | + $fields = $type['fields']; |
|
143 | + $field_types = _content_field_types(); |
|
144 | 144 | |
145 | - $extra = $type['extra']; |
|
146 | - $groups = $group_options = $group_types = array(); |
|
147 | - if (module_exists('fieldgroup')) { |
|
145 | + $extra = $type['extra']; |
|
146 | + $groups = $group_options = $group_types = array(); |
|
147 | + if (module_exists('fieldgroup')) { |
|
148 | 148 | $groups = fieldgroup_groups($type['type']); |
149 | 149 | $group_types = fieldgroup_types(); |
150 | 150 | $group_options = _fieldgroup_groups_label($type['type']); |
151 | 151 | // Add the ability to group under the newly created row. |
152 | 152 | $group_options['_add_new_group'] = '_add_new_group'; |
153 | - } |
|
153 | + } |
|
154 | 154 | |
155 | - // Store the default weights as we meet them, to be able to put the |
|
156 | - //'add new' rows after them. |
|
157 | - $weights = array(); |
|
155 | + // Store the default weights as we meet them, to be able to put the |
|
156 | + //'add new' rows after them. |
|
157 | + $weights = array(); |
|
158 | 158 | |
159 | - $form = array( |
|
159 | + $form = array( |
|
160 | 160 | '#tree' => TRUE, |
161 | 161 | '#type_name' => $type['type'], |
162 | 162 | '#fields' => array_keys($fields), |
@@ -164,94 +164,94 @@ discard block |
||
164 | 164 | '#extra' => array_keys($extra), |
165 | 165 | '#field_rows' => array(), |
166 | 166 | '#group_rows' => array(), |
167 | - ); |
|
167 | + ); |
|
168 | 168 | |
169 | - // Fields. |
|
170 | - foreach ($fields as $name => $field) { |
|
169 | + // Fields. |
|
170 | + foreach ($fields as $name => $field) { |
|
171 | 171 | $weight = $field['widget']['weight']; |
172 | 172 | $form[$name] = array( |
173 | - 'label' => array('#value' => check_plain($field['widget']['label'])), |
|
174 | - 'field_name' => array('#value' => $field['field_name']), |
|
175 | - 'type' => array('#value' => t($field_types[$field['type']]['label'])), |
|
176 | - 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'])), |
|
177 | - 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/remove')), |
|
178 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
179 | - 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
180 | - 'prev_parent' => array('#type' => 'hidden', '#value' => ''), |
|
181 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $field['field_name']), |
|
182 | - '#leaf' => TRUE, |
|
183 | - '#row_type' => 'field', |
|
184 | - 'field' => array('#type' => 'value', '#value' => $field), |
|
173 | + 'label' => array('#value' => check_plain($field['widget']['label'])), |
|
174 | + 'field_name' => array('#value' => $field['field_name']), |
|
175 | + 'type' => array('#value' => t($field_types[$field['type']]['label'])), |
|
176 | + 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'])), |
|
177 | + 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/remove')), |
|
178 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
179 | + 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
180 | + 'prev_parent' => array('#type' => 'hidden', '#value' => ''), |
|
181 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $field['field_name']), |
|
182 | + '#leaf' => TRUE, |
|
183 | + '#row_type' => 'field', |
|
184 | + 'field' => array('#type' => 'value', '#value' => $field), |
|
185 | 185 | ); |
186 | 186 | if ($field['locked']) { |
187 | - $form[$name]['configure'] = array('#value' => t('Locked')); |
|
188 | - $form[$name]['remove'] = array(); |
|
189 | - $form[$name]['#disabled_row'] = TRUE; |
|
187 | + $form[$name]['configure'] = array('#value' => t('Locked')); |
|
188 | + $form[$name]['remove'] = array(); |
|
189 | + $form[$name]['#disabled_row'] = TRUE; |
|
190 | 190 | } |
191 | 191 | $form['#field_rows'][] = $name; |
192 | 192 | $weights[] = $weight; |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - // Groups. |
|
196 | - foreach ($groups as $name => $group) { |
|
195 | + // Groups. |
|
196 | + foreach ($groups as $name => $group) { |
|
197 | 197 | $weight = $group['weight']; |
198 | 198 | $form[$name] = array( |
199 | - 'label' => array('#value' => check_plain($group['label'])), |
|
200 | - 'group_name' => array('#value' => $group['group_name']), |
|
201 | - 'group_type' => array('#value' => t($group_types[$group['group_type']])), |
|
202 | - 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'])), |
|
203 | - 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'] .'/remove')), |
|
204 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
205 | - 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
206 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $group['group_name']), |
|
207 | - '#root' => TRUE, |
|
208 | - '#row_type' => 'group', |
|
209 | - 'group' => array('#type' => 'value', '#value' => $group), |
|
199 | + 'label' => array('#value' => check_plain($group['label'])), |
|
200 | + 'group_name' => array('#value' => $group['group_name']), |
|
201 | + 'group_type' => array('#value' => t($group_types[$group['group_type']])), |
|
202 | + 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'])), |
|
203 | + 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'] .'/remove')), |
|
204 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
205 | + 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
206 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $group['group_name']), |
|
207 | + '#root' => TRUE, |
|
208 | + '#row_type' => 'group', |
|
209 | + 'group' => array('#type' => 'value', '#value' => $group), |
|
210 | 210 | ); |
211 | 211 | // Adjust child fields rows. |
212 | 212 | foreach ($group['fields'] as $field_name => $field) { |
213 | - $form[$field_name]['parent']['#default_value'] = $name; |
|
214 | - $form[$field_name]['prev_parent']['#value'] = $name; |
|
213 | + $form[$field_name]['parent']['#default_value'] = $name; |
|
214 | + $form[$field_name]['prev_parent']['#value'] = $name; |
|
215 | 215 | } |
216 | 216 | $form['#group_rows'][] = $name; |
217 | 217 | $weights[] = $weight; |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - // Non-CCK 'fields'. |
|
221 | - foreach ($extra as $name => $label) { |
|
220 | + // Non-CCK 'fields'. |
|
221 | + foreach ($extra as $name => $label) { |
|
222 | 222 | $weight = $extra[$name]['weight']; |
223 | 223 | $form[$name] = array( |
224 | - 'label' => array('#value' => check_plain(t($extra[$name]['label']))), |
|
225 | - 'description' => array('#value' => isset($extra[$name]['description']) ? $extra[$name]['description'] : ''), |
|
226 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
227 | - 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
228 | - 'configure' => array('#value' => isset($extra[$name]['configure']) ? $extra[$name]['configure'] : ''), |
|
229 | - 'remove' => array('#value' => isset($extra[$name]['remove']) ? $extra[$name]['remove'] : ''), |
|
230 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
231 | - '#leaf' => TRUE, |
|
232 | - '#root' => TRUE, |
|
233 | - '#disabled_row' => TRUE, |
|
234 | - '#row_type' => 'extra', |
|
224 | + 'label' => array('#value' => check_plain(t($extra[$name]['label']))), |
|
225 | + 'description' => array('#value' => isset($extra[$name]['description']) ? $extra[$name]['description'] : ''), |
|
226 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
227 | + 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
228 | + 'configure' => array('#value' => isset($extra[$name]['configure']) ? $extra[$name]['configure'] : ''), |
|
229 | + 'remove' => array('#value' => isset($extra[$name]['remove']) ? $extra[$name]['remove'] : ''), |
|
230 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
231 | + '#leaf' => TRUE, |
|
232 | + '#root' => TRUE, |
|
233 | + '#disabled_row' => TRUE, |
|
234 | + '#row_type' => 'extra', |
|
235 | 235 | ); |
236 | 236 | $form['#field_rows'][] = $name; |
237 | 237 | $weights[] = $weight; |
238 | - } |
|
238 | + } |
|
239 | 239 | |
240 | - // Additional row : add new field. |
|
241 | - $weight = max($weights) + 1; |
|
242 | - $field_type_options = content_field_type_options(); |
|
243 | - $widget_type_options = content_widget_type_options(NULL, TRUE); |
|
244 | - if ($field_type_options && $widget_type_options) { |
|
240 | + // Additional row : add new field. |
|
241 | + $weight = max($weights) + 1; |
|
242 | + $field_type_options = content_field_type_options(); |
|
243 | + $widget_type_options = content_widget_type_options(NULL, TRUE); |
|
244 | + if ($field_type_options && $widget_type_options) { |
|
245 | 245 | array_unshift($field_type_options, t('- Select a field type -')); |
246 | 246 | array_unshift($widget_type_options, t('- Select a widget -')); |
247 | 247 | $name = '_add_new_field'; |
248 | 248 | $form[$name] = array( |
249 | - 'label' => array( |
|
249 | + 'label' => array( |
|
250 | 250 | '#type' => 'textfield', |
251 | 251 | '#size' => 15, |
252 | 252 | '#description' => t('Label'), |
253 | - ), |
|
254 | - 'field_name' => array( |
|
253 | + ), |
|
254 | + 'field_name' => array( |
|
255 | 255 | '#type' => 'textfield', |
256 | 256 | // This field should stay LTR even for RTL languages. |
257 | 257 | '#field_prefix' => '<span dir="ltr">field_', |
@@ -262,70 +262,70 @@ discard block |
||
262 | 262 | // prefix which is 6 characters long. |
263 | 263 | '#maxlength' => 26, |
264 | 264 | '#description' => t('Field name (a-z, 0-9, _)'), |
265 | - ), |
|
266 | - 'type' => array( |
|
265 | + ), |
|
266 | + 'type' => array( |
|
267 | 267 | '#type' => 'select', |
268 | 268 | '#options' => $field_type_options, |
269 | 269 | '#description' => theme('advanced_help_topic', 'content', 'fields') . t('Type of data to store.'), |
270 | - ), |
|
271 | - 'widget_type' => array( |
|
270 | + ), |
|
271 | + 'widget_type' => array( |
|
272 | 272 | '#type' => 'select', |
273 | 273 | '#options' => $widget_type_options, |
274 | 274 | '#description' => t('Form element to edit the data.'), |
275 | - ), |
|
276 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
277 | - 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
278 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
279 | - '#leaf' => TRUE, |
|
280 | - '#add_new' => TRUE, |
|
281 | - '#row_type' => 'add_new_field', |
|
275 | + ), |
|
276 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
277 | + 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
278 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
279 | + '#leaf' => TRUE, |
|
280 | + '#add_new' => TRUE, |
|
281 | + '#row_type' => 'add_new_field', |
|
282 | 282 | ); |
283 | 283 | $form['#field_rows'][] = $name; |
284 | - } |
|
284 | + } |
|
285 | 285 | |
286 | - // Additional row : add existing field. |
|
287 | - $existing_field_options = content_existing_field_options($type_name); |
|
288 | - if ($existing_field_options && $widget_type_options) { |
|
286 | + // Additional row : add existing field. |
|
287 | + $existing_field_options = content_existing_field_options($type_name); |
|
288 | + if ($existing_field_options && $widget_type_options) { |
|
289 | 289 | $weight++; |
290 | 290 | array_unshift($existing_field_options, t('- Select an existing field -')); |
291 | 291 | $name = '_add_existing_field'; |
292 | 292 | $form[$name] = array( |
293 | - 'label' => array( |
|
293 | + 'label' => array( |
|
294 | 294 | '#type' => 'textfield', |
295 | 295 | '#size' => 15, |
296 | 296 | '#description' => t('Label'), |
297 | - ), |
|
298 | - 'field_name' => array( |
|
297 | + ), |
|
298 | + 'field_name' => array( |
|
299 | 299 | '#type' => 'select', |
300 | 300 | '#options' => $existing_field_options, |
301 | 301 | '#description' => t('Field to share'), |
302 | - ), |
|
303 | - 'widget_type' => array( |
|
302 | + ), |
|
303 | + 'widget_type' => array( |
|
304 | 304 | '#type' => 'select', |
305 | 305 | '#options' => $widget_type_options, |
306 | 306 | '#description' => t('Form element to edit the data.'), |
307 | - ), |
|
308 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
309 | - 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
310 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
311 | - '#leaf' => TRUE, |
|
312 | - '#add_new' => TRUE, |
|
313 | - '#row_type' => 'add_existing_field', |
|
307 | + ), |
|
308 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
309 | + 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
|
310 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
311 | + '#leaf' => TRUE, |
|
312 | + '#add_new' => TRUE, |
|
313 | + '#row_type' => 'add_existing_field', |
|
314 | 314 | ); |
315 | 315 | $form['#field_rows'][] = $name; |
316 | - } |
|
316 | + } |
|
317 | 317 | |
318 | - // Additional row : add new group. |
|
319 | - if (!empty($group_types)) { |
|
318 | + // Additional row : add new group. |
|
319 | + if (!empty($group_types)) { |
|
320 | 320 | $weight++; |
321 | 321 | $name = '_add_new_group'; |
322 | 322 | $form[$name] = array( |
323 | - 'label' => array( |
|
323 | + 'label' => array( |
|
324 | 324 | '#type' => 'textfield', |
325 | 325 | '#size' => 15, |
326 | 326 | '#description' => t('Label'), |
327 | - ), |
|
328 | - 'group_name' => array( |
|
327 | + ), |
|
328 | + 'group_name' => array( |
|
329 | 329 | '#type' => 'textfield', |
330 | 330 | // This field should stay LTR even for RTL languages. |
331 | 331 | '#field_prefix' => '<span dir="ltr">group_', |
@@ -336,40 +336,40 @@ discard block |
||
336 | 336 | // prefix which is 6 characters long. |
337 | 337 | '#maxlength' => 26, |
338 | 338 | '#description' => t('Group name (a-z, 0-9, _)'), |
339 | - ), |
|
340 | - 'group_option' => array( |
|
339 | + ), |
|
340 | + 'group_option' => array( |
|
341 | 341 | '#type' => 'hidden', |
342 | 342 | '#value' => '', |
343 | - ), |
|
344 | - 'group_type' => array( |
|
343 | + ), |
|
344 | + 'group_type' => array( |
|
345 | 345 | '#type' => 'hidden', |
346 | 346 | '#value' => 'standard', |
347 | - ), |
|
348 | - 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
349 | - 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
350 | - 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
351 | - '#root' => TRUE, |
|
352 | - '#add_new' => TRUE, |
|
353 | - '#row_type' => 'add_new_group', |
|
347 | + ), |
|
348 | + 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
|
349 | + 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
|
350 | + 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
|
351 | + '#root' => TRUE, |
|
352 | + '#add_new' => TRUE, |
|
353 | + '#row_type' => 'add_new_group', |
|
354 | 354 | ); |
355 | 355 | if (count($group_types) > 1) { |
356 | - $form[$name]['group_type'] = array( |
|
356 | + $form[$name]['group_type'] = array( |
|
357 | 357 | '#type' => 'select', |
358 | 358 | '#description' => t('Type of group.'), |
359 | 359 | '#options' => $group_types, |
360 | 360 | '#default_value' => 'standard', |
361 | - ); |
|
361 | + ); |
|
362 | 362 | } |
363 | 363 | $form['#group_rows'][] = $name; |
364 | - } |
|
364 | + } |
|
365 | 365 | |
366 | - $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); |
|
367 | - return $form; |
|
366 | + $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); |
|
367 | + return $form; |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | function content_field_overview_form_validate($form, &$form_state) { |
371 | - _content_field_overview_form_validate_add_new($form, $form_state); |
|
372 | - _content_field_overview_form_validate_add_existing($form, $form_state); |
|
371 | + _content_field_overview_form_validate_add_new($form, $form_state); |
|
372 | + _content_field_overview_form_validate_add_existing($form, $form_state); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -378,71 +378,71 @@ discard block |
||
378 | 378 | * Validate the 'add new field' row. |
379 | 379 | */ |
380 | 380 | function _content_field_overview_form_validate_add_new($form, &$form_state) { |
381 | - $field = $form_state['values']['_add_new_field']; |
|
381 | + $field = $form_state['values']['_add_new_field']; |
|
382 | 382 | |
383 | - // Validate if any information was provided in the 'add new field' row. |
|
384 | - if (array_filter(array($field['label'], $field['field_name'], $field['type'], $field['widget_type']))) { |
|
383 | + // Validate if any information was provided in the 'add new field' row. |
|
384 | + if (array_filter(array($field['label'], $field['field_name'], $field['type'], $field['widget_type']))) { |
|
385 | 385 | // No label. |
386 | 386 | if (!$field['label']) { |
387 | - form_set_error('_add_new_field][label', t('Add new field: you need to provide a label.')); |
|
387 | + form_set_error('_add_new_field][label', t('Add new field: you need to provide a label.')); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | // No field name. |
391 | 391 | if (!$field['field_name']) { |
392 | - form_set_error('_add_new_field][field_name', t('Add new field: you need to provide a field name.')); |
|
392 | + form_set_error('_add_new_field][field_name', t('Add new field: you need to provide a field name.')); |
|
393 | 393 | } |
394 | 394 | // Field name validation. |
395 | 395 | else { |
396 | - $field_name = $field['field_name']; |
|
396 | + $field_name = $field['field_name']; |
|
397 | 397 | |
398 | - // Add the 'field_' prefix. |
|
399 | - if (substr($field_name, 0, 6) != 'field_') { |
|
398 | + // Add the 'field_' prefix. |
|
399 | + if (substr($field_name, 0, 6) != 'field_') { |
|
400 | 400 | $field_name = 'field_'. $field_name; |
401 | 401 | form_set_value($form['_add_new_field']['field_name'], $field_name, $form_state); |
402 | - } |
|
402 | + } |
|
403 | 403 | |
404 | - // Invalid field name. |
|
405 | - if (!preg_match('!^field_[a-z0-9_]+$!', $field_name)) { |
|
404 | + // Invalid field name. |
|
405 | + if (!preg_match('!^field_[a-z0-9_]+$!', $field_name)) { |
|
406 | 406 | form_set_error('_add_new_field][field_name', t('Add new field: the field name %field_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%field_name' => $field_name))); |
407 | - } |
|
408 | - if (strlen($field_name) > 32) { |
|
407 | + } |
|
408 | + if (strlen($field_name) > 32) { |
|
409 | 409 | form_set_error('_add_new_field][field_name', t('Add new field: the field name %field_name is too long. The name is limited to 32 characters, including the \'field_\' prefix.', array('%field_name' => $field_name))); |
410 | - } |
|
411 | - // A field named 'field_instance' would cause a tablename clash with {content_field_instance} |
|
412 | - if ($field_name == 'field_instance') { |
|
410 | + } |
|
411 | + // A field named 'field_instance' would cause a tablename clash with {content_field_instance} |
|
412 | + if ($field_name == 'field_instance') { |
|
413 | 413 | form_set_error('_add_new_field][field_name', t("Add new field: the name 'field_instance' is a reserved name.")); |
414 | - } |
|
415 | - |
|
416 | - // Field name already exists. |
|
417 | - // We need to check inactive fields as well, so we can't use content_fields(). |
|
418 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
419 | - $fields = content_field_instance_read(array(), TRUE); |
|
420 | - $used = FALSE; |
|
421 | - foreach ($fields as $existing_field) { |
|
414 | + } |
|
415 | + |
|
416 | + // Field name already exists. |
|
417 | + // We need to check inactive fields as well, so we can't use content_fields(). |
|
418 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
419 | + $fields = content_field_instance_read(array(), TRUE); |
|
420 | + $used = FALSE; |
|
421 | + foreach ($fields as $existing_field) { |
|
422 | 422 | $used |= ($existing_field['field_name'] == $field_name); |
423 | - } |
|
424 | - if ($used) { |
|
423 | + } |
|
424 | + if ($used) { |
|
425 | 425 | form_set_error('_add_new_field][field_name', t('Add new field: the field name %field_name already exists.', array('%field_name' => $field_name))); |
426 | - } |
|
426 | + } |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | // No field type. |
430 | 430 | if (!$field['type']) { |
431 | - form_set_error('_add_new_field][type', t('Add new field: you need to select a field type.')); |
|
431 | + form_set_error('_add_new_field][type', t('Add new field: you need to select a field type.')); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | // No widget type. |
435 | 435 | if (!$field['widget_type']) { |
436 | - form_set_error('_add_new_field][widget_type', t('Add new field: you need to select a widget.')); |
|
436 | + form_set_error('_add_new_field][widget_type', t('Add new field: you need to select a widget.')); |
|
437 | 437 | } |
438 | 438 | // Wrong widget type. |
439 | 439 | elseif ($field['type']) { |
440 | - $widget_types = content_widget_type_options($field['type']); |
|
441 | - if (!isset($widget_types[$field['widget_type']])) { |
|
440 | + $widget_types = content_widget_type_options($field['type']); |
|
441 | + if (!isset($widget_types[$field['widget_type']])) { |
|
442 | 442 | form_set_error('_add_new_field][widget_type', t('Add new field: invalid widget.')); |
443 | - } |
|
443 | + } |
|
444 | + } |
|
444 | 445 | } |
445 | - } |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | /** |
@@ -451,112 +451,112 @@ discard block |
||
451 | 451 | * Validate the 'add existing field' row. |
452 | 452 | */ |
453 | 453 | function _content_field_overview_form_validate_add_existing($form, &$form_state) { |
454 | - // The form element might be absent if no existing fields can be added to |
|
455 | - // this content type |
|
456 | - if (isset($form_state['values']['_add_existing_field'])) { |
|
454 | + // The form element might be absent if no existing fields can be added to |
|
455 | + // this content type |
|
456 | + if (isset($form_state['values']['_add_existing_field'])) { |
|
457 | 457 | $field = $form_state['values']['_add_existing_field']; |
458 | 458 | |
459 | 459 | // Validate if any information was provided in the 'add existing field' row. |
460 | 460 | if (array_filter(array($field['label'], $field['field_name'], $field['widget_type']))) { |
461 | - // No label. |
|
462 | - if (!$field['label']) { |
|
461 | + // No label. |
|
462 | + if (!$field['label']) { |
|
463 | 463 | form_set_error('_add_existing_field][label', t('Add existing field: you need to provide a label.')); |
464 | - } |
|
464 | + } |
|
465 | 465 | |
466 | - // No existing field. |
|
467 | - if (!$field['field_name']) { |
|
466 | + // No existing field. |
|
467 | + if (!$field['field_name']) { |
|
468 | 468 | form_set_error('_add_existing_field][field_name', t('Add existing field: you need to select a field.')); |
469 | - } |
|
469 | + } |
|
470 | 470 | |
471 | - // No widget type. |
|
472 | - if (!$field['widget_type']) { |
|
471 | + // No widget type. |
|
472 | + if (!$field['widget_type']) { |
|
473 | 473 | form_set_error('_add_existing_field][widget_type', t('Add existing field: you need to select a widget.')); |
474 | - } |
|
475 | - // Wrong widget type. |
|
476 | - elseif ($field['field_name'] && ($existing_field = content_fields($field['field_name']))) { |
|
474 | + } |
|
475 | + // Wrong widget type. |
|
476 | + elseif ($field['field_name'] && ($existing_field = content_fields($field['field_name']))) { |
|
477 | 477 | $widget_types = content_widget_type_options($existing_field['type']); |
478 | 478 | if (!isset($widget_types[$field['widget_type']])) { |
479 | - form_set_error('_add_existing_field][widget_type', t('Add existing field: invalid widget.')); |
|
479 | + form_set_error('_add_existing_field][widget_type', t('Add existing field: invalid widget.')); |
|
480 | + } |
|
480 | 481 | } |
481 | - } |
|
482 | 482 | } |
483 | - } |
|
483 | + } |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | function content_field_overview_form_submit($form, &$form_state) { |
487 | - $form_values = $form_state['values']; |
|
487 | + $form_values = $form_state['values']; |
|
488 | 488 | |
489 | - $type_name = $form['#type_name']; |
|
490 | - $type = content_types($type_name); |
|
489 | + $type_name = $form['#type_name']; |
|
490 | + $type = content_types($type_name); |
|
491 | 491 | |
492 | - // Update field weights. |
|
493 | - $extra = array(); |
|
494 | - foreach ($form_values as $key => $values) { |
|
492 | + // Update field weights. |
|
493 | + $extra = array(); |
|
494 | + foreach ($form_values as $key => $values) { |
|
495 | 495 | // Groups are handled in fieldgroup_content_overview_form_submit(). |
496 | 496 | if (in_array($key, $form['#fields'])) { |
497 | - db_query("UPDATE {". content_instance_tablename() ."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", |
|
497 | + db_query("UPDATE {". content_instance_tablename() ."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", |
|
498 | 498 | $values['weight'], $type_name, $key); |
499 | 499 | } |
500 | 500 | elseif (in_array($key, $form['#extra'])) { |
501 | - $extra[$key] = $values['weight']; |
|
501 | + $extra[$key] = $values['weight']; |
|
502 | + } |
|
502 | 503 | } |
503 | - } |
|
504 | 504 | |
505 | - if ($extra) { |
|
505 | + if ($extra) { |
|
506 | 506 | variable_set('content_extra_weights_'. $type_name, $extra); |
507 | - } |
|
508 | - else { |
|
507 | + } |
|
508 | + else { |
|
509 | 509 | variable_del('content_extra_weights_'. $type_name); |
510 | - } |
|
510 | + } |
|
511 | 511 | |
512 | - content_clear_type_cache(); |
|
512 | + content_clear_type_cache(); |
|
513 | 513 | |
514 | - $destinations = array(); |
|
514 | + $destinations = array(); |
|
515 | 515 | |
516 | - // Create new field. |
|
517 | - if (!empty($form_values['_add_new_field']['field_name'])) { |
|
516 | + // Create new field. |
|
517 | + if (!empty($form_values['_add_new_field']['field_name'])) { |
|
518 | 518 | $field = $form_values['_add_new_field']; |
519 | 519 | $field['type_name'] = $type_name; |
520 | 520 | |
521 | 521 | module_load_include('inc', 'content', 'includes/content.crud'); |
522 | 522 | if (content_field_instance_create($field)) { |
523 | - // Store new field information for fieldgroup submit handler. |
|
524 | - $form_state['fields_added']['_add_new_field'] = $field['field_name']; |
|
525 | - $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
|
523 | + // Store new field information for fieldgroup submit handler. |
|
524 | + $form_state['fields_added']['_add_new_field'] = $field['field_name']; |
|
525 | + $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
|
526 | 526 | } |
527 | 527 | else { |
528 | - drupal_set_message(t('There was a problem creating field %label.', array( |
|
528 | + drupal_set_message(t('There was a problem creating field %label.', array( |
|
529 | 529 | '%label' => $field['label']))); |
530 | 530 | } |
531 | - } |
|
531 | + } |
|
532 | 532 | |
533 | - // Add existing field. |
|
534 | - if (!empty($form_values['_add_existing_field']['field_name'])) { |
|
533 | + // Add existing field. |
|
534 | + if (!empty($form_values['_add_existing_field']['field_name'])) { |
|
535 | 535 | $field = $form_values['_add_existing_field']; |
536 | 536 | $field['type_name'] = $type_name; |
537 | 537 | $existing_field = content_fields($field['field_name']); |
538 | 538 | |
539 | 539 | if ($existing_field['locked']) { |
540 | - drupal_set_message(t('The field %label cannot be added to a content type because it is locked.', array('%label' => $field['field_name']))); |
|
540 | + drupal_set_message(t('The field %label cannot be added to a content type because it is locked.', array('%label' => $field['field_name']))); |
|
541 | 541 | } |
542 | 542 | else { |
543 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
544 | - if (content_field_instance_create($field)) { |
|
543 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
544 | + if (content_field_instance_create($field)) { |
|
545 | 545 | // Store new field information for fieldgroup submit handler. |
546 | 546 | $form_state['fields_added']['_add_existing_field'] = $field['field_name']; |
547 | 547 | $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
548 | - } |
|
549 | - else { |
|
548 | + } |
|
549 | + else { |
|
550 | 550 | drupal_set_message(t('There was a problem adding field %label.', array('%label' => $field['field_name']))); |
551 | - } |
|
551 | + } |
|
552 | + } |
|
552 | 553 | } |
553 | - } |
|
554 | 554 | |
555 | - if ($destinations) { |
|
555 | + if ($destinations) { |
|
556 | 556 | $destinations[] = urldecode(substr(drupal_get_destination(), 12)); |
557 | 557 | unset($_REQUEST['destination']); |
558 | 558 | $form_state['redirect'] = content_get_destinations($destinations); |
559 | - } |
|
559 | + } |
|
560 | 560 | |
561 | 561 | } |
562 | 562 | |
@@ -567,173 +567,173 @@ discard block |
||
567 | 567 | * and how the field labels should be rendered. |
568 | 568 | */ |
569 | 569 | function content_display_overview_form(&$form_state, $type_name, $contexts_selector = 'basic') { |
570 | - content_inactive_message($type_name); |
|
570 | + content_inactive_message($type_name); |
|
571 | 571 | |
572 | - // Gather type information. |
|
573 | - $type = content_types($type_name); |
|
574 | - $field_types = _content_field_types(); |
|
575 | - $fields = $type['fields']; |
|
572 | + // Gather type information. |
|
573 | + $type = content_types($type_name); |
|
574 | + $field_types = _content_field_types(); |
|
575 | + $fields = $type['fields']; |
|
576 | 576 | |
577 | - $groups = array(); |
|
578 | - if (module_exists('fieldgroup')) { |
|
577 | + $groups = array(); |
|
578 | + if (module_exists('fieldgroup')) { |
|
579 | 579 | $groups = fieldgroup_groups($type['type']); |
580 | - } |
|
581 | - $contexts = content_build_modes($contexts_selector); |
|
580 | + } |
|
581 | + $contexts = content_build_modes($contexts_selector); |
|
582 | 582 | |
583 | - $form = array( |
|
583 | + $form = array( |
|
584 | 584 | '#tree' => TRUE, |
585 | 585 | '#type_name' => $type['type'], |
586 | 586 | '#fields' => array_keys($fields), |
587 | 587 | '#groups' => array_keys($groups), |
588 | 588 | '#contexts' => $contexts_selector, |
589 | - ); |
|
589 | + ); |
|
590 | 590 | |
591 | - if (empty($fields)) { |
|
591 | + if (empty($fields)) { |
|
592 | 592 | drupal_set_message(t('There are no fields configured for this content type. You can add new fields on the <a href="@link">Manage fields</a> page.', array( |
593 | - '@link' => url('admin/content/node-type/'. $type['url_str'] .'/fields'))), 'warning'); |
|
593 | + '@link' => url('admin/content/node-type/'. $type['url_str'] .'/fields'))), 'warning'); |
|
594 | 594 | return $form; |
595 | - } |
|
595 | + } |
|
596 | 596 | |
597 | - // Fields. |
|
598 | - $label_options = array( |
|
597 | + // Fields. |
|
598 | + $label_options = array( |
|
599 | 599 | 'above' => t('Above'), |
600 | 600 | 'inline' => t('Inline'), |
601 | 601 | 'hidden' => t('<Hidden>'), |
602 | - ); |
|
603 | - foreach ($fields as $name => $field) { |
|
602 | + ); |
|
603 | + foreach ($fields as $name => $field) { |
|
604 | 604 | $field_type = $field_types[$field['type']]; |
605 | 605 | $defaults = $field['display_settings']; |
606 | 606 | $weight = $field['widget']['weight']; |
607 | 607 | |
608 | 608 | $form[$name] = array( |
609 | - 'human_name' => array('#value' => check_plain($field['widget']['label'])), |
|
610 | - 'weight' => array('#type' => 'value', '#value' => $weight), |
|
611 | - 'parent' => array('#type' => 'value', '#value' => ''), |
|
609 | + 'human_name' => array('#value' => check_plain($field['widget']['label'])), |
|
610 | + 'weight' => array('#type' => 'value', '#value' => $weight), |
|
611 | + 'parent' => array('#type' => 'value', '#value' => ''), |
|
612 | 612 | ); |
613 | 613 | |
614 | 614 | // Label |
615 | 615 | if ($contexts_selector == 'basic') { |
616 | - $form[$name]['label']['format'] = array( |
|
616 | + $form[$name]['label']['format'] = array( |
|
617 | 617 | '#type' => 'select', |
618 | 618 | '#options' => $label_options, |
619 | 619 | '#default_value' => isset($defaults['label']['format']) ? $defaults['label']['format'] : 'above', |
620 | - ); |
|
620 | + ); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | // Formatters. |
624 | 624 | $options = array(); |
625 | 625 | foreach ($field_type['formatters'] as $formatter_name => $formatter_info) { |
626 | - $options[$formatter_name] = $formatter_info['label']; |
|
626 | + $options[$formatter_name] = $formatter_info['label']; |
|
627 | 627 | } |
628 | 628 | $options['hidden'] = t('<Hidden>'); |
629 | 629 | |
630 | 630 | foreach ($contexts as $key => $value) { |
631 | - $form[$name][$key]['format'] = array( |
|
631 | + $form[$name][$key]['format'] = array( |
|
632 | 632 | '#type' => 'select', |
633 | 633 | '#options' => $options, |
634 | 634 | '#default_value' => isset($defaults[$key]['format']) ? $defaults[$key]['format'] : 'default', |
635 | - ); |
|
636 | - // exclude from $content |
|
637 | - $form[$name][$key]['exclude'] = array( |
|
635 | + ); |
|
636 | + // exclude from $content |
|
637 | + $form[$name][$key]['exclude'] = array( |
|
638 | 638 | '#type' => 'checkbox', |
639 | 639 | '#options' => array(0 => t('Include'), 1 => t('Exclude')), |
640 | 640 | '#default_value' => isset($defaults[$key]['exclude']) ? $defaults[$key]['exclude'] : 0, |
641 | - ); |
|
641 | + ); |
|
642 | + } |
|
642 | 643 | } |
643 | - } |
|
644 | 644 | |
645 | - // Groups. |
|
646 | - $label_options = array( |
|
645 | + // Groups. |
|
646 | + $label_options = array( |
|
647 | 647 | 'above' => t('Above'), |
648 | 648 | 'hidden' => t('<Hidden>'), |
649 | - ); |
|
650 | - $options = array( |
|
649 | + ); |
|
650 | + $options = array( |
|
651 | 651 | 'no_style' => t('no styling'), |
652 | 652 | 'simple' => t('simple'), |
653 | 653 | 'fieldset' => t('fieldset'), |
654 | 654 | 'fieldset_collapsible' => t('fieldset - collapsible'), |
655 | 655 | 'fieldset_collapsed' => t('fieldset - collapsed'), |
656 | 656 | 'hidden' => t('<Hidden>'), |
657 | - ); |
|
658 | - foreach ($groups as $name => $group) { |
|
657 | + ); |
|
658 | + foreach ($groups as $name => $group) { |
|
659 | 659 | $defaults = $group['settings']['display']; |
660 | 660 | $weight = $group['weight']; |
661 | 661 | |
662 | 662 | $form[$name] = array( |
663 | - 'human_name' => array('#value' => check_plain($group['label'])), |
|
664 | - 'weight' => array('#type' => 'value', '#value' => $weight), |
|
663 | + 'human_name' => array('#value' => check_plain($group['label'])), |
|
664 | + 'weight' => array('#type' => 'value', '#value' => $weight), |
|
665 | 665 | ); |
666 | 666 | if ($contexts_selector == 'basic') { |
667 | - $form[$name]['label'] = array( |
|
667 | + $form[$name]['label'] = array( |
|
668 | 668 | '#type' => 'select', |
669 | 669 | '#options' => $label_options, |
670 | 670 | '#default_value' => isset($defaults['label']) ? $defaults['label'] : 'above', |
671 | - ); |
|
671 | + ); |
|
672 | 672 | } |
673 | 673 | foreach ($contexts as $key => $title) { |
674 | - $form[$name][$key]['format'] = array( |
|
674 | + $form[$name][$key]['format'] = array( |
|
675 | 675 | '#type' => 'select', |
676 | 676 | '#options' => $options, |
677 | 677 | '#default_value' => isset($defaults[$key]['format']) ? $defaults[$key]['format'] : 'fieldset', |
678 | - ); |
|
679 | - // exclude in $content |
|
680 | - $form[$name][$key]['exclude'] = array( |
|
678 | + ); |
|
679 | + // exclude in $content |
|
680 | + $form[$name][$key]['exclude'] = array( |
|
681 | 681 | '#type' => 'checkbox', |
682 | 682 | '#options' => array(0 => t('Include'), 1 => t('Exclude')), |
683 | 683 | '#default_value' => isset($defaults[$key]['exclude']) ? $defaults[$key]['exclude'] : 0, |
684 | - ); |
|
684 | + ); |
|
685 | 685 | } |
686 | 686 | foreach ($group['fields'] as $field_name => $field) { |
687 | - $form[$field_name]['parent']['#value'] = $name; |
|
687 | + $form[$field_name]['parent']['#value'] = $name; |
|
688 | + } |
|
688 | 689 | } |
689 | - } |
|
690 | 690 | |
691 | - $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); |
|
692 | - return $form; |
|
691 | + $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); |
|
692 | + return $form; |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | /** |
696 | 696 | * Submit handler for the display overview form. |
697 | 697 | */ |
698 | 698 | function content_display_overview_form_submit($form, &$form_state) { |
699 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
700 | - $form_values = $form_state['values']; |
|
701 | - foreach ($form_values as $key => $values) { |
|
699 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
700 | + $form_values = $form_state['values']; |
|
701 | + foreach ($form_values as $key => $values) { |
|
702 | 702 | // Groups are handled in fieldgroup_display_overview_form_submit(). |
703 | 703 | if (in_array($key, $form['#fields'])) { |
704 | - $field = content_fields($key, $form['#type_name']); |
|
705 | - // We have some numeric keys here, so we can't use array_merge. |
|
706 | - $field['display_settings'] = $values + $field['display_settings']; |
|
707 | - content_field_instance_update($field, FALSE); |
|
704 | + $field = content_fields($key, $form['#type_name']); |
|
705 | + // We have some numeric keys here, so we can't use array_merge. |
|
706 | + $field['display_settings'] = $values + $field['display_settings']; |
|
707 | + content_field_instance_update($field, FALSE); |
|
708 | + } |
|
708 | 709 | } |
709 | - } |
|
710 | 710 | |
711 | - // Clear caches and rebuild menu. |
|
712 | - content_clear_type_cache(TRUE); |
|
713 | - menu_rebuild(); |
|
711 | + // Clear caches and rebuild menu. |
|
712 | + content_clear_type_cache(TRUE); |
|
713 | + menu_rebuild(); |
|
714 | 714 | |
715 | - drupal_set_message(t('Your settings have been saved.')); |
|
715 | + drupal_set_message(t('Your settings have been saved.')); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
719 | 719 | * Return an array of field_type options. |
720 | 720 | */ |
721 | 721 | function content_field_type_options() { |
722 | - static $options; |
|
722 | + static $options; |
|
723 | 723 | |
724 | - if (!isset($options)) { |
|
724 | + if (!isset($options)) { |
|
725 | 725 | $options = array(); |
726 | 726 | $field_types = _content_field_types(); |
727 | 727 | $field_type_options = array(); |
728 | 728 | foreach ($field_types as $field_type_name => $field_type) { |
729 | - // skip field types which have no widget types. |
|
730 | - if (content_widget_type_options($field_type_name)) { |
|
729 | + // skip field types which have no widget types. |
|
730 | + if (content_widget_type_options($field_type_name)) { |
|
731 | 731 | $options[$field_type_name] = t($field_type['label']); |
732 | - } |
|
732 | + } |
|
733 | 733 | } |
734 | 734 | asort($options); |
735 | - } |
|
736 | - return $options; |
|
735 | + } |
|
736 | + return $options; |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
@@ -743,320 +743,320 @@ discard block |
||
743 | 743 | * all widget types, keyed by field type human name |
744 | 744 | */ |
745 | 745 | function content_widget_type_options($field_type = NULL, $by_label = FALSE) { |
746 | - static $options; |
|
746 | + static $options; |
|
747 | 747 | |
748 | - if (!isset($options)) { |
|
748 | + if (!isset($options)) { |
|
749 | 749 | $options = array(); |
750 | 750 | foreach (_content_widget_types() as $widget_type_name => $widget_type) { |
751 | - foreach ($widget_type['field types'] as $widget_field_type) { |
|
751 | + foreach ($widget_type['field types'] as $widget_field_type) { |
|
752 | 752 | $options[$widget_field_type][$widget_type_name] = t($widget_type['label']); |
753 | - } |
|
753 | + } |
|
754 | + } |
|
754 | 755 | } |
755 | - } |
|
756 | 756 | |
757 | - if ($field_type) { |
|
757 | + if ($field_type) { |
|
758 | 758 | return !empty($options[$field_type]) ? $options[$field_type] : array(); |
759 | - } |
|
760 | - elseif ($by_label) { |
|
759 | + } |
|
760 | + elseif ($by_label) { |
|
761 | 761 | $field_types = _content_field_types(); |
762 | 762 | $options_by_label = array(); |
763 | 763 | foreach ($options as $field_type => $widgets) { |
764 | - $options_by_label[t($field_types[$field_type]['label'])] = $widgets; |
|
764 | + $options_by_label[t($field_types[$field_type]['label'])] = $widgets; |
|
765 | 765 | } |
766 | 766 | return $options_by_label; |
767 | - } |
|
768 | - else { |
|
767 | + } |
|
768 | + else { |
|
769 | 769 | return $options; |
770 | - } |
|
770 | + } |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
774 | 774 | * Return an array of existing field to be added to a node type. |
775 | 775 | */ |
776 | 776 | function content_existing_field_options($type_name) { |
777 | - $type = content_types($type_name); |
|
778 | - $fields = content_fields(); |
|
779 | - $field_types = _content_field_types(); |
|
777 | + $type = content_types($type_name); |
|
778 | + $fields = content_fields(); |
|
779 | + $field_types = _content_field_types(); |
|
780 | 780 | |
781 | - $options = array(); |
|
782 | - foreach ($fields as $field) { |
|
781 | + $options = array(); |
|
782 | + foreach ($fields as $field) { |
|
783 | 783 | if (!isset($type['fields'][$field['field_name']]) && !$field['locked']) { |
784 | - $field_type = $field_types[$field['type']]; |
|
785 | - $text = t('@type: @field (@label)', array('@type' => t($field_type['label']), '@label' => t($field['widget']['label']), '@field' => $field['field_name'])); |
|
786 | - $options[$field['field_name']] = (drupal_strlen($text) > 80) ? truncate_utf8($text, 77) . '...' : $text; |
|
784 | + $field_type = $field_types[$field['type']]; |
|
785 | + $text = t('@type: @field (@label)', array('@type' => t($field_type['label']), '@label' => t($field['widget']['label']), '@field' => $field['field_name'])); |
|
786 | + $options[$field['field_name']] = (drupal_strlen($text) > 80) ? truncate_utf8($text, 77) . '...' : $text; |
|
787 | 787 | } |
788 | - } |
|
789 | - // Sort the list by type, then by field name, then by label. |
|
790 | - asort($options); |
|
788 | + } |
|
789 | + // Sort the list by type, then by field name, then by label. |
|
790 | + asort($options); |
|
791 | 791 | |
792 | - return $options; |
|
792 | + return $options; |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
796 | 796 | * A form element for selecting field, widget, and label. |
797 | 797 | */ |
798 | 798 | function content_field_basic_form(&$form_state, $form_values) { |
799 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
799 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
800 | 800 | |
801 | - $type_name = $form_values['type_name']; |
|
802 | - $type = content_types($form_values['type_name']); |
|
803 | - $field_name = $form_values['field_name']; |
|
804 | - $field_type = $form_values['type']; |
|
805 | - $label = $form_values['label']; |
|
801 | + $type_name = $form_values['type_name']; |
|
802 | + $type = content_types($form_values['type_name']); |
|
803 | + $field_name = $form_values['field_name']; |
|
804 | + $field_type = $form_values['type']; |
|
805 | + $label = $form_values['label']; |
|
806 | 806 | |
807 | - $form = array(); |
|
807 | + $form = array(); |
|
808 | 808 | |
809 | - $form['basic'] = array( |
|
809 | + $form['basic'] = array( |
|
810 | 810 | '#type' => 'fieldset', |
811 | 811 | '#title' => t('Edit basic information'), |
812 | - ); |
|
813 | - $form['basic']['field_name'] = array( |
|
812 | + ); |
|
813 | + $form['basic']['field_name'] = array( |
|
814 | 814 | '#title' => t('Field name'), |
815 | 815 | '#type' => 'textfield', |
816 | 816 | '#value' => $field_name, |
817 | 817 | '#description' => t("The machine-readable name of the field. This name cannot be changed."), |
818 | 818 | '#disabled' => TRUE, |
819 | - ); |
|
820 | - $form['basic']['label'] = array( |
|
819 | + ); |
|
820 | + $form['basic']['label'] = array( |
|
821 | 821 | '#type' => 'textfield', |
822 | 822 | '#title' => t('Label'), |
823 | 823 | '#default_value' => $label, |
824 | 824 | '#required' => TRUE, |
825 | 825 | '#description' => t('A human-readable name to be used as the label for this field in the %type content type.', array('%type' => $type['name'])), |
826 | - ); |
|
827 | - $form['basic']['type'] = array( |
|
826 | + ); |
|
827 | + $form['basic']['type'] = array( |
|
828 | 828 | '#type' => 'select', |
829 | 829 | '#title' => t('Field type'), |
830 | 830 | '#options' => content_field_type_options(), |
831 | 831 | '#default_value' => $field_type, |
832 | 832 | '#description' => t('The type of data you would like to store in the database with this field. This option cannot be changed.'), |
833 | 833 | '#disabled' => TRUE, |
834 | - ); |
|
835 | - $form['basic']['widget_type'] = array( |
|
834 | + ); |
|
835 | + $form['basic']['widget_type'] = array( |
|
836 | 836 | '#type' => 'select', |
837 | 837 | '#title' => t('Widget type'), |
838 | 838 | '#required' => TRUE, |
839 | 839 | '#options' => content_widget_type_options($field_type), |
840 | 840 | '#default_value' => $form_values['widget_type'], |
841 | 841 | '#description' => t('The type of form element you would like to present to the user when creating this field in the %type content type.', array('%type' => $type['name'])), |
842 | - ); |
|
842 | + ); |
|
843 | 843 | |
844 | - $form['type_name'] = array( |
|
844 | + $form['type_name'] = array( |
|
845 | 845 | '#type' => 'value', |
846 | 846 | '#value' => $type_name, |
847 | - ); |
|
847 | + ); |
|
848 | 848 | |
849 | - $form['submit'] = array( |
|
849 | + $form['submit'] = array( |
|
850 | 850 | '#type' => 'submit', |
851 | 851 | '#value' => t('Continue'), |
852 | - ); |
|
852 | + ); |
|
853 | 853 | |
854 | - $form['#validate'] = array(); |
|
855 | - $form['#submit'] = array('content_field_basic_form_submit'); |
|
854 | + $form['#validate'] = array(); |
|
855 | + $form['#submit'] = array('content_field_basic_form_submit'); |
|
856 | 856 | |
857 | - return $form; |
|
857 | + return $form; |
|
858 | 858 | } |
859 | 859 | |
860 | 860 | /** |
861 | 861 | * Create a new field for a content type. |
862 | 862 | */ |
863 | 863 | function content_field_basic_form_submit($form, &$form_state) { |
864 | - $form_values = $form_state['values']; |
|
864 | + $form_values = $form_state['values']; |
|
865 | 865 | |
866 | - $label = $form_values['label']; |
|
866 | + $label = $form_values['label']; |
|
867 | 867 | |
868 | - // Set the right module information |
|
869 | - $field_types = _content_field_types(); |
|
870 | - $widget_types = _content_widget_types(); |
|
871 | - $form_values['module'] = $field_types[$form_values['type']]['module']; |
|
872 | - $form_values['widget_module'] = $widget_types[$form_values['widget_type']]['module']; |
|
868 | + // Set the right module information |
|
869 | + $field_types = _content_field_types(); |
|
870 | + $widget_types = _content_widget_types(); |
|
871 | + $form_values['module'] = $field_types[$form_values['type']]['module']; |
|
872 | + $form_values['widget_module'] = $widget_types[$form_values['widget_type']]['module']; |
|
873 | 873 | |
874 | - // Make sure we retain previous values and only over-write changed values. |
|
875 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
876 | - $instances = content_field_instance_read(array('field_name' => $form_values['field_name'], 'type_name' => $form_values['type_name'])); |
|
877 | - $field = array_merge(content_field_instance_collapse($instances[0]), $form_values); |
|
878 | - if (content_field_instance_update($field)) { |
|
874 | + // Make sure we retain previous values and only over-write changed values. |
|
875 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
876 | + $instances = content_field_instance_read(array('field_name' => $form_values['field_name'], 'type_name' => $form_values['type_name'])); |
|
877 | + $field = array_merge(content_field_instance_collapse($instances[0]), $form_values); |
|
878 | + if (content_field_instance_update($field)) { |
|
879 | 879 | drupal_set_message(t('Updated basic settings for field %label.', array( |
880 | - '%label' => $label))); |
|
881 | - } |
|
882 | - else { |
|
880 | + '%label' => $label))); |
|
881 | + } |
|
882 | + else { |
|
883 | 883 | drupal_set_message(t('There was a problem updating the basic settings for field %label.', array( |
884 | - '%label' => $label))); |
|
885 | - } |
|
884 | + '%label' => $label))); |
|
885 | + } |
|
886 | 886 | |
887 | - $type = content_types($form_values['type_name']); |
|
888 | - $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $form_values['field_name']; |
|
889 | - $form_state['rebuild'] = FALSE; |
|
887 | + $type = content_types($form_values['type_name']); |
|
888 | + $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $form_values['field_name']; |
|
889 | + $form_state['rebuild'] = FALSE; |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
893 | 893 | * Menu callback; present a form for removing a field from a content type. |
894 | 894 | */ |
895 | 895 | function content_field_remove_form(&$form_state, $type_name, $field_name) { |
896 | - $type = content_types($type_name); |
|
897 | - $field = $type['fields'][$field_name]; |
|
896 | + $type = content_types($type_name); |
|
897 | + $field = $type['fields'][$field_name]; |
|
898 | 898 | |
899 | - $form = array(); |
|
900 | - $form['type_name'] = array( |
|
899 | + $form = array(); |
|
900 | + $form['type_name'] = array( |
|
901 | 901 | '#type' => 'value', |
902 | 902 | '#value' => $type_name, |
903 | - ); |
|
904 | - $form['field_name'] = array( |
|
903 | + ); |
|
904 | + $form['field_name'] = array( |
|
905 | 905 | '#type' => 'value', |
906 | 906 | '#value' => $field_name, |
907 | - ); |
|
907 | + ); |
|
908 | 908 | |
909 | - $output = confirm_form($form, |
|
909 | + $output = confirm_form($form, |
|
910 | 910 | t('Are you sure you want to remove the field %field?', array('%field' => $field['widget']['label'])), |
911 | 911 | 'admin/content/node-type/'. $type['url_str'] .'/fields', |
912 | 912 | t('If you have any content left in this field, it will be lost. This action cannot be undone.'), |
913 | 913 | t('Remove'), t('Cancel'), |
914 | 914 | 'confirm' |
915 | - ); |
|
915 | + ); |
|
916 | 916 | |
917 | - if ($field['locked']) { |
|
917 | + if ($field['locked']) { |
|
918 | 918 | unset($output['actions']['submit']); |
919 | 919 | $output['description']['#value'] = t('This field is <strong>locked</strong> and cannot be removed.'); |
920 | - } |
|
920 | + } |
|
921 | 921 | |
922 | - return $output; |
|
922 | + return $output; |
|
923 | 923 | } |
924 | 924 | |
925 | 925 | /** |
926 | 926 | * Remove a field from a content type. |
927 | 927 | */ |
928 | 928 | function content_field_remove_form_submit($form, &$form_state) { |
929 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
930 | - $form_values = $form_state['values']; |
|
929 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
930 | + $form_values = $form_state['values']; |
|
931 | 931 | |
932 | - $type = content_types($form_values['type_name']); |
|
933 | - $field = $type['fields'][$form_values['field_name']]; |
|
934 | - if ($field['locked']) { |
|
932 | + $type = content_types($form_values['type_name']); |
|
933 | + $field = $type['fields'][$form_values['field_name']]; |
|
934 | + if ($field['locked']) { |
|
935 | 935 | return; |
936 | - } |
|
936 | + } |
|
937 | 937 | |
938 | - if ($type && $field && $form_values['confirm']) { |
|
938 | + if ($type && $field && $form_values['confirm']) { |
|
939 | 939 | if (content_field_instance_delete($form_values['field_name'], $form_values['type_name'])) { |
940 | - drupal_set_message(t('Removed field %field from %type.', array( |
|
940 | + drupal_set_message(t('Removed field %field from %type.', array( |
|
941 | 941 | '%field' => $field['widget']['label'], |
942 | 942 | '%type' => $type['name']))); |
943 | 943 | } |
944 | 944 | else { |
945 | - drupal_set_message(t('There was a problem deleting %field from %type.', array( |
|
945 | + drupal_set_message(t('There was a problem deleting %field from %type.', array( |
|
946 | 946 | '%field' => $field['widget']['label'], |
947 | 947 | '%type' => $type['name']))); |
948 | 948 | } |
949 | 949 | $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; |
950 | - } |
|
950 | + } |
|
951 | 951 | } |
952 | 952 | |
953 | 953 | /** |
954 | 954 | * Menu callback; presents the field editing page. |
955 | 955 | */ |
956 | 956 | function content_field_edit_form(&$form_state, $type_name, $field_name) { |
957 | - $output = ''; |
|
958 | - $type = content_types($type_name); |
|
959 | - $field = $type['fields'][$field_name]; |
|
957 | + $output = ''; |
|
958 | + $type = content_types($type_name); |
|
959 | + $field = $type['fields'][$field_name]; |
|
960 | 960 | |
961 | - if ($field['locked']) { |
|
961 | + if ($field['locked']) { |
|
962 | 962 | $output = array(); |
963 | 963 | $output['locked'] = array( |
964 | - '#value' => t('The field %field is locked and cannot be edited.', array('%field' => $field['widget']['label'])), |
|
964 | + '#value' => t('The field %field is locked and cannot be edited.', array('%field' => $field['widget']['label'])), |
|
965 | 965 | ); |
966 | 966 | return $output; |
967 | - } |
|
967 | + } |
|
968 | 968 | |
969 | - $field_types = _content_field_types(); |
|
970 | - $field_type = $field_types[$field['type']]; |
|
971 | - $widget_types = _content_widget_types(); |
|
972 | - $widget_type = $widget_types[$field['widget']['type']]; |
|
969 | + $field_types = _content_field_types(); |
|
970 | + $field_type = $field_types[$field['type']]; |
|
971 | + $widget_types = _content_widget_types(); |
|
972 | + $widget_type = $widget_types[$field['widget']['type']]; |
|
973 | 973 | |
974 | - $title = isset($field['widget']['label']) ? $field['widget']['label'] : $field['field_name']; |
|
975 | - drupal_set_title(check_plain($title)); |
|
974 | + $title = isset($field['widget']['label']) ? $field['widget']['label'] : $field['field_name']; |
|
975 | + drupal_set_title(check_plain($title)); |
|
976 | 976 | |
977 | - // See if we need to change the widget type or label. |
|
978 | - if (isset($form_state['change_basic'])) { |
|
977 | + // See if we need to change the widget type or label. |
|
978 | + if (isset($form_state['change_basic'])) { |
|
979 | 979 | module_load_include('inc', 'content', 'includes/content.crud'); |
980 | 980 | $field_values = content_field_instance_collapse($field); |
981 | 981 | return content_field_basic_form($form_state, $field_values); |
982 | - } |
|
982 | + } |
|
983 | 983 | |
984 | - $add_new_sequence = isset($_REQUEST['destinations']); |
|
984 | + $add_new_sequence = isset($_REQUEST['destinations']); |
|
985 | 985 | |
986 | - // Remove menu tabs when we are in an 'add new' sequence. |
|
987 | - if ($add_new_sequence) { |
|
986 | + // Remove menu tabs when we are in an 'add new' sequence. |
|
987 | + if ($add_new_sequence) { |
|
988 | 988 | menu_set_item(NULL, menu_get_item('node')); |
989 | - } |
|
989 | + } |
|
990 | 990 | |
991 | - $form = array(); |
|
992 | - $form['#field'] = $field; |
|
993 | - $form['#type'] = $type; |
|
991 | + $form = array(); |
|
992 | + $form['#field'] = $field; |
|
993 | + $form['#type'] = $type; |
|
994 | 994 | |
995 | - // Basic iformation : hide when we are in an 'add new' sequence. |
|
996 | - $form['basic'] = array( |
|
995 | + // Basic iformation : hide when we are in an 'add new' sequence. |
|
996 | + $form['basic'] = array( |
|
997 | 997 | '#type' => 'fieldset', |
998 | 998 | '#title' => t('%type basic information', array('%type' => $type['name'])), |
999 | 999 | '#access' => !$add_new_sequence, |
1000 | - ); |
|
1001 | - $form['basic']['label'] = array( |
|
1000 | + ); |
|
1001 | + $form['basic']['label'] = array( |
|
1002 | 1002 | '#type' => 'textfield', |
1003 | 1003 | '#title' => t('Label'), |
1004 | 1004 | '#value' => $field['widget']['label'], |
1005 | 1005 | '#disabled' => TRUE, |
1006 | - ); |
|
1007 | - $form['basic']['field_name'] = array( |
|
1006 | + ); |
|
1007 | + $form['basic']['field_name'] = array( |
|
1008 | 1008 | '#type' => 'hidden', |
1009 | 1009 | '#title' => t('Field name'), |
1010 | 1010 | '#value' => $field['field_name'], |
1011 | 1011 | '#disabled' => TRUE, |
1012 | - ); |
|
1013 | - $form['basic']['type'] = array( |
|
1012 | + ); |
|
1013 | + $form['basic']['type'] = array( |
|
1014 | 1014 | '#type' => 'hidden', |
1015 | 1015 | '#title' => t('Field type'), |
1016 | 1016 | '#value' => $field['type'], |
1017 | 1017 | '#disabled' => TRUE, |
1018 | - ); |
|
1019 | - $widget_options = content_widget_type_options($field['type']); |
|
1020 | - $form['basic']['widget_type'] = array( |
|
1018 | + ); |
|
1019 | + $widget_options = content_widget_type_options($field['type']); |
|
1020 | + $form['basic']['widget_type'] = array( |
|
1021 | 1021 | '#type' => 'select', |
1022 | 1022 | '#title' => t('Widget type'), |
1023 | 1023 | '#options' => $widget_options, |
1024 | 1024 | '#default_value' => $field['widget']['type'] ? $field['widget']['type'] : key($widget_options), |
1025 | 1025 | '#disabled' => TRUE, |
1026 | - ); |
|
1027 | - $form['basic']['change'] = array( |
|
1026 | + ); |
|
1027 | + $form['basic']['change'] = array( |
|
1028 | 1028 | '#type' => 'submit', |
1029 | 1029 | '#value' => t('Change basic information'), |
1030 | 1030 | '#submit' => array('content_field_edit_form_submit_update_basic'), |
1031 | - ); |
|
1031 | + ); |
|
1032 | 1032 | |
1033 | - $form['widget'] = array( |
|
1033 | + $form['widget'] = array( |
|
1034 | 1034 | '#type' => 'fieldset', |
1035 | 1035 | '#title' => t('%type settings', array('%type' => $type['name'])), |
1036 | 1036 | '#description' => t('These settings apply only to the %field field as it appears in the %type content type.', array( |
1037 | - '%field' => $field['widget']['label'], |
|
1038 | - '%type' => $type['name'])), |
|
1039 | - ); |
|
1040 | - $form['widget']['weight'] = array( |
|
1037 | + '%field' => $field['widget']['label'], |
|
1038 | + '%type' => $type['name'])), |
|
1039 | + ); |
|
1040 | + $form['widget']['weight'] = array( |
|
1041 | 1041 | '#type' => 'hidden', |
1042 | 1042 | '#default_value' => $field['widget']['weight'], |
1043 | - ); |
|
1043 | + ); |
|
1044 | 1044 | |
1045 | - $additions = (array) module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget']); |
|
1046 | - drupal_alter('widget_settings', $additions, 'form', $field['widget']); |
|
1047 | - $form['widget'] = array_merge($form['widget'], $additions); |
|
1045 | + $additions = (array) module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget']); |
|
1046 | + drupal_alter('widget_settings', $additions, 'form', $field['widget']); |
|
1047 | + $form['widget'] = array_merge($form['widget'], $additions); |
|
1048 | 1048 | |
1049 | - $form['widget']['description'] = array( |
|
1049 | + $form['widget']['description'] = array( |
|
1050 | 1050 | '#type' => 'textarea', |
1051 | 1051 | '#title' => t('Help text'), |
1052 | 1052 | '#default_value' => $field['widget']['description'], |
1053 | 1053 | '#rows' => 5, |
1054 | 1054 | '#description' => t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => _content_filter_xss_display_allowed_tags())), |
1055 | 1055 | '#required' => FALSE, |
1056 | - ); |
|
1056 | + ); |
|
1057 | 1057 | |
1058 | - // Add handling for default value if not provided by field. |
|
1059 | - if (content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) { |
|
1058 | + // Add handling for default value if not provided by field. |
|
1059 | + if (content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) { |
|
1060 | 1060 | |
1061 | 1061 | // Store the original default value for use in programmed forms. |
1062 | 1062 | // Set '#default_value' instead of '#value' so programmed values |
@@ -1064,22 +1064,22 @@ discard block |
||
1064 | 1064 | $default_value = isset($field['widget']['default_value']) ? $field['widget']['default_value'] : array(); |
1065 | 1065 | $default_value_php = isset($field['widget']['default_value_php']) ? $field['widget']['default_value_php'] : ''; |
1066 | 1066 | $form['widget']['default_value'] = array( |
1067 | - '#type' => 'value', |
|
1068 | - '#default_value' => $default_value, |
|
1067 | + '#type' => 'value', |
|
1068 | + '#default_value' => $default_value, |
|
1069 | 1069 | ); |
1070 | 1070 | $form['widget']['default_value_php'] = array( |
1071 | - '#type' => 'value', |
|
1072 | - '#default_value' => $default_value_php, |
|
1071 | + '#type' => 'value', |
|
1072 | + '#default_value' => $default_value_php, |
|
1073 | 1073 | ); |
1074 | 1074 | |
1075 | 1075 | // We can't tell at the time we build the form if this is a programmed |
1076 | 1076 | // form or not, so we always end up adding the default value widget |
1077 | 1077 | // even if we won't use it. |
1078 | 1078 | $form['widget']['default_value_fieldset'] = array( |
1079 | - '#type' => 'fieldset', |
|
1080 | - '#title' => t('Default value'), |
|
1081 | - '#collapsible' => TRUE, |
|
1082 | - '#collapsed' => TRUE, |
|
1079 | + '#type' => 'fieldset', |
|
1080 | + '#title' => t('Default value'), |
|
1081 | + '#collapsible' => TRUE, |
|
1082 | + '#collapsed' => TRUE, |
|
1083 | 1083 | ); |
1084 | 1084 | |
1085 | 1085 | // Default value widget. |
@@ -1097,264 +1097,264 @@ discard block |
||
1097 | 1097 | |
1098 | 1098 | // Advanced: PHP code. |
1099 | 1099 | $form['widget']['default_value_fieldset']['advanced_options'] = array( |
1100 | - '#type' => 'fieldset', |
|
1101 | - '#title' => t('PHP code'), |
|
1102 | - '#collapsible' => TRUE, |
|
1103 | - '#collapsed' => empty($field['widget']['default_value_php']), |
|
1100 | + '#type' => 'fieldset', |
|
1101 | + '#title' => t('PHP code'), |
|
1102 | + '#collapsible' => TRUE, |
|
1103 | + '#collapsed' => empty($field['widget']['default_value_php']), |
|
1104 | 1104 | ); |
1105 | 1105 | |
1106 | 1106 | if (user_access('Use PHP input for field settings (dangerous - grant with care)')) { |
1107 | - $db_info = content_database_info($field); |
|
1108 | - $columns = array_keys($db_info['columns']); |
|
1109 | - foreach ($columns as $key => $column) { |
|
1107 | + $db_info = content_database_info($field); |
|
1108 | + $columns = array_keys($db_info['columns']); |
|
1109 | + foreach ($columns as $key => $column) { |
|
1110 | 1110 | $columns[$key] = t("'@column' => value for @column", array('@column' => $column)); |
1111 | - } |
|
1112 | - $sample = t("return array(\n 0 => array(@columns),\n // You'll usually want to stop here. Provide more values\n // if you want your 'default value' to be multi-valued:\n 1 => array(@columns),\n 2 => ...\n);", array('@columns' => implode(', ', $columns))); |
|
1111 | + } |
|
1112 | + $sample = t("return array(\n 0 => array(@columns),\n // You'll usually want to stop here. Provide more values\n // if you want your 'default value' to be multi-valued:\n 1 => array(@columns),\n 2 => ...\n);", array('@columns' => implode(', ', $columns))); |
|
1113 | 1113 | |
1114 | - $form['widget']['default_value_fieldset']['advanced_options']['default_value_php'] = array( |
|
1114 | + $form['widget']['default_value_fieldset']['advanced_options']['default_value_php'] = array( |
|
1115 | 1115 | '#type' => 'textarea', |
1116 | 1116 | '#title' => t('Code'), |
1117 | 1117 | '#default_value' => isset($field['widget']['default_value_php']) ? $field['widget']['default_value_php'] : '', |
1118 | 1118 | '#rows' => 6, |
1119 | 1119 | '#tree' => TRUE, |
1120 | 1120 | '#description' => t('Advanced usage only: PHP code that returns a default value. Should not include <?php ?> delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format: <pre>!sample</pre>To figure out the expected format, you can use the <em>devel load</em> tab provided by <a href="@link_devel">devel module</a> on a %type content page.', array( |
1121 | - '!sample' => $sample, |
|
1122 | - '@link_devel' => 'http://www.drupal.org/project/devel', |
|
1123 | - '%type' => $type_name)), |
|
1124 | - ); |
|
1121 | + '!sample' => $sample, |
|
1122 | + '@link_devel' => 'http://www.drupal.org/project/devel', |
|
1123 | + '%type' => $type_name)), |
|
1124 | + ); |
|
1125 | 1125 | } |
1126 | 1126 | else { |
1127 | - $form['widget']['default_value_fieldset']['advanced_options']['markup_default_value_php'] = array( |
|
1127 | + $form['widget']['default_value_fieldset']['advanced_options']['markup_default_value_php'] = array( |
|
1128 | 1128 | '#type' => 'item', |
1129 | 1129 | '#title' => t('Code'), |
1130 | 1130 | '#value' => !empty($field['widget']['default_value_php']) ? '<code>'. check_plain($field['widget']['default_value_php']) .'</code>' : t('<none>'), |
1131 | 1131 | '#description' => empty($field['widget']['default_value_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override any value specified above.'), |
1132 | - ); |
|
1132 | + ); |
|
1133 | + } |
|
1133 | 1134 | } |
1134 | - } |
|
1135 | 1135 | |
1136 | - $form['field'] = array( |
|
1136 | + $form['field'] = array( |
|
1137 | 1137 | '#type' => 'fieldset', |
1138 | 1138 | '#title' => t('Global settings'), |
1139 | 1139 | '#description' => t('These settings apply to the %field field in every content type in which it appears.', array('%field' => $field['widget']['label'])), |
1140 | - ); |
|
1141 | - $form['field']['required'] = array( |
|
1140 | + ); |
|
1141 | + $form['field']['required'] = array( |
|
1142 | 1142 | '#type' => 'checkbox', |
1143 | 1143 | '#title' => t('Required'), |
1144 | 1144 | '#default_value' => $field['required'], |
1145 | - ); |
|
1146 | - $description = t('Maximum number of values users can enter for this field.'); |
|
1147 | - if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
1145 | + ); |
|
1146 | + $description = t('Maximum number of values users can enter for this field.'); |
|
1147 | + if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
1148 | 1148 | $description .= '<br/>'. t("'Unlimited' will provide an 'Add more' button so the users can add as many values as they like."); |
1149 | - } |
|
1150 | - $description .= '<br/><strong>'. t('Warning! Changing this setting after data has been created could result in the loss of data!') .'</strong>'; |
|
1151 | - $form['field']['multiple'] = array( |
|
1149 | + } |
|
1150 | + $description .= '<br/><strong>'. t('Warning! Changing this setting after data has been created could result in the loss of data!') .'</strong>'; |
|
1151 | + $form['field']['multiple'] = array( |
|
1152 | 1152 | '#type' => 'select', |
1153 | 1153 | '#title' => t('Number of values'), |
1154 | 1154 | '#options' => array(1 => t('Unlimited'), 0 => 1) + drupal_map_assoc(range(2, 10)), |
1155 | 1155 | '#default_value' => $field['multiple'], |
1156 | 1156 | '#description' => $description, |
1157 | - ); |
|
1157 | + ); |
|
1158 | 1158 | |
1159 | - $form['field']['previous_field'] = array( |
|
1159 | + $form['field']['previous_field'] = array( |
|
1160 | 1160 | '#type' => 'hidden', |
1161 | 1161 | '#value' => serialize($field), |
1162 | - ); |
|
1162 | + ); |
|
1163 | 1163 | |
1164 | - $additions = (array) module_invoke($field_type['module'], 'field_settings', 'form', $field); |
|
1165 | - drupal_alter('field_settings', $additions, 'form', $field); |
|
1166 | - $form['field'] = array_merge($form['field'], $additions); |
|
1164 | + $additions = (array) module_invoke($field_type['module'], 'field_settings', 'form', $field); |
|
1165 | + drupal_alter('field_settings', $additions, 'form', $field); |
|
1166 | + $form['field'] = array_merge($form['field'], $additions); |
|
1167 | 1167 | |
1168 | - $form['submit'] = array( |
|
1168 | + $form['submit'] = array( |
|
1169 | 1169 | '#type' => 'submit', |
1170 | 1170 | '#value' => t('Save field settings'), |
1171 | - ); |
|
1172 | - $form['type_name'] = array( |
|
1171 | + ); |
|
1172 | + $form['type_name'] = array( |
|
1173 | 1173 | '#type' => 'value', |
1174 | 1174 | '#value' => $type_name, |
1175 | - ); |
|
1176 | - $form['field_name'] = array( |
|
1175 | + ); |
|
1176 | + $form['field_name'] = array( |
|
1177 | 1177 | '#type' => 'value', |
1178 | 1178 | '#value' => $field_name, |
1179 | - ); |
|
1180 | - $form['type'] = array( |
|
1179 | + ); |
|
1180 | + $form['type'] = array( |
|
1181 | 1181 | '#type' => 'value', |
1182 | 1182 | '#value' => $field['type'], |
1183 | - ); |
|
1184 | - $form['module'] = array( |
|
1183 | + ); |
|
1184 | + $form['module'] = array( |
|
1185 | 1185 | '#type' => 'value', |
1186 | 1186 | '#value' => $field['module'], |
1187 | - ); |
|
1188 | - $form['widget']['label'] = array( |
|
1187 | + ); |
|
1188 | + $form['widget']['label'] = array( |
|
1189 | 1189 | '#type' => 'value', |
1190 | 1190 | '#value' => $field['widget']['label'], |
1191 | - ); |
|
1192 | - $form['widget_module'] = array( |
|
1191 | + ); |
|
1192 | + $form['widget_module'] = array( |
|
1193 | 1193 | '#type' => 'value', |
1194 | 1194 | '#value' => $field['widget']['module'], |
1195 | - ); |
|
1196 | - $form['columns'] = array( |
|
1195 | + ); |
|
1196 | + $form['columns'] = array( |
|
1197 | 1197 | '#type' => 'value', |
1198 | 1198 | '#value' => $field['columns'], |
1199 | - ); |
|
1200 | - return $form; |
|
1199 | + ); |
|
1200 | + return $form; |
|
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | /** |
1204 | 1204 | * Validate a field's settings. |
1205 | 1205 | */ |
1206 | 1206 | function content_field_edit_form_validate($form, &$form_state) { |
1207 | - $form_values = $form_state['values']; |
|
1208 | - if (isset($form_state['change_basic']) || $form_values['op'] == t('Change basic information')) { |
|
1207 | + $form_values = $form_state['values']; |
|
1208 | + if (isset($form_state['change_basic']) || $form_values['op'] == t('Change basic information')) { |
|
1209 | 1209 | return; |
1210 | - } |
|
1210 | + } |
|
1211 | 1211 | |
1212 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
1213 | - $previous_field = unserialize($form_values['previous_field']); |
|
1214 | - $field = content_field_instance_expand($form_values); |
|
1215 | - $field['db_storage'] = content_storage_type($field); |
|
1212 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
1213 | + $previous_field = unserialize($form_values['previous_field']); |
|
1214 | + $field = content_field_instance_expand($form_values); |
|
1215 | + $field['db_storage'] = content_storage_type($field); |
|
1216 | 1216 | |
1217 | - $field_types = _content_field_types(); |
|
1218 | - $field_type = $field_types[$field['type']]; |
|
1219 | - $widget_types = _content_widget_types(); |
|
1220 | - $widget_type = $widget_types[$field['widget']['type']]; |
|
1217 | + $field_types = _content_field_types(); |
|
1218 | + $field_type = $field_types[$field['type']]; |
|
1219 | + $widget_types = _content_widget_types(); |
|
1220 | + $widget_type = $widget_types[$field['widget']['type']]; |
|
1221 | 1221 | |
1222 | - if ($dropped_data = content_alter_db_analyze($previous_field, $field)) { |
|
1222 | + if ($dropped_data = content_alter_db_analyze($previous_field, $field)) { |
|
1223 | 1223 | // @TODO |
1224 | 1224 | // This is a change that might result in loss of data. |
1225 | 1225 | // Add a confirmation form here. |
1226 | 1226 | // dsm($dropped_data); |
1227 | - } |
|
1227 | + } |
|
1228 | 1228 | |
1229 | - module_invoke($widget_type['module'], 'widget_settings', 'validate', array_merge($field, $form_values)); |
|
1230 | - module_invoke($field_type['module'], 'field_settings', 'validate', array_merge($field, $form_values)); |
|
1229 | + module_invoke($widget_type['module'], 'widget_settings', 'validate', array_merge($field, $form_values)); |
|
1230 | + module_invoke($field_type['module'], 'field_settings', 'validate', array_merge($field, $form_values)); |
|
1231 | 1231 | |
1232 | - // If content.module is handling the default value, |
|
1233 | - // validate the result using the field validation. |
|
1234 | - if (content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) { |
|
1232 | + // If content.module is handling the default value, |
|
1233 | + // validate the result using the field validation. |
|
1234 | + if (content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) { |
|
1235 | 1235 | |
1236 | 1236 | // If this is a programmed form, get rid of the default value widget, |
1237 | 1237 | // we have the default values already. |
1238 | 1238 | if ($form['#programmed']) { |
1239 | - form_set_value(array('#parents' => array('default_value_widget')), NULL, $form_state); |
|
1240 | - return; |
|
1239 | + form_set_value(array('#parents' => array('default_value_widget')), NULL, $form_state); |
|
1240 | + return; |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | if (isset($form_values['default_value_php']) && |
1244 | 1244 | ($php = trim($form_values['default_value_php']))) { |
1245 | - $error = FALSE; |
|
1246 | - ob_start(); |
|
1247 | - $return = eval($php); |
|
1248 | - ob_end_clean(); |
|
1249 | - if (!is_array($return)) { |
|
1245 | + $error = FALSE; |
|
1246 | + ob_start(); |
|
1247 | + $return = eval($php); |
|
1248 | + ob_end_clean(); |
|
1249 | + if (!is_array($return)) { |
|
1250 | 1250 | $error = TRUE; |
1251 | - } |
|
1252 | - else { |
|
1251 | + } |
|
1252 | + else { |
|
1253 | 1253 | foreach ($return as $item) { |
1254 | - if (!is_array($item)) { |
|
1254 | + if (!is_array($item)) { |
|
1255 | 1255 | $error = TRUE; |
1256 | 1256 | break; |
1257 | - } |
|
1257 | + } |
|
1258 | 1258 | } |
1259 | - } |
|
1260 | - if ($error) { |
|
1259 | + } |
|
1260 | + if ($error) { |
|
1261 | 1261 | $db_info = content_database_info($field); |
1262 | 1262 | $columns = array_keys($db_info['columns']); |
1263 | 1263 | foreach ($columns as $key => $column) { |
1264 | - $columns[$key] = t("'@column' => value for @column", array('@column' => $column)); |
|
1264 | + $columns[$key] = t("'@column' => value for @column", array('@column' => $column)); |
|
1265 | 1265 | } |
1266 | 1266 | $sample = t("return array(\n 0 => array(@columns),\n // You'll usually want to stop here. Provide more values\n // if you want your 'default value' to be multi-valued:\n 1 => array(@columns),\n 2 => ...\n);", array('@columns' => implode(', ', $columns))); |
1267 | 1267 | |
1268 | 1268 | form_set_error('default_value_php', t('The default value PHP code returned an incorrect value.<br/>Expected format: <pre>!sample</pre> Returned value: @value', array( |
1269 | - '!sample' => $sample, |
|
1270 | - '@value' => print_r($return, TRUE)))); |
|
1269 | + '!sample' => $sample, |
|
1270 | + '@value' => print_r($return, TRUE)))); |
|
1271 | 1271 | return; |
1272 | - } |
|
1273 | - else { |
|
1272 | + } |
|
1273 | + else { |
|
1274 | 1274 | $default_value = $return; |
1275 | 1275 | $is_code = TRUE; |
1276 | 1276 | form_set_value(array('#parents' => array('default_value_php')), $php, $form_state); |
1277 | 1277 | form_set_value(array('#parents' => array('default_value')), array(), $form_state); |
1278 | - } |
|
1278 | + } |
|
1279 | 1279 | } |
1280 | 1280 | elseif (!empty($form_values['default_value_widget'])) { |
1281 | - // Fields that handle their own multiple values may use an expected |
|
1282 | - // value as the top-level key, so just pop off the top element. |
|
1283 | - $key = array_shift(array_keys($form_values['default_value_widget'])); |
|
1284 | - $default_value = $form_values['default_value_widget'][$key]; |
|
1285 | - $is_code = FALSE; |
|
1286 | - form_set_value(array('#parents' => array('default_value_php')), '', $form_state); |
|
1287 | - form_set_value(array('#parents' => array('default_value')), $default_value, $form_state); |
|
1281 | + // Fields that handle their own multiple values may use an expected |
|
1282 | + // value as the top-level key, so just pop off the top element. |
|
1283 | + $key = array_shift(array_keys($form_values['default_value_widget'])); |
|
1284 | + $default_value = $form_values['default_value_widget'][$key]; |
|
1285 | + $is_code = FALSE; |
|
1286 | + form_set_value(array('#parents' => array('default_value_php')), '', $form_state); |
|
1287 | + form_set_value(array('#parents' => array('default_value')), $default_value, $form_state); |
|
1288 | 1288 | } |
1289 | 1289 | if (isset($default_value)) { |
1290 | - $node = array(); |
|
1291 | - $node[$form_values['field_name']] = $default_value; |
|
1292 | - $field['required'] = FALSE; |
|
1293 | - $field_function = $field_type['module'] .'_field'; |
|
1290 | + $node = array(); |
|
1291 | + $node[$form_values['field_name']] = $default_value; |
|
1292 | + $field['required'] = FALSE; |
|
1293 | + $field_function = $field_type['module'] .'_field'; |
|
1294 | 1294 | |
1295 | - $errors_before = form_get_errors(); |
|
1295 | + $errors_before = form_get_errors(); |
|
1296 | 1296 | |
1297 | - // Widget now does its own validation, should be no need |
|
1298 | - // to add anything for widget validation here. |
|
1299 | - if (function_exists($field_function)) { |
|
1297 | + // Widget now does its own validation, should be no need |
|
1298 | + // to add anything for widget validation here. |
|
1299 | + if (function_exists($field_function)) { |
|
1300 | 1300 | $field_function('validate', $node, $field, $default_value, $form, NULL); |
1301 | - } |
|
1302 | - // The field validation routine won't set an error on the right field, |
|
1303 | - // so set it here. |
|
1304 | - $errors_after = form_get_errors(); |
|
1305 | - if (count($errors_after) > count($errors_before)) { |
|
1301 | + } |
|
1302 | + // The field validation routine won't set an error on the right field, |
|
1303 | + // so set it here. |
|
1304 | + $errors_after = form_get_errors(); |
|
1305 | + if (count($errors_after) > count($errors_before)) { |
|
1306 | 1306 | if (trim($form_values['default_value_php'])) { |
1307 | - form_set_error('default_value_php', t("The PHP code for 'default value' returned @value, which is invalid.", array( |
|
1307 | + form_set_error('default_value_php', t("The PHP code for 'default value' returned @value, which is invalid.", array( |
|
1308 | 1308 | '@value' => print_r($default_value, TRUE)))); |
1309 | 1309 | } |
1310 | 1310 | else { |
1311 | - form_set_error('default_value', t('The default value is invalid.')); |
|
1311 | + form_set_error('default_value', t('The default value is invalid.')); |
|
1312 | 1312 | } |
1313 | - } |
|
1313 | + } |
|
1314 | + } |
|
1314 | 1315 | } |
1315 | - } |
|
1316 | 1316 | } |
1317 | 1317 | |
1318 | 1318 | /** |
1319 | 1319 | * Button submit handler. |
1320 | 1320 | */ |
1321 | 1321 | function content_field_edit_form_submit_update_basic($form, &$form_state) { |
1322 | - $form_state['change_basic'] = TRUE; |
|
1323 | - $form_state['rebuild'] = TRUE; |
|
1322 | + $form_state['change_basic'] = TRUE; |
|
1323 | + $form_state['rebuild'] = TRUE; |
|
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | /** |
1327 | 1327 | * Save a field's settings after editing. |
1328 | 1328 | */ |
1329 | 1329 | function content_field_edit_form_submit($form, &$form_state) { |
1330 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
1331 | - $form_values = $form_state['values']; |
|
1332 | - content_field_instance_update($form_values); |
|
1333 | - |
|
1334 | - $destinations = !empty($_REQUEST['destinations']) ? $_REQUEST['destinations'] : array(); |
|
1335 | - // Remove any external URLs. |
|
1336 | - $destinations = array_diff($destinations, array_filter($destinations, 'menu_path_is_external')); |
|
1337 | - if ($destinations) { |
|
1330 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
1331 | + $form_values = $form_state['values']; |
|
1332 | + content_field_instance_update($form_values); |
|
1333 | + |
|
1334 | + $destinations = !empty($_REQUEST['destinations']) ? $_REQUEST['destinations'] : array(); |
|
1335 | + // Remove any external URLs. |
|
1336 | + $destinations = array_diff($destinations, array_filter($destinations, 'menu_path_is_external')); |
|
1337 | + if ($destinations) { |
|
1338 | 1338 | drupal_set_message(t('Added field %label.', array('%label' => $form_values['label']))); |
1339 | 1339 | $form_state['redirect'] = content_get_destinations($destinations); |
1340 | - } |
|
1341 | - else { |
|
1340 | + } |
|
1341 | + else { |
|
1342 | 1342 | drupal_set_message(t('Saved field %label.', array('%label' => $form_values['label']))); |
1343 | 1343 | $type = content_types($form_values['type_name']); |
1344 | 1344 | $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; |
1345 | - } |
|
1345 | + } |
|
1346 | 1346 | } |
1347 | 1347 | |
1348 | 1348 | /** |
1349 | 1349 | * Helper function to handle multipage redirects. |
1350 | 1350 | */ |
1351 | 1351 | function content_get_destinations($destinations) { |
1352 | - $query = array(); |
|
1353 | - $path = array_shift($destinations); |
|
1354 | - if ($destinations) { |
|
1352 | + $query = array(); |
|
1353 | + $path = array_shift($destinations); |
|
1354 | + if ($destinations) { |
|
1355 | 1355 | $query['destinations'] = $destinations; |
1356 | - } |
|
1357 | - return array($path, $query); |
|
1356 | + } |
|
1357 | + return array($path, $query); |
|
1358 | 1358 | } |
1359 | 1359 | |
1360 | 1360 | /** |
@@ -1367,7 +1367,7 @@ discard block |
||
1367 | 1367 | * |
1368 | 1368 | */ |
1369 | 1369 | function content_alter_schema($previous_field, $new_field) { |
1370 | - content_alter_db($previous_field, $new_field); |
|
1370 | + content_alter_db($previous_field, $new_field); |
|
1371 | 1371 | } |
1372 | 1372 | |
1373 | 1373 | /** |
@@ -1378,37 +1378,37 @@ discard block |
||
1378 | 1378 | * we actually alter the schema. |
1379 | 1379 | */ |
1380 | 1380 | function content_alter_db_analyze($previous_field, $new_field) { |
1381 | - $dropped = array(); |
|
1382 | - // There is no loss of data if there was no previous data. |
|
1383 | - if (empty($previous_field)) { |
|
1381 | + $dropped = array(); |
|
1382 | + // There is no loss of data if there was no previous data. |
|
1383 | + if (empty($previous_field)) { |
|
1384 | 1384 | return $dropped; |
1385 | - } |
|
1385 | + } |
|
1386 | 1386 | |
1387 | - // Analyze possible data loss from changes in storage type. |
|
1388 | - if (!empty($previous_field) && !empty($new_field)) { |
|
1387 | + // Analyze possible data loss from changes in storage type. |
|
1388 | + if (!empty($previous_field) && !empty($new_field)) { |
|
1389 | 1389 | // Changing from multiple to not multiple data, will cause loss of all |
1390 | 1390 | // values greater than zero. |
1391 | 1391 | if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD && |
1392 | 1392 | $new_field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE) { |
1393 | - $dropped['delta'] = 0; |
|
1393 | + $dropped['delta'] = 0; |
|
1394 | 1394 | } |
1395 | 1395 | // Changing from one multiple value to another will cause loss of all |
1396 | 1396 | // values for deltas greater than or equal to the new multiple value. |
1397 | 1397 | elseif (isset($previous_field['multiple']) && isset($new_field['multiple'])) { |
1398 | - if ($previous_field['multiple'] > $new_field['multiple'] && |
|
1398 | + if ($previous_field['multiple'] > $new_field['multiple'] && |
|
1399 | 1399 | $new_field['multiple'] > 1) { |
1400 | 1400 | $dropped['delta'] = $new_field['multiple']; |
1401 | - } |
|
1401 | + } |
|
1402 | + } |
|
1402 | 1403 | } |
1403 | - } |
|
1404 | 1404 | |
1405 | - // Analyze possible data loss from changes in field columns. |
|
1406 | - $previous_schema = !empty($previous_field) ? content_table_schema($previous_field) : array('fields' => array()); |
|
1407 | - $new_schema = !empty($new_field) ? content_table_schema($new_field) : array('fields' => array()); |
|
1408 | - $dropped_columns = array_diff(array_keys($previous_schema['fields']), array_keys($new_schema['fields'])); |
|
1409 | - if ($dropped_columns) { |
|
1405 | + // Analyze possible data loss from changes in field columns. |
|
1406 | + $previous_schema = !empty($previous_field) ? content_table_schema($previous_field) : array('fields' => array()); |
|
1407 | + $new_schema = !empty($new_field) ? content_table_schema($new_field) : array('fields' => array()); |
|
1408 | + $dropped_columns = array_diff(array_keys($previous_schema['fields']), array_keys($new_schema['fields'])); |
|
1409 | + if ($dropped_columns) { |
|
1410 | 1410 | $dropped['columns'] = $dropped_columns; |
1411 | - } |
|
1411 | + } |
|
1412 | 1412 | // if (empty($new_schema['fields'])) { |
1413 | 1413 | // // No new columns, will lose all columns for a field. |
1414 | 1414 | // foreach ($previous_schema['fields'] as $column => $attributes) { |
@@ -1424,7 +1424,7 @@ discard block |
||
1424 | 1424 | // } |
1425 | 1425 | // } |
1426 | 1426 | |
1427 | - return $dropped; |
|
1427 | + return $dropped; |
|
1428 | 1428 | } |
1429 | 1429 | |
1430 | 1430 | /** |
@@ -1432,214 +1432,214 @@ discard block |
||
1432 | 1432 | * new field definitions. |
1433 | 1433 | */ |
1434 | 1434 | function content_alter_db($previous_field, $new_field) { |
1435 | - $ret = array(); |
|
1435 | + $ret = array(); |
|
1436 | 1436 | |
1437 | - // One or the other of these must be valid. |
|
1438 | - if (empty($previous_field) && empty($new_field)) { |
|
1437 | + // One or the other of these must be valid. |
|
1438 | + if (empty($previous_field) && empty($new_field)) { |
|
1439 | 1439 | return $ret; |
1440 | - } |
|
1440 | + } |
|
1441 | 1441 | |
1442 | - // Gather relevant information : schema, table name... |
|
1443 | - $previous_schema = !empty($previous_field) ? content_table_schema($previous_field) : array(); |
|
1444 | - $new_schema = !empty($new_field) ? content_table_schema($new_field) : array(); |
|
1445 | - if (!empty($previous_field)) { |
|
1442 | + // Gather relevant information : schema, table name... |
|
1443 | + $previous_schema = !empty($previous_field) ? content_table_schema($previous_field) : array(); |
|
1444 | + $new_schema = !empty($new_field) ? content_table_schema($new_field) : array(); |
|
1445 | + if (!empty($previous_field)) { |
|
1446 | 1446 | $previous_db_info = content_database_info($previous_field); |
1447 | 1447 | $previous_table = $previous_db_info['table']; |
1448 | - } |
|
1449 | - if (!empty($new_field)) { |
|
1448 | + } |
|
1449 | + if (!empty($new_field)) { |
|
1450 | 1450 | $new_db_info = content_database_info($new_field); |
1451 | 1451 | $new_table = $new_db_info['table']; |
1452 | - } |
|
1452 | + } |
|
1453 | 1453 | |
1454 | - // Deletion of a field instance: drop relevant columns and tables and return. |
|
1455 | - if (empty($new_field)) { |
|
1454 | + // Deletion of a field instance: drop relevant columns and tables and return. |
|
1455 | + if (empty($new_field)) { |
|
1456 | 1456 | if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
1457 | - db_drop_table($ret, $previous_table); |
|
1457 | + db_drop_table($ret, $previous_table); |
|
1458 | 1458 | } |
1459 | 1459 | else { |
1460 | - foreach ($previous_schema['fields'] as $column => $attributes) { |
|
1460 | + foreach ($previous_schema['fields'] as $column => $attributes) { |
|
1461 | 1461 | if (!in_array($column, array('nid', 'vid', 'delta'))) { |
1462 | - db_drop_field($ret, $previous_table, $column); |
|
1462 | + db_drop_field($ret, $previous_table, $column); |
|
1463 | + } |
|
1463 | 1464 | } |
1464 | - } |
|
1465 | 1465 | } |
1466 | 1466 | content_alter_db_cleanup(); |
1467 | 1467 | return $ret; |
1468 | - } |
|
1468 | + } |
|
1469 | 1469 | |
1470 | - // Check that content types that have fields do have a per-type table. |
|
1471 | - if (!empty($new_field)) { |
|
1470 | + // Check that content types that have fields do have a per-type table. |
|
1471 | + if (!empty($new_field)) { |
|
1472 | 1472 | $base_tablename = _content_tablename($new_field['type_name'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE); |
1473 | 1473 | if (!db_table_exists($base_tablename)) { |
1474 | - db_create_table($ret, $base_tablename, content_table_schema()); |
|
1474 | + db_create_table($ret, $base_tablename, content_table_schema()); |
|
1475 | + } |
|
1475 | 1476 | } |
1476 | - } |
|
1477 | 1477 | |
1478 | - // Create new table and columns, if not already created. |
|
1479 | - if (!db_table_exists($new_table)) { |
|
1478 | + // Create new table and columns, if not already created. |
|
1479 | + if (!db_table_exists($new_table)) { |
|
1480 | 1480 | db_create_table($ret, $new_table, $new_schema); |
1481 | - } |
|
1482 | - else { |
|
1481 | + } |
|
1482 | + else { |
|
1483 | 1483 | // Or add fields and/or indexes to an existing table. |
1484 | 1484 | foreach ($new_schema['fields'] as $column => $attributes) { |
1485 | - if (!in_array($column, array('nid', 'vid', 'delta'))) { |
|
1485 | + if (!in_array($column, array('nid', 'vid', 'delta'))) { |
|
1486 | 1486 | // Create the column if it does not exist. |
1487 | 1487 | if (!db_column_exists($new_table, $column)) { |
1488 | - db_add_field($ret, $new_table, $column, $attributes); |
|
1488 | + db_add_field($ret, $new_table, $column, $attributes); |
|
1489 | 1489 | } |
1490 | 1490 | // Create the index if requested to, and it does not exist. |
1491 | 1491 | if (isset($new_schema['indexes'][$column]) && !content_db_index_exists($new_table, $column)) { |
1492 | - db_add_index($ret, $new_table, $column, $new_schema['indexes'][$column]); |
|
1492 | + db_add_index($ret, $new_table, $column, $new_schema['indexes'][$column]); |
|
1493 | + } |
|
1493 | 1494 | } |
1494 | - } |
|
1495 | 1495 | } |
1496 | - } |
|
1496 | + } |
|
1497 | 1497 | |
1498 | - // If this is a new field, we're done. |
|
1499 | - if (empty($previous_field)) { |
|
1498 | + // If this is a new field, we're done. |
|
1499 | + if (empty($previous_field)) { |
|
1500 | 1500 | content_alter_db_cleanup(); |
1501 | 1501 | return $ret; |
1502 | - } |
|
1502 | + } |
|
1503 | 1503 | |
1504 | - // If the previous table doesn't exist, we're done. |
|
1505 | - // Could happen if someone tries to run a schema update from an |
|
1506 | - // content.install update function more than once. |
|
1507 | - if (!db_table_exists($previous_table)) { |
|
1504 | + // If the previous table doesn't exist, we're done. |
|
1505 | + // Could happen if someone tries to run a schema update from an |
|
1506 | + // content.install update function more than once. |
|
1507 | + if (!db_table_exists($previous_table)) { |
|
1508 | 1508 | content_alter_db_cleanup(); |
1509 | 1509 | return $ret; |
1510 | - } |
|
1510 | + } |
|
1511 | 1511 | |
1512 | - // If changing data from one schema to another, see if changes require that |
|
1513 | - // we drop multiple values or migrate data from one storage type to another. |
|
1514 | - $migrate_columns = array_intersect_assoc($new_schema['fields'], $previous_schema['fields']); |
|
1515 | - unset($migrate_columns['nid'], $migrate_columns['vid'], $migrate_columns['delta']); |
|
1512 | + // If changing data from one schema to another, see if changes require that |
|
1513 | + // we drop multiple values or migrate data from one storage type to another. |
|
1514 | + $migrate_columns = array_intersect_assoc($new_schema['fields'], $previous_schema['fields']); |
|
1515 | + unset($migrate_columns['nid'], $migrate_columns['vid'], $migrate_columns['delta']); |
|
1516 | 1516 | |
1517 | - // If we're going from one multiple value a smaller one or to single, |
|
1518 | - // drop all delta values higher than the new maximum delta value. |
|
1519 | - // Not needed if the new multiple is unlimited or if the new table is the content table. |
|
1520 | - if ($new_table != $base_tablename && $new_field['multiple'] < $previous_field['multiple'] && $new_field['multiple'] != 1) { |
|
1517 | + // If we're going from one multiple value a smaller one or to single, |
|
1518 | + // drop all delta values higher than the new maximum delta value. |
|
1519 | + // Not needed if the new multiple is unlimited or if the new table is the content table. |
|
1520 | + if ($new_table != $base_tablename && $new_field['multiple'] < $previous_field['multiple'] && $new_field['multiple'] != 1) { |
|
1521 | 1521 | db_query("DELETE FROM {". $new_table ."} WHERE delta >= ". max(1, $new_field['multiple'])); |
1522 | - } |
|
1522 | + } |
|
1523 | 1523 | |
1524 | - // If going from multiple to non-multiple, make sure the field tables have |
|
1525 | - // the right database structure to accept migrated data. |
|
1526 | - if ($new_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
|
1524 | + // If going from multiple to non-multiple, make sure the field tables have |
|
1525 | + // the right database structure to accept migrated data. |
|
1526 | + if ($new_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
|
1527 | 1527 | if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD && count($previous_schema['fields'])) { |
1528 | - // Already using per-field storage; change multiplicity if needed. |
|
1529 | - if ($previous_field['multiple'] > 0 && $new_field['multiple'] == 0) { |
|
1528 | + // Already using per-field storage; change multiplicity if needed. |
|
1529 | + if ($previous_field['multiple'] > 0 && $new_field['multiple'] == 0) { |
|
1530 | 1530 | db_drop_field($ret, $new_table, 'delta'); |
1531 | 1531 | db_drop_primary_key($ret, $new_table); |
1532 | 1532 | db_add_primary_key($ret, $new_table, array('vid')); |
1533 | - } |
|
1534 | - else if ($previous_field['multiple'] == 0 && $new_field['multiple'] > 0) { |
|
1533 | + } |
|
1534 | + else if ($previous_field['multiple'] == 0 && $new_field['multiple'] > 0) { |
|
1535 | 1535 | db_add_field($ret, $new_table, 'delta', array( |
1536 | - 'type' => 'int', |
|
1537 | - 'unsigned' => TRUE, |
|
1538 | - 'not null' => TRUE, |
|
1539 | - 'default' => 0)); |
|
1536 | + 'type' => 'int', |
|
1537 | + 'unsigned' => TRUE, |
|
1538 | + 'not null' => TRUE, |
|
1539 | + 'default' => 0)); |
|
1540 | 1540 | db_drop_primary_key($ret, $new_table); |
1541 | 1541 | db_add_primary_key($ret, $new_table, array('vid', 'delta')); |
1542 | - } |
|
1542 | + } |
|
1543 | + } |
|
1543 | 1544 | } |
1544 | - } |
|
1545 | 1545 | |
1546 | - // Migrate data from per-content-type storage. |
|
1547 | - if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE && |
|
1546 | + // Migrate data from per-content-type storage. |
|
1547 | + if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE && |
|
1548 | 1548 | $new_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
1549 | 1549 | $columns = array_keys($migrate_columns); |
1550 | 1550 | if ($new_field['multiple']) { |
1551 | - db_query('INSERT INTO {'. $new_table .'} (vid, nid, delta, '. implode(', ', $columns) .') '. |
|
1551 | + db_query('INSERT INTO {'. $new_table .'} (vid, nid, delta, '. implode(', ', $columns) .') '. |
|
1552 | 1552 | ' SELECT vid, nid, 0, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
1553 | 1553 | } |
1554 | 1554 | else { |
1555 | - db_query('INSERT INTO {'. $new_table .'} (vid, nid, '. implode(', ', $columns) .') '. |
|
1555 | + db_query('INSERT INTO {'. $new_table .'} (vid, nid, '. implode(', ', $columns) .') '. |
|
1556 | 1556 | ' SELECT vid, nid, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
1557 | 1557 | } |
1558 | 1558 | foreach ($columns as $column_name) { |
1559 | - db_drop_field($ret, $previous_table, $column_name); |
|
1559 | + db_drop_field($ret, $previous_table, $column_name); |
|
1560 | + } |
|
1560 | 1561 | } |
1561 | - } |
|
1562 | 1562 | |
1563 | - // Migrate data from per-field storage, and drop per-field table. |
|
1564 | - if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD && |
|
1563 | + // Migrate data from per-field storage, and drop per-field table. |
|
1564 | + if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD && |
|
1565 | 1565 | $new_field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE) { |
1566 | 1566 | // In order to be able to use drupal_write_record, we need to |
1567 | 1567 | // rebuild the schema now. |
1568 | 1568 | content_alter_db_cleanup(); |
1569 | 1569 | if ($previous_field['multiple']) { |
1570 | - $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE delta = 0 AND n.type = '%s'", $new_field['type_name']); |
|
1570 | + $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE delta = 0 AND n.type = '%s'", $new_field['type_name']); |
|
1571 | 1571 | } |
1572 | 1572 | else { |
1573 | - $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s'", $new_field['type_name']); |
|
1573 | + $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s'", $new_field['type_name']); |
|
1574 | 1574 | } |
1575 | 1575 | $record = array(); |
1576 | 1576 | while ($data = db_fetch_array($result)) { |
1577 | - $record['nid'] = $data['nid']; |
|
1578 | - $record['vid'] = $data['vid']; |
|
1579 | - if ($previous_field['multiple']) { |
|
1577 | + $record['nid'] = $data['nid']; |
|
1578 | + $record['vid'] = $data['vid']; |
|
1579 | + if ($previous_field['multiple']) { |
|
1580 | 1580 | $record['delta'] = $data['delta']; |
1581 | - } |
|
1582 | - foreach ($migrate_columns as $column => $attributes) { |
|
1581 | + } |
|
1582 | + foreach ($migrate_columns as $column => $attributes) { |
|
1583 | 1583 | if (is_null($data[$column])) { |
1584 | - $record[$column] = NULL; |
|
1584 | + $record[$column] = NULL; |
|
1585 | 1585 | } |
1586 | 1586 | else { |
1587 | - $record[$column] = $data[$column]; |
|
1588 | - // Prevent double serializtion in drupal_write_record. |
|
1589 | - if (isset($attributes['serialize']) && $attributes['serialize']) { |
|
1587 | + $record[$column] = $data[$column]; |
|
1588 | + // Prevent double serializtion in drupal_write_record. |
|
1589 | + if (isset($attributes['serialize']) && $attributes['serialize']) { |
|
1590 | 1590 | $record[$column] = unserialize($record[$column]); |
1591 | - } |
|
1591 | + } |
|
1592 | 1592 | } |
1593 | - } |
|
1594 | - if (db_result(db_query('SELECT COUNT(*) FROM {'. $new_table . |
|
1595 | - '} WHERE vid = %d AND nid = %d', $data['vid'], $data['nid']))) { |
|
1593 | + } |
|
1594 | + if (db_result(db_query('SELECT COUNT(*) FROM {'. $new_table . |
|
1595 | + '} WHERE vid = %d AND nid = %d', $data['vid'], $data['nid']))) { |
|
1596 | 1596 | $keys = $new_field['multiple'] ? array('vid', 'delta') : array('vid'); |
1597 | 1597 | drupal_write_record($new_table, $record, $keys); |
1598 | - } |
|
1599 | - else { |
|
1598 | + } |
|
1599 | + else { |
|
1600 | 1600 | drupal_write_record($new_table, $record); |
1601 | - } |
|
1601 | + } |
|
1602 | 1602 | } |
1603 | 1603 | db_drop_table($ret, $previous_table); |
1604 | - } |
|
1604 | + } |
|
1605 | 1605 | |
1606 | - // Change modified columns that don't involve storage changes. |
|
1607 | - foreach ($new_schema['fields'] as $column => $attributes) { |
|
1606 | + // Change modified columns that don't involve storage changes. |
|
1607 | + foreach ($new_schema['fields'] as $column => $attributes) { |
|
1608 | 1608 | if (isset($previous_schema['fields'][$column]) && |
1609 | 1609 | $previous_field['db_storage'] == $new_field['db_storage']) { |
1610 | - if ($attributes != $previous_schema['fields'][$column]) { |
|
1610 | + if ($attributes != $previous_schema['fields'][$column]) { |
|
1611 | 1611 | if (!in_array($column, array('nid', 'vid', 'delta'))) { |
1612 | - db_change_field($ret, $new_table, $column, $column, $attributes); |
|
1612 | + db_change_field($ret, $new_table, $column, $column, $attributes); |
|
1613 | + } |
|
1613 | 1614 | } |
1614 | - } |
|
1615 | 1615 | } |
1616 | - } |
|
1616 | + } |
|
1617 | 1617 | |
1618 | - // Remove obsolete columns. |
|
1619 | - foreach ($previous_schema['fields'] as $column => $attributes) { |
|
1618 | + // Remove obsolete columns. |
|
1619 | + foreach ($previous_schema['fields'] as $column => $attributes) { |
|
1620 | 1620 | if (!isset($new_schema['fields'][$column])) { |
1621 | - if (!in_array($column, array('nid', 'vid', 'delta'))) { |
|
1621 | + if (!in_array($column, array('nid', 'vid', 'delta'))) { |
|
1622 | 1622 | db_drop_field($ret, $previous_table, $column); |
1623 | - } |
|
1623 | + } |
|
1624 | + } |
|
1624 | 1625 | } |
1625 | - } |
|
1626 | 1626 | |
1627 | - // TODO: debugging stuff - should be removed |
|
1628 | - if (module_exists('devel')) { |
|
1627 | + // TODO: debugging stuff - should be removed |
|
1628 | + if (module_exists('devel')) { |
|
1629 | 1629 | //dsm($ret); |
1630 | - } |
|
1631 | - return $ret; |
|
1630 | + } |
|
1631 | + return $ret; |
|
1632 | 1632 | } |
1633 | 1633 | |
1634 | 1634 | /** |
1635 | 1635 | * Helper function for handling cleanup operations when schema changes are made. |
1636 | 1636 | */ |
1637 | 1637 | function content_alter_db_cleanup() { |
1638 | - // Rebuild the whole database schema. |
|
1639 | - // TODO: this could be optimized. We don't need to rebuild in *every case*... |
|
1640 | - // Or do we? This affects the schema and menu and may have unfortunate |
|
1641 | - // delayed effects if we don't clear everything out at this point. |
|
1642 | - content_clear_type_cache(TRUE); |
|
1638 | + // Rebuild the whole database schema. |
|
1639 | + // TODO: this could be optimized. We don't need to rebuild in *every case*... |
|
1640 | + // Or do we? This affects the schema and menu and may have unfortunate |
|
1641 | + // delayed effects if we don't clear everything out at this point. |
|
1642 | + content_clear_type_cache(TRUE); |
|
1643 | 1643 | } |
1644 | 1644 | |
1645 | 1645 | /** |
@@ -1650,27 +1650,27 @@ discard block |
||
1650 | 1650 | * relationships are sorted out. |
1651 | 1651 | */ |
1652 | 1652 | function _content_overview_order(&$form, $field_rows, $group_rows) { |
1653 | - // Put weight and parenting values into a $dummy render structure |
|
1654 | - // and let drupal_render figure out the corresponding row order. |
|
1655 | - $dummy = array(); |
|
1656 | - // Group rows: account for weight. |
|
1657 | - if (module_exists('fieldgroup')) { |
|
1653 | + // Put weight and parenting values into a $dummy render structure |
|
1654 | + // and let drupal_render figure out the corresponding row order. |
|
1655 | + $dummy = array(); |
|
1656 | + // Group rows: account for weight. |
|
1657 | + if (module_exists('fieldgroup')) { |
|
1658 | 1658 | foreach ($group_rows as $name) { |
1659 | - $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name .' '); |
|
1659 | + $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name .' '); |
|
1660 | 1660 | } |
1661 | - } |
|
1662 | - // Field rows : account for weight and parenting. |
|
1663 | - foreach ($field_rows as $name) { |
|
1661 | + } |
|
1662 | + // Field rows : account for weight and parenting. |
|
1663 | + foreach ($field_rows as $name) { |
|
1664 | 1664 | $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name .' '); |
1665 | 1665 | if (module_exists('fieldgroup')) { |
1666 | - if ($parent = $form[$name]['parent']['#value']) { |
|
1666 | + if ($parent = $form[$name]['parent']['#value']) { |
|
1667 | 1667 | $form[$name]['#depth'] = 1; |
1668 | 1668 | $dummy[$parent][$name] = $dummy[$name]; |
1669 | 1669 | unset($dummy[$name]); |
1670 | - } |
|
1670 | + } |
|
1671 | 1671 | } |
1672 | - } |
|
1673 | - return $dummy ? explode(' ', trim(drupal_render($dummy))) : array(); |
|
1672 | + } |
|
1673 | + return $dummy ? explode(' ', trim(drupal_render($dummy))) : array(); |
|
1674 | 1674 | } |
1675 | 1675 | |
1676 | 1676 | /** |
@@ -1683,50 +1683,50 @@ discard block |
||
1683 | 1683 | * this and get it working properly when the fields are altered via the API. |
1684 | 1684 | */ |
1685 | 1685 | function content_alter_fields($previous_field, $new_field) { |
1686 | - // See what values need to be updated in the field data. |
|
1687 | - $mask = content_alter_db_mask($previous_field, $new_field); |
|
1688 | - |
|
1689 | - // We use batch processing to prevent timeout when updating a large number |
|
1690 | - // of nodes. If there is no previous data to adjust, we can just go straight |
|
1691 | - // to altering the schema, otherwise use batch processing to update |
|
1692 | - // the database one node at a time, then update the schema. |
|
1693 | - if (empty($mask)) { |
|
1686 | + // See what values need to be updated in the field data. |
|
1687 | + $mask = content_alter_db_mask($previous_field, $new_field); |
|
1688 | + |
|
1689 | + // We use batch processing to prevent timeout when updating a large number |
|
1690 | + // of nodes. If there is no previous data to adjust, we can just go straight |
|
1691 | + // to altering the schema, otherwise use batch processing to update |
|
1692 | + // the database one node at a time, then update the schema. |
|
1693 | + if (empty($mask)) { |
|
1694 | 1694 | return content_alter_db($previous_field, $new_field); |
1695 | - } |
|
1696 | - $updates = array( |
|
1695 | + } |
|
1696 | + $updates = array( |
|
1697 | 1697 | 'mask' => $mask['mask'], |
1698 | 1698 | 'alt_mask' => $mask['alt_mask'], |
1699 | 1699 | 'delta' => $mask['delta'], |
1700 | 1700 | ); |
1701 | - $batch = array( |
|
1701 | + $batch = array( |
|
1702 | 1702 | 'operations' => array( |
1703 | - array('content_field_batch_update', array($previous_field['field_name'] => $updates)), |
|
1704 | - array('content_alter_db', array($previous_field, $new_field)) |
|
1703 | + array('content_field_batch_update', array($previous_field['field_name'] => $updates)), |
|
1704 | + array('content_alter_db', array($previous_field, $new_field)) |
|
1705 | 1705 | ), |
1706 | 1706 | 'finished' => '_content_alter_fields_finished', |
1707 | 1707 | 'title' => t('Processing'), |
1708 | 1708 | 'error_message' => t('The update has encountered an error.'), |
1709 | 1709 | 'file' => './'. drupal_get_path('module', 'content') .'/includes/content.admin.inc', |
1710 | - ); |
|
1711 | - batch_set($batch); |
|
1712 | - if (!empty($url)) { |
|
1710 | + ); |
|
1711 | + batch_set($batch); |
|
1712 | + if (!empty($url)) { |
|
1713 | 1713 | batch_process($url, $url); |
1714 | - } |
|
1714 | + } |
|
1715 | 1715 | } |
1716 | 1716 | |
1717 | 1717 | /** |
1718 | 1718 | * Content Replace Fields 'finished' callback. |
1719 | 1719 | */ |
1720 | 1720 | function _content_alter_fields_finished($success, $results, $operations) { |
1721 | - if ($success) { |
|
1721 | + if ($success) { |
|
1722 | 1722 | drupal_set_message(t('The database has been altered and data has been migrated or deleted.')); |
1723 | - } |
|
1724 | - else { |
|
1723 | + } |
|
1724 | + else { |
|
1725 | 1725 | drupal_set_message(t('An error occurred and database alteration did not complete.'), 'error'); |
1726 | 1726 | $message = format_plural(count($results), '1 item successfully processed:', '@count items successfully processed:'); |
1727 | 1727 | $message .= theme('item_list', $results); |
1728 | 1728 | drupal_set_message($message); |
1729 | - } |
|
1729 | + } |
|
1730 | 1730 | } |
1731 | 1731 | |
1732 | 1732 | /** |
@@ -1741,28 +1741,28 @@ discard block |
||
1741 | 1741 | * some columns still have values, so all these things need to be tested. |
1742 | 1742 | */ |
1743 | 1743 | function content_alter_db_mask($previous_field, $new_field) { |
1744 | - // Get an array of column values that will be dropped by this |
|
1745 | - // schema change and create a mask to feed to content_batch_update. |
|
1744 | + // Get an array of column values that will be dropped by this |
|
1745 | + // schema change and create a mask to feed to content_batch_update. |
|
1746 | 1746 | |
1747 | - $dropped = content_alter_db_analyze($previous_field, $new_field); |
|
1748 | - if (empty($dropped)) { |
|
1747 | + $dropped = content_alter_db_analyze($previous_field, $new_field); |
|
1748 | + if (empty($dropped)) { |
|
1749 | 1749 | return array(); |
1750 | - } |
|
1751 | - $mask = array('mask' => array()); |
|
1752 | - foreach (array_keys($previous_field['columns']) as $column_name) { |
|
1750 | + } |
|
1751 | + $mask = array('mask' => array()); |
|
1752 | + foreach (array_keys($previous_field['columns']) as $column_name) { |
|
1753 | 1753 | // The basic mask will empty the dropped columns. |
1754 | 1754 | if (isset($dropped['columns']) && in_array($column_name, $dropped['columns'])) { |
1755 | - $mask['mask'][$column_name] = NULL; |
|
1755 | + $mask['mask'][$column_name] = NULL; |
|
1756 | 1756 | } |
1757 | 1757 | // Over the delta we'll empty all columns. |
1758 | 1758 | if (isset($dropped['delta'])) { |
1759 | - $mask['alt_mask'][$column_name] = NULL; |
|
1759 | + $mask['alt_mask'][$column_name] = NULL; |
|
1760 | + } |
|
1760 | 1761 | } |
1761 | - } |
|
1762 | - if (isset($dropped['delta'])) { |
|
1762 | + if (isset($dropped['delta'])) { |
|
1763 | 1763 | $mask['delta'] = $dropped['delta']; |
1764 | - } |
|
1765 | - return $mask; |
|
1764 | + } |
|
1765 | + return $mask; |
|
1766 | 1766 | } |
1767 | 1767 | |
1768 | 1768 | /** |
@@ -1785,36 +1785,36 @@ discard block |
||
1785 | 1785 | * ), |
1786 | 1786 | */ |
1787 | 1787 | function content_field_batch_update($updates, &$context) { |
1788 | - if (empty($field)) { |
|
1788 | + if (empty($field)) { |
|
1789 | 1789 | $context['finished'] = 1; |
1790 | 1790 | return; |
1791 | - } |
|
1792 | - $field_name = $updates['field_name']; |
|
1793 | - $field = content_fields($field_name); |
|
1791 | + } |
|
1792 | + $field_name = $updates['field_name']; |
|
1793 | + $field = content_fields($field_name); |
|
1794 | 1794 | |
1795 | - if (!isset($context['sandbox']['progress'])) { |
|
1795 | + if (!isset($context['sandbox']['progress'])) { |
|
1796 | 1796 | $db_info = content_database_info($field); |
1797 | 1797 | |
1798 | 1798 | // Might run into non-existent tables when cleaning up a corrupted |
1799 | 1799 | // database, like some of the old content storage changes in the |
1800 | 1800 | // .install files. |
1801 | 1801 | if (!db_table_exists($db_info['table'])) { |
1802 | - return $context['finished'] = 1; |
|
1802 | + return $context['finished'] = 1; |
|
1803 | 1803 | } |
1804 | 1804 | $nodes = array(); |
1805 | 1805 | $result = db_query("SELECT nid FROM {". $db_info['table'] ."}"); |
1806 | 1806 | while ($node = db_fetch_array($result)) { |
1807 | - $nodes[] = $node['nid']; |
|
1807 | + $nodes[] = $node['nid']; |
|
1808 | 1808 | } |
1809 | 1809 | $context['sandbox']['progress'] = 0; |
1810 | 1810 | $context['sandbox']['max'] = count($nodes); |
1811 | 1811 | $context['sandbox']['nodes'] = $nodes; |
1812 | - } |
|
1812 | + } |
|
1813 | 1813 | |
1814 | - // Process nodes by groups of 5. |
|
1815 | - $count = min(5, count($context['sandbox']['nodes'])); |
|
1814 | + // Process nodes by groups of 5. |
|
1815 | + $count = min(5, count($context['sandbox']['nodes'])); |
|
1816 | 1816 | |
1817 | - for ($i = 1; $i <= $count; $i++) { |
|
1817 | + for ($i = 1; $i <= $count; $i++) { |
|
1818 | 1818 | // For each nid, load the node, empty the column values |
1819 | 1819 | // or the whole field, and re-save it. |
1820 | 1820 | $nid = array_shift($context['sandbox']['nodes']); |
@@ -1826,13 +1826,13 @@ discard block |
||
1826 | 1826 | // Update our progress information. |
1827 | 1827 | $context['sandbox']['progress']++; |
1828 | 1828 | $context['message'] = t('Processing %title', array('%title' => $node->title)); |
1829 | - } |
|
1829 | + } |
|
1830 | 1830 | |
1831 | - // Inform the batch engine that we are not finished, |
|
1832 | - // and provide an estimation of the completion level we reached. |
|
1833 | - if ($context['sandbox']['progress'] != $context['sandbox']['max']) { |
|
1831 | + // Inform the batch engine that we are not finished, |
|
1832 | + // and provide an estimation of the completion level we reached. |
|
1833 | + if ($context['sandbox']['progress'] != $context['sandbox']['max']) { |
|
1834 | 1834 | $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; |
1835 | - } |
|
1835 | + } |
|
1836 | 1836 | } |
1837 | 1837 | |
1838 | 1838 | /** |
@@ -1869,48 +1869,48 @@ discard block |
||
1869 | 1869 | * ), |
1870 | 1870 | */ |
1871 | 1871 | function content_field_replace($nid, $updates) { |
1872 | - $node = node_load($nid, NULL, TRUE); |
|
1873 | - foreach ($updates as $field_name => $update) { |
|
1872 | + $node = node_load($nid, NULL, TRUE); |
|
1873 | + foreach ($updates as $field_name => $update) { |
|
1874 | 1874 | $items = isset($node->$field_name) ? $node->$field_name : array(); |
1875 | 1875 | foreach ($items as $delta => $value) { |
1876 | - $field_mask = (isset($update['delta']) && isset($update['alt_mask']) && $delta >= $update['delta']) ? $update['alt_mask'] : $mask['mask']; |
|
1877 | - // Merge the mask into the field values to do the replacements. |
|
1878 | - $items[$delta] = array_merge($items[$delta], $field_mask); |
|
1876 | + $field_mask = (isset($update['delta']) && isset($update['alt_mask']) && $delta >= $update['delta']) ? $update['alt_mask'] : $mask['mask']; |
|
1877 | + // Merge the mask into the field values to do the replacements. |
|
1878 | + $items[$delta] = array_merge($items[$delta], $field_mask); |
|
1879 | 1879 | } |
1880 | 1880 | // Test if the new values will make items qualify as empty. |
1881 | 1881 | $items = content_set_empty($field, $items); |
1882 | 1882 | $node->$field_name = $items; |
1883 | - } |
|
1884 | - node_save($node); |
|
1885 | - return $node; |
|
1883 | + } |
|
1884 | + node_save($node); |
|
1885 | + return $node; |
|
1886 | 1886 | } |
1887 | 1887 | |
1888 | 1888 | /** |
1889 | 1889 | * Helper form element validator : integer. |
1890 | 1890 | */ |
1891 | 1891 | function _element_validate_integer($element, &$form_state) { |
1892 | - $value = $element['#value']; |
|
1893 | - if ($value !== '' && (!is_numeric($value) || intval($value) != $value)) { |
|
1892 | + $value = $element['#value']; |
|
1893 | + if ($value !== '' && (!is_numeric($value) || intval($value) != $value)) { |
|
1894 | 1894 | form_error($element, t('%name must be an integer.', array('%name' => $element['#title']))); |
1895 | - } |
|
1895 | + } |
|
1896 | 1896 | } |
1897 | 1897 | |
1898 | 1898 | /** |
1899 | 1899 | * Helper form element validator : integer > 0. |
1900 | 1900 | */ |
1901 | 1901 | function _element_validate_integer_positive($element, &$form_state) { |
1902 | - $value = $element['#value']; |
|
1903 | - if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value <= 0)) { |
|
1902 | + $value = $element['#value']; |
|
1903 | + if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value <= 0)) { |
|
1904 | 1904 | form_error($element, t('%name must be a positive integer.', array('%name' => $element['#title']))); |
1905 | - } |
|
1905 | + } |
|
1906 | 1906 | } |
1907 | 1907 | |
1908 | 1908 | /** |
1909 | 1909 | * Helper form element validator : number. |
1910 | 1910 | */ |
1911 | 1911 | function _element_validate_number($element, &$form_state) { |
1912 | - $value = $element['#value']; |
|
1913 | - if ($value != '' && !is_numeric($value)) { |
|
1912 | + $value = $element['#value']; |
|
1913 | + if ($value != '' && !is_numeric($value)) { |
|
1914 | 1914 | form_error($element, t('%name must be a number.', array('%name' => $element['#title']))); |
1915 | - } |
|
1915 | + } |
|
1916 | 1916 | } |
@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | // Make the description smaller |
28 | 28 | $row[] = array('data' => filter_xss_admin($type->description), 'class' => 'description'); |
29 | 29 | // Set the edit column. |
30 | - $row[] = array('data' => l(t('edit'), 'admin/content/node-type/'. $type_url_str)); |
|
30 | + $row[] = array('data' => l(t('edit'), 'admin/content/node-type/'.$type_url_str)); |
|
31 | 31 | // Set links for managing fields. |
32 | 32 | // TODO: a hook to allow other content modules to add more stuff? |
33 | - $row[] = array('data' => l(t('manage fields'), 'admin/content/node-type/'. $type_url_str .'/fields')); |
|
33 | + $row[] = array('data' => l(t('manage fields'), 'admin/content/node-type/'.$type_url_str.'/fields')); |
|
34 | 34 | // Set the delete column. |
35 | 35 | if ($type->custom) { |
36 | - $row[] = array('data' => l(t('delete'), 'admin/content/node-type/'. $type_url_str .'/delete')); |
|
36 | + $row[] = array('data' => l(t('delete'), 'admin/content/node-type/'.$type_url_str.'/delete')); |
|
37 | 37 | } |
38 | 38 | else { |
39 | 39 | $row[] = array('data' => ''); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | // Allow external modules alter the table headers and rows. |
47 | 47 | foreach (module_implements('content_types_overview_alter') as $module) { |
48 | - $function = $module .'_content_types_overview_alter'; |
|
48 | + $function = $module.'_content_types_overview_alter'; |
|
49 | 49 | $function($header, $rows); |
50 | 50 | } |
51 | 51 | |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | $rows[] = array(array('data' => t('No content types available.'), 'colspan' => '7', 'class' => 'message')); |
54 | 54 | } |
55 | 55 | |
56 | - return theme('table', $header, $rows) .theme('content_overview_links'); |
|
56 | + return theme('table', $header, $rows).theme('content_overview_links'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function theme_content_overview_links() { |
60 | - return '<div class="content-overview-links">'. l(t('» Add a new content type'), 'admin/content/types/add') .'</div>'; |
|
60 | + return '<div class="content-overview-links">'.l(t('» Add a new content type'), 'admin/content/types/add').'</div>'; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $row[] = t($field_types[$field['type']]['label']); |
79 | 79 | |
80 | 80 | $types = array(); |
81 | - $result = db_query("SELECT nt.name, nt.type FROM {". content_instance_tablename() ."} nfi ". |
|
81 | + $result = db_query("SELECT nt.name, nt.type FROM {".content_instance_tablename()."} nfi ". |
|
82 | 82 | "LEFT JOIN {node_type} nt ON nt.type = nfi.type_name ". |
83 | 83 | "WHERE nfi.field_name = '%s' ". |
84 | 84 | // Keep disabled modules out of table. |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | "ORDER BY nt.name ASC", $field['field_name']); |
87 | 87 | while ($type = db_fetch_array($result)) { |
88 | 88 | $content_type = content_types($type['type']); |
89 | - $types[] = l($type['name'], 'admin/content/node-type/'. $content_type['url_str'] .'/fields'); |
|
89 | + $types[] = l($type['name'], 'admin/content/node-type/'.$content_type['url_str'].'/fields'); |
|
90 | 90 | } |
91 | 91 | $row[] = implode(', ', $types); |
92 | 92 | |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | 'label' => array('#value' => check_plain($field['widget']['label'])), |
174 | 174 | 'field_name' => array('#value' => $field['field_name']), |
175 | 175 | 'type' => array('#value' => t($field_types[$field['type']]['label'])), |
176 | - 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'])), |
|
177 | - 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/remove')), |
|
176 | + 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'.$type['url_str'].'/fields/'.$field['field_name'])), |
|
177 | + 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'.$type['url_str'].'/fields/'.$field['field_name'].'/remove')), |
|
178 | 178 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
179 | 179 | 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
180 | 180 | 'prev_parent' => array('#type' => 'hidden', '#value' => ''), |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | 'label' => array('#value' => check_plain($group['label'])), |
200 | 200 | 'group_name' => array('#value' => $group['group_name']), |
201 | 201 | 'group_type' => array('#value' => t($group_types[$group['group_type']])), |
202 | - 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'])), |
|
203 | - 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'. $type['url_str'] .'/groups/'. $group['group_name'] .'/remove')), |
|
202 | + 'configure' => array('#value' => l(t('Configure'), 'admin/content/node-type/'.$type['url_str'].'/groups/'.$group['group_name'])), |
|
203 | + 'remove' => array('#value' => l(t('Remove'), 'admin/content/node-type/'.$type['url_str'].'/groups/'.$group['group_name'].'/remove')), |
|
204 | 204 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
205 | 205 | 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
206 | 206 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $group['group_name']), |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | 'type' => array( |
267 | 267 | '#type' => 'select', |
268 | 268 | '#options' => $field_type_options, |
269 | - '#description' => theme('advanced_help_topic', 'content', 'fields') . t('Type of data to store.'), |
|
269 | + '#description' => theme('advanced_help_topic', 'content', 'fields').t('Type of data to store.'), |
|
270 | 270 | ), |
271 | 271 | 'widget_type' => array( |
272 | 272 | '#type' => 'select', |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | |
398 | 398 | // Add the 'field_' prefix. |
399 | 399 | if (substr($field_name, 0, 6) != 'field_') { |
400 | - $field_name = 'field_'. $field_name; |
|
400 | + $field_name = 'field_'.$field_name; |
|
401 | 401 | form_set_value($form['_add_new_field']['field_name'], $field_name, $form_state); |
402 | 402 | } |
403 | 403 | |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | foreach ($form_values as $key => $values) { |
495 | 495 | // Groups are handled in fieldgroup_content_overview_form_submit(). |
496 | 496 | if (in_array($key, $form['#fields'])) { |
497 | - db_query("UPDATE {". content_instance_tablename() ."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", |
|
497 | + db_query("UPDATE {".content_instance_tablename()."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", |
|
498 | 498 | $values['weight'], $type_name, $key); |
499 | 499 | } |
500 | 500 | elseif (in_array($key, $form['#extra'])) { |
@@ -503,10 +503,10 @@ discard block |
||
503 | 503 | } |
504 | 504 | |
505 | 505 | if ($extra) { |
506 | - variable_set('content_extra_weights_'. $type_name, $extra); |
|
506 | + variable_set('content_extra_weights_'.$type_name, $extra); |
|
507 | 507 | } |
508 | 508 | else { |
509 | - variable_del('content_extra_weights_'. $type_name); |
|
509 | + variable_del('content_extra_weights_'.$type_name); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | content_clear_type_cache(); |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | if (content_field_instance_create($field)) { |
523 | 523 | // Store new field information for fieldgroup submit handler. |
524 | 524 | $form_state['fields_added']['_add_new_field'] = $field['field_name']; |
525 | - $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
|
525 | + $destinations[] = 'admin/content/node-type/'.$type['url_str'].'/fields/'.$field['field_name']; |
|
526 | 526 | } |
527 | 527 | else { |
528 | 528 | drupal_set_message(t('There was a problem creating field %label.', array( |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | if (content_field_instance_create($field)) { |
545 | 545 | // Store new field information for fieldgroup submit handler. |
546 | 546 | $form_state['fields_added']['_add_existing_field'] = $field['field_name']; |
547 | - $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
|
547 | + $destinations[] = 'admin/content/node-type/'.$type['url_str'].'/fields/'.$field['field_name']; |
|
548 | 548 | } |
549 | 549 | else { |
550 | 550 | drupal_set_message(t('There was a problem adding field %label.', array('%label' => $field['field_name']))); |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | |
591 | 591 | if (empty($fields)) { |
592 | 592 | drupal_set_message(t('There are no fields configured for this content type. You can add new fields on the <a href="@link">Manage fields</a> page.', array( |
593 | - '@link' => url('admin/content/node-type/'. $type['url_str'] .'/fields'))), 'warning'); |
|
593 | + '@link' => url('admin/content/node-type/'.$type['url_str'].'/fields'))), 'warning'); |
|
594 | 594 | return $form; |
595 | 595 | } |
596 | 596 | |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | if (!isset($type['fields'][$field['field_name']]) && !$field['locked']) { |
784 | 784 | $field_type = $field_types[$field['type']]; |
785 | 785 | $text = t('@type: @field (@label)', array('@type' => t($field_type['label']), '@label' => t($field['widget']['label']), '@field' => $field['field_name'])); |
786 | - $options[$field['field_name']] = (drupal_strlen($text) > 80) ? truncate_utf8($text, 77) . '...' : $text; |
|
786 | + $options[$field['field_name']] = (drupal_strlen($text) > 80) ? truncate_utf8($text, 77).'...' : $text; |
|
787 | 787 | } |
788 | 788 | } |
789 | 789 | // Sort the list by type, then by field name, then by label. |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | } |
886 | 886 | |
887 | 887 | $type = content_types($form_values['type_name']); |
888 | - $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $form_values['field_name']; |
|
888 | + $form_state['redirect'] = 'admin/content/node-type/'.$type['url_str'].'/fields/'.$form_values['field_name']; |
|
889 | 889 | $form_state['rebuild'] = FALSE; |
890 | 890 | } |
891 | 891 | |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | |
909 | 909 | $output = confirm_form($form, |
910 | 910 | t('Are you sure you want to remove the field %field?', array('%field' => $field['widget']['label'])), |
911 | - 'admin/content/node-type/'. $type['url_str'] .'/fields', |
|
911 | + 'admin/content/node-type/'.$type['url_str'].'/fields', |
|
912 | 912 | t('If you have any content left in this field, it will be lost. This action cannot be undone.'), |
913 | 913 | t('Remove'), t('Cancel'), |
914 | 914 | 'confirm' |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | '%field' => $field['widget']['label'], |
947 | 947 | '%type' => $type['name']))); |
948 | 948 | } |
949 | - $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; |
|
949 | + $form_state['redirect'] = 'admin/content/node-type/'.$type['url_str'].'/fields'; |
|
950 | 950 | } |
951 | 951 | } |
952 | 952 | |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | '#default_value' => $field['widget']['weight'], |
1043 | 1043 | ); |
1044 | 1044 | |
1045 | - $additions = (array) module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget']); |
|
1045 | + $additions = (array)module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget']); |
|
1046 | 1046 | drupal_alter('widget_settings', $additions, 'form', $field['widget']); |
1047 | 1047 | $form['widget'] = array_merge($form['widget'], $additions); |
1048 | 1048 | |
@@ -1083,7 +1083,7 @@ discard block |
||
1083 | 1083 | ); |
1084 | 1084 | |
1085 | 1085 | // Default value widget. |
1086 | - $widget_form = array('#node' => (object) array('type' => $type_name)); |
|
1086 | + $widget_form = array('#node' => (object)array('type' => $type_name)); |
|
1087 | 1087 | $widget_form_state = array('values' => array($field['field_name'] => $default_value)); |
1088 | 1088 | // Make sure the default value is not a required field. |
1089 | 1089 | $widget_field = $field; |
@@ -1127,7 +1127,7 @@ discard block |
||
1127 | 1127 | $form['widget']['default_value_fieldset']['advanced_options']['markup_default_value_php'] = array( |
1128 | 1128 | '#type' => 'item', |
1129 | 1129 | '#title' => t('Code'), |
1130 | - '#value' => !empty($field['widget']['default_value_php']) ? '<code>'. check_plain($field['widget']['default_value_php']) .'</code>' : t('<none>'), |
|
1130 | + '#value' => !empty($field['widget']['default_value_php']) ? '<code>'.check_plain($field['widget']['default_value_php']).'</code>' : t('<none>'), |
|
1131 | 1131 | '#description' => empty($field['widget']['default_value_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override any value specified above.'), |
1132 | 1132 | ); |
1133 | 1133 | } |
@@ -1145,9 +1145,9 @@ discard block |
||
1145 | 1145 | ); |
1146 | 1146 | $description = t('Maximum number of values users can enter for this field.'); |
1147 | 1147 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
1148 | - $description .= '<br/>'. t("'Unlimited' will provide an 'Add more' button so the users can add as many values as they like."); |
|
1148 | + $description .= '<br/>'.t("'Unlimited' will provide an 'Add more' button so the users can add as many values as they like."); |
|
1149 | 1149 | } |
1150 | - $description .= '<br/><strong>'. t('Warning! Changing this setting after data has been created could result in the loss of data!') .'</strong>'; |
|
1150 | + $description .= '<br/><strong>'.t('Warning! Changing this setting after data has been created could result in the loss of data!').'</strong>'; |
|
1151 | 1151 | $form['field']['multiple'] = array( |
1152 | 1152 | '#type' => 'select', |
1153 | 1153 | '#title' => t('Number of values'), |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | '#value' => serialize($field), |
1162 | 1162 | ); |
1163 | 1163 | |
1164 | - $additions = (array) module_invoke($field_type['module'], 'field_settings', 'form', $field); |
|
1164 | + $additions = (array)module_invoke($field_type['module'], 'field_settings', 'form', $field); |
|
1165 | 1165 | drupal_alter('field_settings', $additions, 'form', $field); |
1166 | 1166 | $form['field'] = array_merge($form['field'], $additions); |
1167 | 1167 | |
@@ -1290,7 +1290,7 @@ discard block |
||
1290 | 1290 | $node = array(); |
1291 | 1291 | $node[$form_values['field_name']] = $default_value; |
1292 | 1292 | $field['required'] = FALSE; |
1293 | - $field_function = $field_type['module'] .'_field'; |
|
1293 | + $field_function = $field_type['module'].'_field'; |
|
1294 | 1294 | |
1295 | 1295 | $errors_before = form_get_errors(); |
1296 | 1296 | |
@@ -1341,7 +1341,7 @@ discard block |
||
1341 | 1341 | else { |
1342 | 1342 | drupal_set_message(t('Saved field %label.', array('%label' => $form_values['label']))); |
1343 | 1343 | $type = content_types($form_values['type_name']); |
1344 | - $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; |
|
1344 | + $form_state['redirect'] = 'admin/content/node-type/'.$type['url_str'].'/fields'; |
|
1345 | 1345 | } |
1346 | 1346 | } |
1347 | 1347 | |
@@ -1518,7 +1518,7 @@ discard block |
||
1518 | 1518 | // drop all delta values higher than the new maximum delta value. |
1519 | 1519 | // Not needed if the new multiple is unlimited or if the new table is the content table. |
1520 | 1520 | if ($new_table != $base_tablename && $new_field['multiple'] < $previous_field['multiple'] && $new_field['multiple'] != 1) { |
1521 | - db_query("DELETE FROM {". $new_table ."} WHERE delta >= ". max(1, $new_field['multiple'])); |
|
1521 | + db_query("DELETE FROM {".$new_table."} WHERE delta >= ".max(1, $new_field['multiple'])); |
|
1522 | 1522 | } |
1523 | 1523 | |
1524 | 1524 | // If going from multiple to non-multiple, make sure the field tables have |
@@ -1548,12 +1548,12 @@ discard block |
||
1548 | 1548 | $new_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
1549 | 1549 | $columns = array_keys($migrate_columns); |
1550 | 1550 | if ($new_field['multiple']) { |
1551 | - db_query('INSERT INTO {'. $new_table .'} (vid, nid, delta, '. implode(', ', $columns) .') '. |
|
1552 | - ' SELECT vid, nid, 0, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
|
1551 | + db_query('INSERT INTO {'.$new_table.'} (vid, nid, delta, '.implode(', ', $columns).') '. |
|
1552 | + ' SELECT vid, nid, 0, '.implode(', ', $columns).' FROM {'.$previous_table.'}'); |
|
1553 | 1553 | } |
1554 | 1554 | else { |
1555 | - db_query('INSERT INTO {'. $new_table .'} (vid, nid, '. implode(', ', $columns) .') '. |
|
1556 | - ' SELECT vid, nid, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
|
1555 | + db_query('INSERT INTO {'.$new_table.'} (vid, nid, '.implode(', ', $columns).') '. |
|
1556 | + ' SELECT vid, nid, '.implode(', ', $columns).' FROM {'.$previous_table.'}'); |
|
1557 | 1557 | } |
1558 | 1558 | foreach ($columns as $column_name) { |
1559 | 1559 | db_drop_field($ret, $previous_table, $column_name); |
@@ -1567,10 +1567,10 @@ discard block |
||
1567 | 1567 | // rebuild the schema now. |
1568 | 1568 | content_alter_db_cleanup(); |
1569 | 1569 | if ($previous_field['multiple']) { |
1570 | - $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE delta = 0 AND n.type = '%s'", $new_field['type_name']); |
|
1570 | + $result = db_query("SELECT * FROM {".$previous_table."} c JOIN {node} n ON c.nid = n.nid WHERE delta = 0 AND n.type = '%s'", $new_field['type_name']); |
|
1571 | 1571 | } |
1572 | 1572 | else { |
1573 | - $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s'", $new_field['type_name']); |
|
1573 | + $result = db_query("SELECT * FROM {".$previous_table."} c JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s'", $new_field['type_name']); |
|
1574 | 1574 | } |
1575 | 1575 | $record = array(); |
1576 | 1576 | while ($data = db_fetch_array($result)) { |
@@ -1591,7 +1591,7 @@ discard block |
||
1591 | 1591 | } |
1592 | 1592 | } |
1593 | 1593 | } |
1594 | - if (db_result(db_query('SELECT COUNT(*) FROM {'. $new_table . |
|
1594 | + if (db_result(db_query('SELECT COUNT(*) FROM {'.$new_table. |
|
1595 | 1595 | '} WHERE vid = %d AND nid = %d', $data['vid'], $data['nid']))) { |
1596 | 1596 | $keys = $new_field['multiple'] ? array('vid', 'delta') : array('vid'); |
1597 | 1597 | drupal_write_record($new_table, $record, $keys); |
@@ -1656,12 +1656,12 @@ discard block |
||
1656 | 1656 | // Group rows: account for weight. |
1657 | 1657 | if (module_exists('fieldgroup')) { |
1658 | 1658 | foreach ($group_rows as $name) { |
1659 | - $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name .' '); |
|
1659 | + $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name.' '); |
|
1660 | 1660 | } |
1661 | 1661 | } |
1662 | 1662 | // Field rows : account for weight and parenting. |
1663 | 1663 | foreach ($field_rows as $name) { |
1664 | - $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name .' '); |
|
1664 | + $dummy[$name] = array('#weight' => $form[$name]['weight']['#value'], '#value' => $name.' '); |
|
1665 | 1665 | if (module_exists('fieldgroup')) { |
1666 | 1666 | if ($parent = $form[$name]['parent']['#value']) { |
1667 | 1667 | $form[$name]['#depth'] = 1; |
@@ -1706,7 +1706,7 @@ discard block |
||
1706 | 1706 | 'finished' => '_content_alter_fields_finished', |
1707 | 1707 | 'title' => t('Processing'), |
1708 | 1708 | 'error_message' => t('The update has encountered an error.'), |
1709 | - 'file' => './'. drupal_get_path('module', 'content') .'/includes/content.admin.inc', |
|
1709 | + 'file' => './'.drupal_get_path('module', 'content').'/includes/content.admin.inc', |
|
1710 | 1710 | ); |
1711 | 1711 | batch_set($batch); |
1712 | 1712 | if (!empty($url)) { |
@@ -1802,7 +1802,7 @@ discard block |
||
1802 | 1802 | return $context['finished'] = 1; |
1803 | 1803 | } |
1804 | 1804 | $nodes = array(); |
1805 | - $result = db_query("SELECT nid FROM {". $db_info['table'] ."}"); |
|
1805 | + $result = db_query("SELECT nid FROM {".$db_info['table']."}"); |
|
1806 | 1806 | while ($node = db_fetch_array($result)) { |
1807 | 1807 | $nodes[] = $node['nid']; |
1808 | 1808 | } |
@@ -1821,7 +1821,7 @@ discard block |
||
1821 | 1821 | $node = content_field_replace($nid, array($updates)); |
1822 | 1822 | |
1823 | 1823 | // Store result for post-processing in the finished callback. |
1824 | - $context['results'][] = l($node->title, 'node/'. $node->nid); |
|
1824 | + $context['results'][] = l($node->title, 'node/'.$node->nid); |
|
1825 | 1825 | |
1826 | 1826 | // Update our progress information. |
1827 | 1827 | $context['sandbox']['progress']++; |
@@ -1831,7 +1831,7 @@ discard block |
||
1831 | 1831 | // Inform the batch engine that we are not finished, |
1832 | 1832 | // and provide an estimation of the completion level we reached. |
1833 | 1833 | if ($context['sandbox']['progress'] != $context['sandbox']['max']) { |
1834 | - $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; |
|
1834 | + $context['finished'] = $context['sandbox']['progress']/$context['sandbox']['max']; |
|
1835 | 1835 | } |
1836 | 1836 | } |
1837 | 1837 |
@@ -34,8 +34,7 @@ discard block |
||
34 | 34 | // Set the delete column. |
35 | 35 | if ($type->custom) { |
36 | 36 | $row[] = array('data' => l(t('delete'), 'admin/content/node-type/'. $type_url_str .'/delete')); |
37 | - } |
|
38 | - else { |
|
37 | + } else { |
|
39 | 38 | $row[] = array('data' => ''); |
40 | 39 | } |
41 | 40 | |
@@ -94,8 +93,7 @@ discard block |
||
94 | 93 | } |
95 | 94 | if (empty($rows)) { |
96 | 95 | $output = t('No fields have been defined for any content type yet.'); |
97 | - } |
|
98 | - else { |
|
96 | + } else { |
|
99 | 97 | $output = theme('table', $header, $rows); |
100 | 98 | } |
101 | 99 | return $output; |
@@ -496,16 +494,14 @@ discard block |
||
496 | 494 | if (in_array($key, $form['#fields'])) { |
497 | 495 | db_query("UPDATE {". content_instance_tablename() ."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", |
498 | 496 | $values['weight'], $type_name, $key); |
499 | - } |
|
500 | - elseif (in_array($key, $form['#extra'])) { |
|
497 | + } elseif (in_array($key, $form['#extra'])) { |
|
501 | 498 | $extra[$key] = $values['weight']; |
502 | 499 | } |
503 | 500 | } |
504 | 501 | |
505 | 502 | if ($extra) { |
506 | 503 | variable_set('content_extra_weights_'. $type_name, $extra); |
507 | - } |
|
508 | - else { |
|
504 | + } else { |
|
509 | 505 | variable_del('content_extra_weights_'. $type_name); |
510 | 506 | } |
511 | 507 | |
@@ -523,8 +519,7 @@ discard block |
||
523 | 519 | // Store new field information for fieldgroup submit handler. |
524 | 520 | $form_state['fields_added']['_add_new_field'] = $field['field_name']; |
525 | 521 | $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
526 | - } |
|
527 | - else { |
|
522 | + } else { |
|
528 | 523 | drupal_set_message(t('There was a problem creating field %label.', array( |
529 | 524 | '%label' => $field['label']))); |
530 | 525 | } |
@@ -538,15 +533,13 @@ discard block |
||
538 | 533 | |
539 | 534 | if ($existing_field['locked']) { |
540 | 535 | drupal_set_message(t('The field %label cannot be added to a content type because it is locked.', array('%label' => $field['field_name']))); |
541 | - } |
|
542 | - else { |
|
536 | + } else { |
|
543 | 537 | module_load_include('inc', 'content', 'includes/content.crud'); |
544 | 538 | if (content_field_instance_create($field)) { |
545 | 539 | // Store new field information for fieldgroup submit handler. |
546 | 540 | $form_state['fields_added']['_add_existing_field'] = $field['field_name']; |
547 | 541 | $destinations[] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $field['field_name']; |
548 | - } |
|
549 | - else { |
|
542 | + } else { |
|
550 | 543 | drupal_set_message(t('There was a problem adding field %label.', array('%label' => $field['field_name']))); |
551 | 544 | } |
552 | 545 | } |
@@ -756,16 +749,14 @@ discard block |
||
756 | 749 | |
757 | 750 | if ($field_type) { |
758 | 751 | return !empty($options[$field_type]) ? $options[$field_type] : array(); |
759 | - } |
|
760 | - elseif ($by_label) { |
|
752 | + } elseif ($by_label) { |
|
761 | 753 | $field_types = _content_field_types(); |
762 | 754 | $options_by_label = array(); |
763 | 755 | foreach ($options as $field_type => $widgets) { |
764 | 756 | $options_by_label[t($field_types[$field_type]['label'])] = $widgets; |
765 | 757 | } |
766 | 758 | return $options_by_label; |
767 | - } |
|
768 | - else { |
|
759 | + } else { |
|
769 | 760 | return $options; |
770 | 761 | } |
771 | 762 | } |
@@ -878,8 +869,7 @@ discard block |
||
878 | 869 | if (content_field_instance_update($field)) { |
879 | 870 | drupal_set_message(t('Updated basic settings for field %label.', array( |
880 | 871 | '%label' => $label))); |
881 | - } |
|
882 | - else { |
|
872 | + } else { |
|
883 | 873 | drupal_set_message(t('There was a problem updating the basic settings for field %label.', array( |
884 | 874 | '%label' => $label))); |
885 | 875 | } |
@@ -940,8 +930,7 @@ discard block |
||
940 | 930 | drupal_set_message(t('Removed field %field from %type.', array( |
941 | 931 | '%field' => $field['widget']['label'], |
942 | 932 | '%type' => $type['name']))); |
943 | - } |
|
944 | - else { |
|
933 | + } else { |
|
945 | 934 | drupal_set_message(t('There was a problem deleting %field from %type.', array( |
946 | 935 | '%field' => $field['widget']['label'], |
947 | 936 | '%type' => $type['name']))); |
@@ -1122,8 +1111,7 @@ discard block |
||
1122 | 1111 | '@link_devel' => 'http://www.drupal.org/project/devel', |
1123 | 1112 | '%type' => $type_name)), |
1124 | 1113 | ); |
1125 | - } |
|
1126 | - else { |
|
1114 | + } else { |
|
1127 | 1115 | $form['widget']['default_value_fieldset']['advanced_options']['markup_default_value_php'] = array( |
1128 | 1116 | '#type' => 'item', |
1129 | 1117 | '#title' => t('Code'), |
@@ -1248,8 +1236,7 @@ discard block |
||
1248 | 1236 | ob_end_clean(); |
1249 | 1237 | if (!is_array($return)) { |
1250 | 1238 | $error = TRUE; |
1251 | - } |
|
1252 | - else { |
|
1239 | + } else { |
|
1253 | 1240 | foreach ($return as $item) { |
1254 | 1241 | if (!is_array($item)) { |
1255 | 1242 | $error = TRUE; |
@@ -1269,15 +1256,13 @@ discard block |
||
1269 | 1256 | '!sample' => $sample, |
1270 | 1257 | '@value' => print_r($return, TRUE)))); |
1271 | 1258 | return; |
1272 | - } |
|
1273 | - else { |
|
1259 | + } else { |
|
1274 | 1260 | $default_value = $return; |
1275 | 1261 | $is_code = TRUE; |
1276 | 1262 | form_set_value(array('#parents' => array('default_value_php')), $php, $form_state); |
1277 | 1263 | form_set_value(array('#parents' => array('default_value')), array(), $form_state); |
1278 | 1264 | } |
1279 | - } |
|
1280 | - elseif (!empty($form_values['default_value_widget'])) { |
|
1265 | + } elseif (!empty($form_values['default_value_widget'])) { |
|
1281 | 1266 | // Fields that handle their own multiple values may use an expected |
1282 | 1267 | // value as the top-level key, so just pop off the top element. |
1283 | 1268 | $key = array_shift(array_keys($form_values['default_value_widget'])); |
@@ -1306,8 +1291,7 @@ discard block |
||
1306 | 1291 | if (trim($form_values['default_value_php'])) { |
1307 | 1292 | form_set_error('default_value_php', t("The PHP code for 'default value' returned @value, which is invalid.", array( |
1308 | 1293 | '@value' => print_r($default_value, TRUE)))); |
1309 | - } |
|
1310 | - else { |
|
1294 | + } else { |
|
1311 | 1295 | form_set_error('default_value', t('The default value is invalid.')); |
1312 | 1296 | } |
1313 | 1297 | } |
@@ -1337,8 +1321,7 @@ discard block |
||
1337 | 1321 | if ($destinations) { |
1338 | 1322 | drupal_set_message(t('Added field %label.', array('%label' => $form_values['label']))); |
1339 | 1323 | $form_state['redirect'] = content_get_destinations($destinations); |
1340 | - } |
|
1341 | - else { |
|
1324 | + } else { |
|
1342 | 1325 | drupal_set_message(t('Saved field %label.', array('%label' => $form_values['label']))); |
1343 | 1326 | $type = content_types($form_values['type_name']); |
1344 | 1327 | $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; |
@@ -1455,8 +1438,7 @@ discard block |
||
1455 | 1438 | if (empty($new_field)) { |
1456 | 1439 | if ($previous_field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
1457 | 1440 | db_drop_table($ret, $previous_table); |
1458 | - } |
|
1459 | - else { |
|
1441 | + } else { |
|
1460 | 1442 | foreach ($previous_schema['fields'] as $column => $attributes) { |
1461 | 1443 | if (!in_array($column, array('nid', 'vid', 'delta'))) { |
1462 | 1444 | db_drop_field($ret, $previous_table, $column); |
@@ -1478,8 +1460,7 @@ discard block |
||
1478 | 1460 | // Create new table and columns, if not already created. |
1479 | 1461 | if (!db_table_exists($new_table)) { |
1480 | 1462 | db_create_table($ret, $new_table, $new_schema); |
1481 | - } |
|
1482 | - else { |
|
1463 | + } else { |
|
1483 | 1464 | // Or add fields and/or indexes to an existing table. |
1484 | 1465 | foreach ($new_schema['fields'] as $column => $attributes) { |
1485 | 1466 | if (!in_array($column, array('nid', 'vid', 'delta'))) { |
@@ -1530,8 +1511,7 @@ discard block |
||
1530 | 1511 | db_drop_field($ret, $new_table, 'delta'); |
1531 | 1512 | db_drop_primary_key($ret, $new_table); |
1532 | 1513 | db_add_primary_key($ret, $new_table, array('vid')); |
1533 | - } |
|
1534 | - else if ($previous_field['multiple'] == 0 && $new_field['multiple'] > 0) { |
|
1514 | + } else if ($previous_field['multiple'] == 0 && $new_field['multiple'] > 0) { |
|
1535 | 1515 | db_add_field($ret, $new_table, 'delta', array( |
1536 | 1516 | 'type' => 'int', |
1537 | 1517 | 'unsigned' => TRUE, |
@@ -1550,8 +1530,7 @@ discard block |
||
1550 | 1530 | if ($new_field['multiple']) { |
1551 | 1531 | db_query('INSERT INTO {'. $new_table .'} (vid, nid, delta, '. implode(', ', $columns) .') '. |
1552 | 1532 | ' SELECT vid, nid, 0, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
1553 | - } |
|
1554 | - else { |
|
1533 | + } else { |
|
1555 | 1534 | db_query('INSERT INTO {'. $new_table .'} (vid, nid, '. implode(', ', $columns) .') '. |
1556 | 1535 | ' SELECT vid, nid, '. implode(', ', $columns) .' FROM {'. $previous_table .'}'); |
1557 | 1536 | } |
@@ -1568,8 +1547,7 @@ discard block |
||
1568 | 1547 | content_alter_db_cleanup(); |
1569 | 1548 | if ($previous_field['multiple']) { |
1570 | 1549 | $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE delta = 0 AND n.type = '%s'", $new_field['type_name']); |
1571 | - } |
|
1572 | - else { |
|
1550 | + } else { |
|
1573 | 1551 | $result = db_query("SELECT * FROM {". $previous_table ."} c JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s'", $new_field['type_name']); |
1574 | 1552 | } |
1575 | 1553 | $record = array(); |
@@ -1582,8 +1560,7 @@ discard block |
||
1582 | 1560 | foreach ($migrate_columns as $column => $attributes) { |
1583 | 1561 | if (is_null($data[$column])) { |
1584 | 1562 | $record[$column] = NULL; |
1585 | - } |
|
1586 | - else { |
|
1563 | + } else { |
|
1587 | 1564 | $record[$column] = $data[$column]; |
1588 | 1565 | // Prevent double serializtion in drupal_write_record. |
1589 | 1566 | if (isset($attributes['serialize']) && $attributes['serialize']) { |
@@ -1595,8 +1572,7 @@ discard block |
||
1595 | 1572 | '} WHERE vid = %d AND nid = %d', $data['vid'], $data['nid']))) { |
1596 | 1573 | $keys = $new_field['multiple'] ? array('vid', 'delta') : array('vid'); |
1597 | 1574 | drupal_write_record($new_table, $record, $keys); |
1598 | - } |
|
1599 | - else { |
|
1575 | + } else { |
|
1600 | 1576 | drupal_write_record($new_table, $record); |
1601 | 1577 | } |
1602 | 1578 | } |
@@ -1720,8 +1696,7 @@ discard block |
||
1720 | 1696 | function _content_alter_fields_finished($success, $results, $operations) { |
1721 | 1697 | if ($success) { |
1722 | 1698 | drupal_set_message(t('The database has been altered and data has been migrated or deleted.')); |
1723 | - } |
|
1724 | - else { |
|
1699 | + } else { |
|
1725 | 1700 | drupal_set_message(t('An error occurred and database alteration did not complete.'), 'error'); |
1726 | 1701 | $message = format_plural(count($results), '1 item successfully processed:', '@count items successfully processed:'); |
1727 | 1702 | $message .= theme('item_list', $results); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $weights = array(); |
158 | 158 | |
159 | 159 | $form = array( |
160 | - '#tree' => TRUE, |
|
160 | + '#tree' => true, |
|
161 | 161 | '#type_name' => $type['type'], |
162 | 162 | '#fields' => array_keys($fields), |
163 | 163 | '#groups' => array_keys($groups), |
@@ -179,14 +179,14 @@ discard block |
||
179 | 179 | 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
180 | 180 | 'prev_parent' => array('#type' => 'hidden', '#value' => ''), |
181 | 181 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $field['field_name']), |
182 | - '#leaf' => TRUE, |
|
182 | + '#leaf' => true, |
|
183 | 183 | '#row_type' => 'field', |
184 | 184 | 'field' => array('#type' => 'value', '#value' => $field), |
185 | 185 | ); |
186 | 186 | if ($field['locked']) { |
187 | 187 | $form[$name]['configure'] = array('#value' => t('Locked')); |
188 | 188 | $form[$name]['remove'] = array(); |
189 | - $form[$name]['#disabled_row'] = TRUE; |
|
189 | + $form[$name]['#disabled_row'] = true; |
|
190 | 190 | } |
191 | 191 | $form['#field_rows'][] = $name; |
192 | 192 | $weights[] = $weight; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
205 | 205 | 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
206 | 206 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $group['group_name']), |
207 | - '#root' => TRUE, |
|
207 | + '#root' => true, |
|
208 | 208 | '#row_type' => 'group', |
209 | 209 | 'group' => array('#type' => 'value', '#value' => $group), |
210 | 210 | ); |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | 'configure' => array('#value' => isset($extra[$name]['configure']) ? $extra[$name]['configure'] : ''), |
229 | 229 | 'remove' => array('#value' => isset($extra[$name]['remove']) ? $extra[$name]['remove'] : ''), |
230 | 230 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
231 | - '#leaf' => TRUE, |
|
232 | - '#root' => TRUE, |
|
233 | - '#disabled_row' => TRUE, |
|
231 | + '#leaf' => true, |
|
232 | + '#root' => true, |
|
233 | + '#disabled_row' => true, |
|
234 | 234 | '#row_type' => 'extra', |
235 | 235 | ); |
236 | 236 | $form['#field_rows'][] = $name; |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | // Additional row : add new field. |
241 | 241 | $weight = max($weights) + 1; |
242 | 242 | $field_type_options = content_field_type_options(); |
243 | - $widget_type_options = content_widget_type_options(NULL, TRUE); |
|
243 | + $widget_type_options = content_widget_type_options(null, true); |
|
244 | 244 | if ($field_type_options && $widget_type_options) { |
245 | 245 | array_unshift($field_type_options, t('- Select a field type -')); |
246 | 246 | array_unshift($widget_type_options, t('- Select a widget -')); |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
277 | 277 | 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
278 | 278 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
279 | - '#leaf' => TRUE, |
|
280 | - '#add_new' => TRUE, |
|
279 | + '#leaf' => true, |
|
280 | + '#add_new' => true, |
|
281 | 281 | '#row_type' => 'add_new_field', |
282 | 282 | ); |
283 | 283 | $form['#field_rows'][] = $name; |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
309 | 309 | 'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''), |
310 | 310 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
311 | - '#leaf' => TRUE, |
|
312 | - '#add_new' => TRUE, |
|
311 | + '#leaf' => true, |
|
312 | + '#add_new' => true, |
|
313 | 313 | '#row_type' => 'add_existing_field', |
314 | 314 | ); |
315 | 315 | $form['#field_rows'][] = $name; |
@@ -348,8 +348,8 @@ discard block |
||
348 | 348 | 'weight' => array('#type' => 'textfield', '#default_value' => $weight, '#size' => 3), |
349 | 349 | 'parent' => array('#type' => 'hidden', '#default_value' => ''), |
350 | 350 | 'hidden_name' => array('#type' => 'hidden', '#default_value' => $name), |
351 | - '#root' => TRUE, |
|
352 | - '#add_new' => TRUE, |
|
351 | + '#root' => true, |
|
352 | + '#add_new' => true, |
|
353 | 353 | '#row_type' => 'add_new_group', |
354 | 354 | ); |
355 | 355 | if (count($group_types) > 1) { |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | // Field name already exists. |
417 | 417 | // We need to check inactive fields as well, so we can't use content_fields(). |
418 | 418 | module_load_include('inc', 'content', 'includes/content.crud'); |
419 | - $fields = content_field_instance_read(array(), TRUE); |
|
420 | - $used = FALSE; |
|
419 | + $fields = content_field_instance_read(array(), true); |
|
420 | + $used = false; |
|
421 | 421 | foreach ($fields as $existing_field) { |
422 | 422 | $used |= ($existing_field['field_name'] == $field_name); |
423 | 423 | } |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | $contexts = content_build_modes($contexts_selector); |
582 | 582 | |
583 | 583 | $form = array( |
584 | - '#tree' => TRUE, |
|
584 | + '#tree' => true, |
|
585 | 585 | '#type_name' => $type['type'], |
586 | 586 | '#fields' => array_keys($fields), |
587 | 587 | '#groups' => array_keys($groups), |
@@ -704,12 +704,12 @@ discard block |
||
704 | 704 | $field = content_fields($key, $form['#type_name']); |
705 | 705 | // We have some numeric keys here, so we can't use array_merge. |
706 | 706 | $field['display_settings'] = $values + $field['display_settings']; |
707 | - content_field_instance_update($field, FALSE); |
|
707 | + content_field_instance_update($field, false); |
|
708 | 708 | } |
709 | 709 | } |
710 | 710 | |
711 | 711 | // Clear caches and rebuild menu. |
712 | - content_clear_type_cache(TRUE); |
|
712 | + content_clear_type_cache(true); |
|
713 | 713 | menu_rebuild(); |
714 | 714 | |
715 | 715 | drupal_set_message(t('Your settings have been saved.')); |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | * If no field type is provided, returns a nested array of |
743 | 743 | * all widget types, keyed by field type human name |
744 | 744 | */ |
745 | -function content_widget_type_options($field_type = NULL, $by_label = FALSE) { |
|
745 | +function content_widget_type_options($field_type = null, $by_label = false) { |
|
746 | 746 | static $options; |
747 | 747 | |
748 | 748 | if (!isset($options)) { |
@@ -815,13 +815,13 @@ discard block |
||
815 | 815 | '#type' => 'textfield', |
816 | 816 | '#value' => $field_name, |
817 | 817 | '#description' => t("The machine-readable name of the field. This name cannot be changed."), |
818 | - '#disabled' => TRUE, |
|
818 | + '#disabled' => true, |
|
819 | 819 | ); |
820 | 820 | $form['basic']['label'] = array( |
821 | 821 | '#type' => 'textfield', |
822 | 822 | '#title' => t('Label'), |
823 | 823 | '#default_value' => $label, |
824 | - '#required' => TRUE, |
|
824 | + '#required' => true, |
|
825 | 825 | '#description' => t('A human-readable name to be used as the label for this field in the %type content type.', array('%type' => $type['name'])), |
826 | 826 | ); |
827 | 827 | $form['basic']['type'] = array( |
@@ -830,12 +830,12 @@ discard block |
||
830 | 830 | '#options' => content_field_type_options(), |
831 | 831 | '#default_value' => $field_type, |
832 | 832 | '#description' => t('The type of data you would like to store in the database with this field. This option cannot be changed.'), |
833 | - '#disabled' => TRUE, |
|
833 | + '#disabled' => true, |
|
834 | 834 | ); |
835 | 835 | $form['basic']['widget_type'] = array( |
836 | 836 | '#type' => 'select', |
837 | 837 | '#title' => t('Widget type'), |
838 | - '#required' => TRUE, |
|
838 | + '#required' => true, |
|
839 | 839 | '#options' => content_widget_type_options($field_type), |
840 | 840 | '#default_value' => $form_values['widget_type'], |
841 | 841 | '#description' => t('The type of form element you would like to present to the user when creating this field in the %type content type.', array('%type' => $type['name'])), |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | |
887 | 887 | $type = content_types($form_values['type_name']); |
888 | 888 | $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields/'. $form_values['field_name']; |
889 | - $form_state['rebuild'] = FALSE; |
|
889 | + $form_state['rebuild'] = false; |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
@@ -985,7 +985,7 @@ discard block |
||
985 | 985 | |
986 | 986 | // Remove menu tabs when we are in an 'add new' sequence. |
987 | 987 | if ($add_new_sequence) { |
988 | - menu_set_item(NULL, menu_get_item('node')); |
|
988 | + menu_set_item(null, menu_get_item('node')); |
|
989 | 989 | } |
990 | 990 | |
991 | 991 | $form = array(); |
@@ -1002,19 +1002,19 @@ discard block |
||
1002 | 1002 | '#type' => 'textfield', |
1003 | 1003 | '#title' => t('Label'), |
1004 | 1004 | '#value' => $field['widget']['label'], |
1005 | - '#disabled' => TRUE, |
|
1005 | + '#disabled' => true, |
|
1006 | 1006 | ); |
1007 | 1007 | $form['basic']['field_name'] = array( |
1008 | 1008 | '#type' => 'hidden', |
1009 | 1009 | '#title' => t('Field name'), |
1010 | 1010 | '#value' => $field['field_name'], |
1011 | - '#disabled' => TRUE, |
|
1011 | + '#disabled' => true, |
|
1012 | 1012 | ); |
1013 | 1013 | $form['basic']['type'] = array( |
1014 | 1014 | '#type' => 'hidden', |
1015 | 1015 | '#title' => t('Field type'), |
1016 | 1016 | '#value' => $field['type'], |
1017 | - '#disabled' => TRUE, |
|
1017 | + '#disabled' => true, |
|
1018 | 1018 | ); |
1019 | 1019 | $widget_options = content_widget_type_options($field['type']); |
1020 | 1020 | $form['basic']['widget_type'] = array( |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | '#title' => t('Widget type'), |
1023 | 1023 | '#options' => $widget_options, |
1024 | 1024 | '#default_value' => $field['widget']['type'] ? $field['widget']['type'] : key($widget_options), |
1025 | - '#disabled' => TRUE, |
|
1025 | + '#disabled' => true, |
|
1026 | 1026 | ); |
1027 | 1027 | $form['basic']['change'] = array( |
1028 | 1028 | '#type' => 'submit', |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | '#default_value' => $field['widget']['description'], |
1053 | 1053 | '#rows' => 5, |
1054 | 1054 | '#description' => t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => _content_filter_xss_display_allowed_tags())), |
1055 | - '#required' => FALSE, |
|
1055 | + '#required' => false, |
|
1056 | 1056 | ); |
1057 | 1057 | |
1058 | 1058 | // Add handling for default value if not provided by field. |
@@ -1078,8 +1078,8 @@ discard block |
||
1078 | 1078 | $form['widget']['default_value_fieldset'] = array( |
1079 | 1079 | '#type' => 'fieldset', |
1080 | 1080 | '#title' => t('Default value'), |
1081 | - '#collapsible' => TRUE, |
|
1082 | - '#collapsed' => TRUE, |
|
1081 | + '#collapsible' => true, |
|
1082 | + '#collapsed' => true, |
|
1083 | 1083 | ); |
1084 | 1084 | |
1085 | 1085 | // Default value widget. |
@@ -1087,11 +1087,11 @@ discard block |
||
1087 | 1087 | $widget_form_state = array('values' => array($field['field_name'] => $default_value)); |
1088 | 1088 | // Make sure the default value is not a required field. |
1089 | 1089 | $widget_field = $field; |
1090 | - $widget_field['required'] = FALSE; |
|
1090 | + $widget_field['required'] = false; |
|
1091 | 1091 | module_load_include('inc', 'content', 'includes/content.node_form'); |
1092 | 1092 | $form_element = content_field_form($widget_form, $widget_form_state, $widget_field, 0); |
1093 | 1093 | $form['widget']['default_value_fieldset']['default_value_widget'] = $form_element; |
1094 | - $form['widget']['default_value_fieldset']['default_value_widget']['#tree'] = TRUE; |
|
1094 | + $form['widget']['default_value_fieldset']['default_value_widget']['#tree'] = true; |
|
1095 | 1095 | // Set up form info that the default value widget will need to find in the form. |
1096 | 1096 | $form['#field_info'] = array($widget_field['field_name'] => $widget_field); |
1097 | 1097 | |
@@ -1099,7 +1099,7 @@ discard block |
||
1099 | 1099 | $form['widget']['default_value_fieldset']['advanced_options'] = array( |
1100 | 1100 | '#type' => 'fieldset', |
1101 | 1101 | '#title' => t('PHP code'), |
1102 | - '#collapsible' => TRUE, |
|
1102 | + '#collapsible' => true, |
|
1103 | 1103 | '#collapsed' => empty($field['widget']['default_value_php']), |
1104 | 1104 | ); |
1105 | 1105 | |
@@ -1116,7 +1116,7 @@ discard block |
||
1116 | 1116 | '#title' => t('Code'), |
1117 | 1117 | '#default_value' => isset($field['widget']['default_value_php']) ? $field['widget']['default_value_php'] : '', |
1118 | 1118 | '#rows' => 6, |
1119 | - '#tree' => TRUE, |
|
1119 | + '#tree' => true, |
|
1120 | 1120 | '#description' => t('Advanced usage only: PHP code that returns a default value. Should not include <?php ?> delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format: <pre>!sample</pre>To figure out the expected format, you can use the <em>devel load</em> tab provided by <a href="@link_devel">devel module</a> on a %type content page.', array( |
1121 | 1121 | '!sample' => $sample, |
1122 | 1122 | '@link_devel' => 'http://www.drupal.org/project/devel', |
@@ -1236,23 +1236,23 @@ discard block |
||
1236 | 1236 | // If this is a programmed form, get rid of the default value widget, |
1237 | 1237 | // we have the default values already. |
1238 | 1238 | if ($form['#programmed']) { |
1239 | - form_set_value(array('#parents' => array('default_value_widget')), NULL, $form_state); |
|
1239 | + form_set_value(array('#parents' => array('default_value_widget')), null, $form_state); |
|
1240 | 1240 | return; |
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | if (isset($form_values['default_value_php']) && |
1244 | 1244 | ($php = trim($form_values['default_value_php']))) { |
1245 | - $error = FALSE; |
|
1245 | + $error = false; |
|
1246 | 1246 | ob_start(); |
1247 | 1247 | $return = eval($php); |
1248 | 1248 | ob_end_clean(); |
1249 | 1249 | if (!is_array($return)) { |
1250 | - $error = TRUE; |
|
1250 | + $error = true; |
|
1251 | 1251 | } |
1252 | 1252 | else { |
1253 | 1253 | foreach ($return as $item) { |
1254 | 1254 | if (!is_array($item)) { |
1255 | - $error = TRUE; |
|
1255 | + $error = true; |
|
1256 | 1256 | break; |
1257 | 1257 | } |
1258 | 1258 | } |
@@ -1267,12 +1267,12 @@ discard block |
||
1267 | 1267 | |
1268 | 1268 | form_set_error('default_value_php', t('The default value PHP code returned an incorrect value.<br/>Expected format: <pre>!sample</pre> Returned value: @value', array( |
1269 | 1269 | '!sample' => $sample, |
1270 | - '@value' => print_r($return, TRUE)))); |
|
1270 | + '@value' => print_r($return, true)))); |
|
1271 | 1271 | return; |
1272 | 1272 | } |
1273 | 1273 | else { |
1274 | 1274 | $default_value = $return; |
1275 | - $is_code = TRUE; |
|
1275 | + $is_code = true; |
|
1276 | 1276 | form_set_value(array('#parents' => array('default_value_php')), $php, $form_state); |
1277 | 1277 | form_set_value(array('#parents' => array('default_value')), array(), $form_state); |
1278 | 1278 | } |
@@ -1282,14 +1282,14 @@ discard block |
||
1282 | 1282 | // value as the top-level key, so just pop off the top element. |
1283 | 1283 | $key = array_shift(array_keys($form_values['default_value_widget'])); |
1284 | 1284 | $default_value = $form_values['default_value_widget'][$key]; |
1285 | - $is_code = FALSE; |
|
1285 | + $is_code = false; |
|
1286 | 1286 | form_set_value(array('#parents' => array('default_value_php')), '', $form_state); |
1287 | 1287 | form_set_value(array('#parents' => array('default_value')), $default_value, $form_state); |
1288 | 1288 | } |
1289 | 1289 | if (isset($default_value)) { |
1290 | 1290 | $node = array(); |
1291 | 1291 | $node[$form_values['field_name']] = $default_value; |
1292 | - $field['required'] = FALSE; |
|
1292 | + $field['required'] = false; |
|
1293 | 1293 | $field_function = $field_type['module'] .'_field'; |
1294 | 1294 | |
1295 | 1295 | $errors_before = form_get_errors(); |
@@ -1297,7 +1297,7 @@ discard block |
||
1297 | 1297 | // Widget now does its own validation, should be no need |
1298 | 1298 | // to add anything for widget validation here. |
1299 | 1299 | if (function_exists($field_function)) { |
1300 | - $field_function('validate', $node, $field, $default_value, $form, NULL); |
|
1300 | + $field_function('validate', $node, $field, $default_value, $form, null); |
|
1301 | 1301 | } |
1302 | 1302 | // The field validation routine won't set an error on the right field, |
1303 | 1303 | // so set it here. |
@@ -1305,7 +1305,7 @@ discard block |
||
1305 | 1305 | if (count($errors_after) > count($errors_before)) { |
1306 | 1306 | if (trim($form_values['default_value_php'])) { |
1307 | 1307 | form_set_error('default_value_php', t("The PHP code for 'default value' returned @value, which is invalid.", array( |
1308 | - '@value' => print_r($default_value, TRUE)))); |
|
1308 | + '@value' => print_r($default_value, true)))); |
|
1309 | 1309 | } |
1310 | 1310 | else { |
1311 | 1311 | form_set_error('default_value', t('The default value is invalid.')); |
@@ -1319,8 +1319,8 @@ discard block |
||
1319 | 1319 | * Button submit handler. |
1320 | 1320 | */ |
1321 | 1321 | function content_field_edit_form_submit_update_basic($form, &$form_state) { |
1322 | - $form_state['change_basic'] = TRUE; |
|
1323 | - $form_state['rebuild'] = TRUE; |
|
1322 | + $form_state['change_basic'] = true; |
|
1323 | + $form_state['rebuild'] = true; |
|
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | /** |
@@ -1534,8 +1534,8 @@ discard block |
||
1534 | 1534 | else if ($previous_field['multiple'] == 0 && $new_field['multiple'] > 0) { |
1535 | 1535 | db_add_field($ret, $new_table, 'delta', array( |
1536 | 1536 | 'type' => 'int', |
1537 | - 'unsigned' => TRUE, |
|
1538 | - 'not null' => TRUE, |
|
1537 | + 'unsigned' => true, |
|
1538 | + 'not null' => true, |
|
1539 | 1539 | 'default' => 0)); |
1540 | 1540 | db_drop_primary_key($ret, $new_table); |
1541 | 1541 | db_add_primary_key($ret, $new_table, array('vid', 'delta')); |
@@ -1581,7 +1581,7 @@ discard block |
||
1581 | 1581 | } |
1582 | 1582 | foreach ($migrate_columns as $column => $attributes) { |
1583 | 1583 | if (is_null($data[$column])) { |
1584 | - $record[$column] = NULL; |
|
1584 | + $record[$column] = null; |
|
1585 | 1585 | } |
1586 | 1586 | else { |
1587 | 1587 | $record[$column] = $data[$column]; |
@@ -1639,7 +1639,7 @@ discard block |
||
1639 | 1639 | // TODO: this could be optimized. We don't need to rebuild in *every case*... |
1640 | 1640 | // Or do we? This affects the schema and menu and may have unfortunate |
1641 | 1641 | // delayed effects if we don't clear everything out at this point. |
1642 | - content_clear_type_cache(TRUE); |
|
1642 | + content_clear_type_cache(true); |
|
1643 | 1643 | } |
1644 | 1644 | |
1645 | 1645 | /** |
@@ -1752,11 +1752,11 @@ discard block |
||
1752 | 1752 | foreach (array_keys($previous_field['columns']) as $column_name) { |
1753 | 1753 | // The basic mask will empty the dropped columns. |
1754 | 1754 | if (isset($dropped['columns']) && in_array($column_name, $dropped['columns'])) { |
1755 | - $mask['mask'][$column_name] = NULL; |
|
1755 | + $mask['mask'][$column_name] = null; |
|
1756 | 1756 | } |
1757 | 1757 | // Over the delta we'll empty all columns. |
1758 | 1758 | if (isset($dropped['delta'])) { |
1759 | - $mask['alt_mask'][$column_name] = NULL; |
|
1759 | + $mask['alt_mask'][$column_name] = null; |
|
1760 | 1760 | } |
1761 | 1761 | } |
1762 | 1762 | if (isset($dropped['delta'])) { |
@@ -1869,7 +1869,7 @@ discard block |
||
1869 | 1869 | * ), |
1870 | 1870 | */ |
1871 | 1871 | function content_field_replace($nid, $updates) { |
1872 | - $node = node_load($nid, NULL, TRUE); |
|
1872 | + $node = node_load($nid, null, true); |
|
1873 | 1873 | foreach ($updates as $field_name => $update) { |
1874 | 1874 | $items = isset($node->$field_name) ? $node->$field_name : array(); |
1875 | 1875 | foreach ($items as $delta => $value) { |