function brazilianids_widget in Brazilian IDs 6
Implementation of hook_widget().
Attach a single form element to the form.
CCK core fields only add a stub element and builds the complete item in #process so reusable elements created by hook_elements can be plugged into any module that provides valid $field information.
Custom widgets that don't care about using hook_elements can be built out completely at this time.
If there are multiple values for this field and CCK is handling multiple values, the content module will call this function as many times as needed.
Parameters
$form: the entire form array, $form['#node'] holds node information
$form_state: the form_state, $form_state['values'][$field['field_name']] holds the field's form values.
$field: the field array
$items: array of default values for this field
$delta: the order of this item in the array of subelements (0, 1, 2, etc)
Return value
the form item for a single element for this field
File
- ./
brazilianids_cck.inc, line 270 - brazilianids_cck.inc Deal with brazilian IDs like CPF and CNPJ as CCK fields.
Code
function brazilianids_widget(&$form, &$form_state, $field, $items, $delta = 0) {
$element['value'] = array(
'#type' => 'textfield',
'#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
'#title' => $field['widget']['label'],
'#required' => $field['required'] ? $field['required'] : FALSE,
'#autocomplete_path' => $element['#autocomplete_path'],
'#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 18,
'#attributes' => array(
'class' => 'edit-brazilianids',
),
'#maxlength' => $field['type'] == 'brazilianids_cpf' ? 14 : 18,
'#description' => $field['widget']['description'],
);
// Used so that hook_field('validate') knows where to
// flag an error in deeply nested forms.
if (empty($form['#parents'])) {
$form['#parents'] = array();
}
$element['_error_element'] = array(
'#type' => 'value',
'#value' => implode('][', array_merge($form['#parents'], array(
'value',
))),
);
return $element;
}