| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: form_builder.properties.inc,v 1.10 2009/06/20 06:18:15 quicksketch Exp $ 3 4 /** 5 * @file form_builder.properties.inc 6 * Implementations of hook_form_builder_properties in separate functions. 7 */ 8 9 /** 10 * Configuration form for the "key" property. 11 * 12 * The key property is special in that it's not actually part of the element, 13 * but instead the array key that is used to reference the element in the 14 * Form API structure. 15 */ 16 function form_builder_property_key_form(&$form_state, $form_type, $element) { 17 $form = array(); 18 19 $form['key'] = array( 20 '#title' => t('Form key'), 21 '#type' => 'textfield', 22 '#default_value' => $element['#key'], 23 '#required' => TRUE, 24 '#weight' => -9, 25 '#element_validate' => array('form_builder_property_key_form_validate'), 26 ); 27 28 return $form; 29 } 30 31 /** 32 * Element validate function for the "key" property. Ensure safe characters. 33 */ 34 function form_builder_property_key_form_validate($element, $form_state) { 35 if (!preg_match('/^[a-z0-9_]+$/', $element['#value'])) { 36 form_error($element, t('The form key may only contain lowercase alphanumeric characters and underscores.')); 37 } 38 } 39 40 /** 41 * Configuration form for the "title" property. 42 */ 43 function form_builder_property_title_form(&$form_state, $form_type, $element) { 44 $form = array(); 45 46 $form['title'] = array( 47 '#title' => t('Title'), 48 '#type' => 'textfield', 49 '#default_value' => $element['#title'], 50 '#required' => TRUE, 51 '#weight' => -10, 52 ); 53 54 return $form; 55 } 56 57 58 /** 59 * Configuration form for the "weight" property. 60 * 61 * This field is in the "hidden" builder group, meaning it's never shown in 62 * the main editing interface. However, it's still there if editing without JS. 63 */ 64 function form_builder_property_weight_form(&$form_state, $form_type, $element) { 65 $form = array(); 66 67 if (!isset($_REQUEST['js'])) { 68 $form['weight'] = array( 69 '#form_builder' => array('property_group' => 'hidden'), 70 '#type' => 'textfield', 71 '#size' => 6, 72 '#title' => t('Weight'), 73 '#default_value' => $element['#weight'], 74 ); 75 } 76 77 return $form; 78 } 79 80 /** 81 * Configuration form for the "description" property. 82 */ 83 function form_builder_property_description_form(&$form_state, $form_type, $element) { 84 $form = array(); 85 86 $form['description'] = array( 87 '#title' => t('Description'), 88 '#type' => 'textarea', 89 '#default_value' => $element['#description'], 90 '#weight' => 5, 91 ); 92 93 return $form; 94 } 95 96 /** 97 * Configuration form for the "required" property. 98 */ 99 function form_builder_property_required_form(&$form_state, $form_type, $element) { 100 $form = array(); 101 102 $form['required'] = array( 103 '#form_builder' => array('property_group' => 'validation'), 104 '#title' => t('Required'), 105 '#type' => 'checkbox', 106 '#default_value' => $element['#required'], 107 '#weight' => -1, 108 ); 109 110 return $form; 111 } 112 113 /** 114 * Configuration form for the "options" property. 115 */ 116 function form_builder_property_options_form(&$form_state, $form_type, $element) { 117 $form = array(); 118 119 // Checkboxes have an implied "multiple" property. 120 if ($element['#type'] == 'checkboxes') { 121 $element['#multiple'] = TRUE; 122 } 123 124 $form['options'] = array( 125 '#form_builder' => array('property_group' => 'options'), 126 '#title' => t('Options'), 127 '#type' => 'options', 128 '#default_value' => $element['#default_value'], 129 '#options' => $element['#options'], 130 '#required' => TRUE, 131 '#multiple' => isset($element['#multiple']) ? $element['#multiple'] : FALSE, 132 '#multiple_toggle' => isset($element['#multiple_toggle']) ? $element['#multiple_toggle'] : FALSE, 133 '#optgroups' => $element['#type'] == 'select' ? TRUE : FALSE, 134 '#limit' => 10, 135 // Uncomment to test numeric fields. 136 '#key_type' => isset($element['#key_type']) ? $element['#key_type'] : 'associative', 137 '#key_type_toggle' => isset($element['#key_type_toggle']) ? $element['#key_type'] : TRUE, 138 ); 139 140 // Remove the default value field, since it's handled by the options field. 141 $form['default_value'] = array(); 142 143 return $form; 144 } 145 146 function form_builder_property_options_form_submit(&$form, &$form_state) { 147 $options = $form_state['values']['options']['options']; 148 $default_value = $form_state['values']['options']['default_value']; 149 150 if (isset($form_state['values']['options']['multiple'])) { 151 $multiple = $form_state['values']['options']['multiple']; 152 $form_state['values']['multiple'] = $multiple; 153 } 154 155 if (isset($form_state['values']['options']['key_type'])) { 156 $key_type = $form_state['values']['options']['key_type'] ? $form_state['values']['options']['key_type'] : 'associative'; 157 $form_state['values']['key_type'] = $key_type; 158 } 159 160 $form_state['values']['options'] = $options; 161 $form_state['values']['default_value'] = $default_value; 162 } 163 164 /** 165 * Configuration form for the "default_value" property. 166 */ 167 function form_builder_property_default_value_form(&$form_state, $form_type, $element) { 168 $form = array(); 169 170 $form['default_value'] = array( 171 '#type' => 'textfield', 172 '#title' => t('Default value'), 173 '#default_value' => $element['#default_value'], 174 '#weight' => 1, 175 ); 176 177 return $form; 178 } 179 180 /** 181 * Configuration form for the "markup" property. 182 */ 183 function form_builder_property_markup_form(&$form_state, $form_type, $element) { 184 $form = array(); 185 186 // TODO: This is a placeholder until "#markup" becomes available in D7. 187 $form['markup'] = array( 188 '#type' => 'textarea', 189 '#title' => t('Markup'), 190 '#default_value' => $element['#markup'], 191 '#weight' => 1, 192 ); 193 194 return $form; 195 } 196 197 /** 198 * Configuration form for the "input_format" property. 199 */ 200 function form_builder_property_input_format_form(&$form_state, $form_type, $element) { 201 $form = array(); 202 203 // TODO: This is a placeholder until "#input_format" becomes available in D7. 204 $form['input_format'] = filter_form(FILTER_FORMAT_DEFAULT, 2, array('input_format')); 205 206 return $form; 207 } 208 209 /** 210 * Configuration form for the "size" property. 211 */ 212 function form_builder_property_size_form(&$form_state, $form_type, $element) { 213 $form = array(); 214 215 $form['size'] = array( 216 '#form_builder' => array('property_group' => 'display'), 217 '#type' => 'textfield', 218 '#size' => 6, 219 '#title' => t('Size'), 220 '#default_value' => $element['#size'], 221 '#weight' => 2, 222 ); 223 224 return $form; 225 } 226 227 /** 228 * Configuration form for the "rows" property. 229 */ 230 function form_builder_property_rows_form(&$form_state, $form_type, $element) { 231 $form = array(); 232 233 $form['rows'] = array( 234 '#form_builder' => array('property_group' => 'display'), 235 '#type' => 'textfield', 236 '#size' => 6, 237 '#title' => t('Rows'), 238 '#default_value' => $element['#rows'], 239 '#weight' => 2, 240 ); 241 242 return $form; 243 } 244 245 /** 246 * Configuration form for the "cols" property. 247 */ 248 function form_builder_property_cols_form(&$form_state, $form_type, $element) { 249 $form = array(); 250 251 $form['cols'] = array( 252 '#form_builder' => array('property_group' => 'display'), 253 '#type' => 'textfield', 254 '#size' => 6, 255 '#title' => t('Columns'), 256 '#default_value' => $element['#cols'], 257 '#weight' => 3, 258 '#description' => t('The width of the textarea. This property might not have a visual impact depending on the CSS of your site.'), 259 ); 260 261 return $form; 262 } 263 264 265 /** 266 * Configuration form for the "field_prefix" property. 267 */ 268 function form_builder_property_field_prefix_form(&$form_state, $form_type, $element) { 269 $form = array(); 270 271 $form['field_prefix'] = array( 272 '#form_builder' => array('property_group' => 'display'), 273 '#type' => 'textfield', 274 '#title' => t('Prefix'), 275 '#default_value' => $element['#field_prefix'], 276 '#weight' => -2, 277 ); 278 279 return $form; 280 } 281 282 /** 283 * Configuration form for the "field_suffix" property. 284 */ 285 function form_builder_property_field_suffix_form(&$form_state, $form_type, $element) { 286 $form = array(); 287 288 $form['field_suffix'] = array( 289 '#form_builder' => array('property_group' => 'display'), 290 '#type' => 'textfield', 291 '#title' => t('Suffix'), 292 '#default_value' => $element['#field_suffix'], 293 '#weight' => -1, 294 ); 295 296 return $form; 297 } 298 299 /** 300 * Configuration form for the "collapsible" property. 301 */ 302 function form_builder_property_collapsible_form(&$form_state, $form_type, $element) { 303 $form = array(); 304 305 $form['collapsible'] = array( 306 '#form_builder' => array('property_group' => 'display'), 307 '#type' => 'checkbox', 308 '#title' => t('Collapsible'), 309 '#default_value' => $element['#collapsible'], 310 '#weight' => -2, 311 ); 312 313 return $form; 314 } 315 316 /** 317 * Configuration form for the "collapsed" property. 318 */ 319 function form_builder_property_collapsed_form(&$form_state, $form_type, $element) { 320 $form = array(); 321 322 $form['collapsed'] = array( 323 '#form_builder' => array('property_group' => 'display'), 324 '#type' => 'checkbox', 325 '#title' => t('Collapsed'), 326 '#default_value' => $element['#collapsed'], 327 '#weight' => -1, 328 '#description' => t('This property will not affect the preview immediately.'), 329 ); 330 331 return $form; 332 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |