textarea.inc
6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* @file
* Webform module textarea component.
*/
/**
* Implements _webform_defaults_component().
*/
function _webform_defaults_textarea() {
return array(
'name' => '',
'form_key' => NULL,
'pid' => 0,
'weight' => 0,
'value' => '',
'mandatory' => 0,
'extra' => array(
'cols' => '',
'rows' => '',
'title_display' => 0,
'resizable' => 1,
'disabled' => 0,
'description' => '',
'attributes' => array(),
'private' => FALSE,
),
);
}
/**
* Implements _webform_theme_component().
*/
function _webform_theme_textarea() {
return array(
'webform_display_textarea' => array(
'render element' => 'element',
'file' => 'components/textarea.inc',
),
);
}
/**
* Implements _webform_edit_component().
*/
function _webform_edit_textarea($component) {
$form = array();
$form['value'] = array(
'#type' => 'textarea',
'#title' => t('Default value'),
'#default_value' => $component['value'],
'#description' => t('The default value of the field.') . theme('webform_token_help'),
'#cols' => 60,
'#rows' => 5,
'#weight' => 0,
);
$form['display']['cols'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => $component['extra']['cols'],
'#description' => t('Width of the textarea in columns. This property might not have a visual impact depending on the CSS of your site.') . ' ' . t('Leaving blank will use the default size.'),
'#size' => 5,
'#maxlength' => 10,
'#parents' => array('extra', 'cols'),
);
$form['display']['rows'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => $component['extra']['rows'],
'#description' => t('Height of the textarea in rows.') . ' ' . t('Leaving blank will use the default size.'),
'#size' => 5,
'#maxlength' => 10,
'#parents' => array('extra', 'rows'),
);
$form['display']['resizable'] = array(
'#type' => 'checkbox',
'#title' => t('Resizable'),
'#description' => t('Make this field resizable by the user.'),
'#weight' => 2,
'#default_value' => $component['extra']['resizable'],
'#parents' => array('extra', 'resizable'),
);
$form['display']['disabled'] = array(
'#type' => 'checkbox',
'#title' => t('Disabled'),
'#return_value' => 1,
'#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'),
'#weight' => 11,
'#default_value' => $component['extra']['disabled'],
'#parents' => array('extra', 'disabled'),
);
return $form;
}
/**
* Implements _webform_render_component().
*/
function _webform_render_textarea($component, $value = NULL, $filter = TRUE) {
$node = isset($component['nid']) ? node_load($component['nid']) : NULL;
$element = array(
'#type' => 'textarea',
'#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
'#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
'#default_value' => $filter ? _webform_filter_values($component['value'], $node) : $component['value'],
'#required' => $component['mandatory'],
'#weight' => $component['weight'],
'#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
'#rows' => !empty($component['extra']['rows']) ? $component['extra']['rows'] : 5,
'#cols' => !empty($component['extra']['cols']) ? $component['extra']['cols'] : 60,
'#attributes' => $component['extra']['attributes'],
'#resizable' => (bool) $component['extra']['resizable'], // MUST be FALSE to disable.
'#theme_wrappers' => array('webform_element'),
'#translatable' => array('title', 'description'),
);
if ($component['extra']['disabled']) {
if ($filter) {
$element['#attributes']['readonly'] = 'readonly';
}
else {
$element['#disabled'] = TRUE;
}
}
if (isset($value)) {
$element['#default_value'] = $value[0];
}
return $element;
}
/**
* Implements _webform_display_component().
*/
function _webform_display_textarea($component, $value, $format = 'html') {
return array(
'#title' => $component['name'],
'#weight' => $component['weight'],
'#theme' => 'webform_display_textarea',
'#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'),
'#format' => $format,
'#value' => isset($value[0]) ? $value[0] : '',
'#translatable' => array('title'),
);
}
/**
* Format the output of data for this component.
*/
function theme_webform_display_textarea($variables) {
$element = $variables['element'];
$output = $element['#format'] == 'html' ? nl2br(check_plain($element['#value'])) : $element['#value'];
if (drupal_strlen($output) > 80) {
$output = ($element['#format'] == 'html') ? '<div class="webform-long-answer">' . $output . '</div>' : $output;
}
return $output !== '' ? $output : ' ';
}
/**
* Implements _webform_analysis_component().
*/
function _webform_analysis_textarea($component, $sids = array()) {
$query = db_select('webform_submitted_data', 'wsd', array('fetch' => PDO::FETCH_ASSOC))
->fields('wsd', array('no', 'data'))
->condition('nid', $component['nid'])
->condition('cid', $component['cid']);
if (count($sids)) {
$query->condition('sid', $sids, 'IN');
}
$nonblanks = 0;
$submissions = 0;
$wordcount = 0;
$result = $query->execute();
foreach ($result as $data) {
if (drupal_strlen(trim($data['data'])) > 0) {
$nonblanks++;
$wordcount += str_word_count(trim($data['data']));
}
$submissions++;
}
$rows[0] = array(t('Left Blank'), ($submissions - $nonblanks));
$rows[1] = array(t('User entered value'), $nonblanks);
$rows[2] = array(t('Average submission length in words (ex blanks)'), ($nonblanks != 0 ? number_format($wordcount/$nonblanks, 2) : '0'));
return $rows;
}
/**
* Implements _webform_table_component().
*/
function _webform_table_textarea($component, $value) {
return empty($value[0]) ? '' : check_plain($value[0]);
}
/**
* Implements _webform_csv_headers_component().
*/
function _webform_csv_headers_textarea($component, $export_options) {
$header = array();
$header[0] = '';
$header[1] = '';
$header[2] = $component['name'];
return $header;
}
/**
* Implements _webform_csv_data_component().
*/
function _webform_csv_data_textarea($component, $export_options, $value) {
return empty($value[0]) ? '' : $value[0];
}