hook_widget($op, &$node, $field, &$node_field)
cck-5--1/field.php, line 410
Define the behavior of a widget.
$op What kind of action is being performed. Possible values:
$field The field the action is being performed on.
&$node_field The contents of the field in this node. Changes to this variable will be saved back to the node object.
This varies depending on the operation.
<?php
function hook_widget($op, &$node, $field, &$node_field) {
switch ($op) {
case 'prepare form values':
if ($field['multiple']) {
$node_field_transposed = content_transpose_array_rows_cols($node_field);
$node_field['default nids'] = $node_field_transposed['nid'];
}
else {
$node_field['default nids'] = array($node_field['nid']);
}
break;
case 'form':
$form = array();
$form[$field['field_name']] = array('#tree' => TRUE);
$form[$field['field_name']]['nids'] = array(
'#type' => 'select',
'#title' => t($field['widget']['label']),
'#default_value' => $node_field['default nids'],
'#multiple' => $field['multiple'],
'#options' => _nodereference_potential_references($field),
'#required' => $field['required'],
'#description' => $field['widget']['description'],
);
return $form;
case 'process form values':
if ($field['multiple']) {
$node_field = content_transpose_array_rows_cols(array('nid' => $node_field['nids']));
}
else {
$node_field['nid'] = is_array($node_field['nids']) ? reset($node_field['nids']) : $node_field['nids'];
}
break;
}
}
?>