function autocomplete_widgets_process in Autocomplete Widgets for Text and Number Fields 6
Process an individual textfield autocomplete element.
1 string reference to 'autocomplete_widgets_process'
- autocomplete_widgets_elements in ./
autocomplete_widgets.module - Implementation of hook_elements().
File
- ./
autocomplete_widgets.module, line 109 - Provides autocomplete widgets for CCK Text and Number fields.
Code
function autocomplete_widgets_process($element, $edit, $form_state, $form) {
$field = $form['#field_info'][$element['#field_name']];
$field_key = $element['#columns'][0];
$value = NULL;
if ($field['widget']['type'] == 'autocomplete_widgets_allowvals') {
if (isset($element['#value'][$field_key])) {
$keys = array(
$element['#value'][$field_key],
);
module_load_include('inc', 'autocomplete_widgets', 'autocomplete_widgets.common');
$options = _autocomplete_widgets_get_options($field, '', '', $keys, 1);
if (!empty($options)) {
$value = current($options);
}
}
}
else {
if ($field['widget']['type'] == 'autocomplete_widgets_flddata') {
if (isset($element['#value'][$field_key])) {
$value = $element['#value'][$field_key];
}
}
}
$element[$field_key] = array(
'#type' => 'textfield',
'#default_value' => $value,
'#autocomplete_path' => 'autocomplete_widgets/' . $element['#type_name'] . '/' . $element['#field_name'],
'#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 60,
'#attributes' => array(
'class' => 'text',
),
// The following values were set by the content module and need
// to be passed down to the nested element.
'#title' => $element['#title'],
'#description' => $element['#description'],
'#required' => $element['#required'],
'#field_name' => $element['#field_name'],
'#type_name' => $element['#type_name'],
'#delta' => $element['#delta'],
'#columns' => $element['#columns'],
);
$element[$field_key]['#maxlength'] = !empty($field['max_length']) ? $field['max_length'] : NULL;
if (empty($element[$field_key]['#element_validate'])) {
$element[$field_key]['#element_validate'] = array();
}
array_unshift($element[$field_key]['#element_validate'], 'autocomplete_widgets_validate');
$element['_error_element'] = array(
'#type' => 'value',
'#value' => implode('][', array_merge($element['#parents'], array(
$field_key,
))),
);
return $element;
}