| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Implements hook_elements(). 5 */ 6 function elements_elements() { 7 $types['tableselect'] = array( 8 '#input' => TRUE, 9 '#js_select' => TRUE, 10 '#multiple' => TRUE, 11 '#process' => array('form_process_tableselect'), 12 '#options' => array(), 13 '#empty' => '', 14 ); 15 $types['emailfield'] = array( 16 '#input' => TRUE, 17 '#size' => 60, 18 '#maxlength' => 128, 19 '#autocomplete_path' => FALSE, 20 '#process' => array('form_expand_ahah'), 21 '#value_callback' => 'form_type_textfield_value', 22 ); 23 $types['searchfield'] = array( 24 '#input' => TRUE, 25 '#size' => 60, 26 '#maxlength' => 128, 27 '#autocomplete_path' => FALSE, 28 '#process' => array('form_expand_ahah'), 29 '#value_callback' => 'form_type_textfield_value', 30 ); 31 $types['telfield'] = array( 32 '#input' => TRUE, 33 '#size' => 20, 34 '#maxlength' => 64, 35 '#autocomplete_path' => FALSE, 36 '#process' => array('form_expand_ahah'), 37 '#value_callback' => 'form_type_textfield_value', 38 ); 39 $types['urlfield'] = array( 40 '#input' => TRUE, 41 '#size' => 80, 42 '#maxlength' => 128, 43 '#autocomplete_path' => FALSE, 44 '#process' => array('form_expand_ahah'), 45 '#value_callback' => 'form_type_textfield_value', 46 ); 47 $types['numberfield'] = array( 48 '#input' => TRUE, 49 '#process' => array('form_expand_ahah'), 50 '#value_callback' => 'form_type_textfield_value', 51 ); 52 $types['rangefield'] = array( 53 '#input' => TRUE, 54 '#process' => array('form_expand_ahah'), 55 '#value_callback' => 'form_type_textfield_value', 56 ); 57 // Add placeholder support to textfields and textareas. 58 $types['textfield'] = array( 59 '#process' => array('form_process_placeholder'), 60 ); 61 $types['textarea'] = array( 62 '#process' => array('form_process_placeholder'), 63 ); 64 return $types; 65 } 66 67 /** 68 * Implements hook_theme(). 69 */ 70 function elements_theme() { 71 return array( 72 'tableselect' => array( 73 'arguments' => array('element' => NULL), 74 'file' => 'elements.theme.inc', 75 ), 76 'emailfield' => array( 77 'arguments' => array('element' => NULL), 78 'file' => 'elements.theme.inc', 79 ), 80 'searchfield' => array( 81 'arguments' => array('element' => NULL), 82 'file' => 'elements.theme.inc', 83 ), 84 'telfield' => array( 85 'arguments' => array('element' => NULL), 86 'file' => 'elements.theme.inc', 87 ), 88 'urlfield' => array( 89 'arguments' => array('element' => NULL), 90 'file' => 'elements.theme.inc', 91 ), 92 'numberfield' => array( 93 'arguments' => array('element' => NULL), 94 'file' => 'elements.theme.inc', 95 ), 96 'rangefield' => array( 97 'arguments' => array('element' => NULL), 98 'file' => 'elements.theme.inc', 99 ), 100 ); 101 } 102 103 /** 104 * Return the autocompletion HTML for a form element. 105 * 106 * @param $element 107 * The renderable element to process for autocompletion. 108 * 109 * @return 110 * The rendered autocompletion element HTML, or an empty string if the field 111 * has no autocompletion enabled. 112 */ 113 function elements_add_autocomplete(&$element) { 114 $output = ''; 115 116 if (!empty($element['#autocomplete_path']) && menu_valid_path(array('link_path' => $element['#autocomplete_path']))) { 117 drupal_add_js('misc/autocomplete.js'); 118 $element['#attributes']['class'] .= ' form-autocomplete'; 119 120 $attributes = array(); 121 $attributes['type'] = 'hidden'; 122 $attributes['id'] = $element['#attributes']['id'] . '-autocomplete'; 123 $attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); 124 $attributes['disabled'] = 'disabled'; 125 $attributes['class'] = 'autocomplete'; 126 $output = '<input' . drupal_attributes($attributes) . ' />'; 127 } 128 129 return $output; 130 } 131 132 /** 133 * Element process callback; adds support for the HTML5 placeholder attribute. 134 * 135 * @param $element 136 * An associative array containing the properties of the element. 137 * 138 * @return 139 * The processed element. 140 */ 141 function form_process_placeholder($element) { 142 if (isset($element['#placeholder']) && !isset($element['#attributes']['placeholder'])) { 143 // If the placeholder FAPI property is set, simply add it to the form's 144 // attributes so it will be output in the HTML tag. 145 $element['#attributes']['placeholder'] = $element['#placeholder']; 146 } 147 return $element; 148 } 149 150 /** 151 * Sets HTML attributes based on element properties. 152 * 153 * This is a backport from the Drupal 7 core function of the same name. 154 * 155 * @param $element 156 * The renderable element to process. 157 * @parm $map 158 * An associative array whose keys are element property names and whose 159 * values are the HTML attribute names to set for corresponding the property; 160 * e.g., array('#propertyname' => 'attributename'). If both names are 161 * identical except for the leading '#', then an attribute name value is 162 * sufficient and no property name needs to be specified. 163 */ 164 function element_set_attributes(array &$element, array $map) { 165 foreach ($map as $property => $attribute) { 166 // If the key is numeric, the attribute name needs to be taken over. 167 if (is_int($property)) { 168 $property = '#' . $attribute; 169 } 170 // Do not overwrite already existing attributes. 171 if (isset($element[$property]) && !isset($element['#attributes'][$attribute])) { 172 $element['#attributes'][$attribute] = $element[$property]; 173 } 174 } 175 } 176 177 /** 178 * Create the correct amount of checkbox or radio elements to populate the table. 179 * 180 * @param $element 181 * An associative array containing the properties and children of the 182 * tableselect element. 183 * @return 184 * The processed element. 185 */ 186 function form_process_tableselect($element) { 187 if ($element['#multiple']) { 188 $value = is_array($element['#value']) ? $element['#value'] : array(); 189 } 190 else { 191 // Advanced selection behaviour make no sense for radios. 192 $element['#js_select'] = FALSE; 193 } 194 195 $element['#tree'] = TRUE; 196 197 if (count($element['#options']) > 0) { 198 if (!isset($element['#default_value']) || $element['#default_value'] === 0) { 199 $element['#default_value'] = array(); 200 } 201 202 // Create a checkbox or radio for each item in #options in such a way that 203 // the value of the tableselect element behaves as if it had been of type 204 // checkboxes or radios. 205 foreach ($element['#options'] as $key => $choice) { 206 // Do not overwrite manually created children. 207 if (!isset($element[$key])) { 208 if ($element['#multiple']) { 209 $element[$key] = array( 210 '#type' => 'checkbox', 211 '#title' => '', 212 '#return_value' => $key, 213 '#default_value' => isset($value[$key]), 214 '#attributes' => $element['#attributes'], 215 '#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL, 216 ); 217 } 218 else { 219 // Generate the parents as the autogenerator does, so we will have a 220 // unique id for each radio button. 221 $parents_for_id = array_merge($element['#parents'], array($key)); 222 $element[$key] = array( 223 '#type' => 'radio', 224 '#title' => '', 225 '#return_value' => $key, 226 '#default_value' => ($element['#default_value'] == $key) ? $key : NULL, 227 '#attributes' => $element['#attributes'], 228 '#parents' => $element['#parents'], 229 '#id' => form_clean_id('edit-' . implode('-', $parents_for_id)), 230 '#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL, 231 ); 232 } 233 if (isset($element['#options'][$key]['#weight'])) { 234 $element[$key]['#weight'] = $element['#options'][$key]['#weight']; 235 } 236 } 237 } 238 } 239 else { 240 $element['#value'] = array(); 241 } 242 return $element; 243 }
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 |