hook_field_widget
- Versions
- 7
hook_field_widget(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element)
Return a single form element for a field widget.
Field widget form elements should be based on the passed in $element, which contains the base form element properties derived from the field configuration.
Field API will set the weight, field name and delta values for each form element. If there are multiple values for this field, the Field API will call this function as many times as needed.
Parameters
$form The entire form array.
$form_state The form_state, $form_state['values'][$field['field_name']] holds the field's form values.
$field The field structure.
$instance The field instance.
$langcode The language associated to $items.
$items Array of default values for this field.
$delta The order of this item in the array of subelements (0, 1, 2, etc).
$element A form element array containing basic properties for the widget:
- #object_type: The name of the object the field is attached to.
- #bundle: The name of the field bundle the field is contained in.
- #field_name: The name of the field.
- #columns: A list of field storage columns of the field.
- #title: The sanitized element label for the field instance, ready for output.
- #description: The sanitized element description for the field instance, ready for output.
- #required: A Boolean indicating whether the element value is required; for required multiple value fields, only the first widget's values are required.
- #delta: The order of this item in the array of subelements; see $delta above.
Return value
The form elements for a single widget for this field.
Related topics
Code
modules/field/field.api.php, line 661
<?php
function hook_field_widget(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$element += array(
'#type' => $instance['widget']['type'],
'#default_value' => isset($items[$delta]) ? $items[$delta] : '',
);
return $element;
}
?>Login or register to post comments 