function blockreference_widget in Block reference 6
Implementation of hook_widget().
Attach a single form element to the form. It will be built out and validated in the callback(s) listed in hook_elements. We build it out in the callbacks rather than here in hook_widget so it can be plugged into any module that can provide it with valid $field information.
Content module will set the weight, field name and delta values for each form element. This is a change from earlier CCK versions where the widget managed its own multiple values.
If there are multiple values for this field, 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
- ./
blockreference.module, line 444 - Defines a field type for referencing a block from a node.
Code
function blockreference_widget(&$form, &$form_state, $field, $items, $delta = 0) {
switch ($field['widget']['type']) {
case 'blockreference_select':
$element = array(
'#type' => 'blockreference_select',
'#default_value' => $items,
);
break;
case 'blockreference_select_sort':
$element = array(
'#type' => 'blockreference_select_sort',
'#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
);
break;
case 'blockreference_autocomplete':
$element = array(
'#type' => 'blockreference_autocomplete',
'#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
'#value_callback' => 'blockreference_autocomplete_value',
);
break;
}
return $element;
}