function rolereference_widget in Role Reference 5
Same name and namespace in other branches
- 6 rolereference.module \rolereference_widget()
Implementation of hook_widget().
File
- ./
rolereference.module, line 115 - Defines a field type for referencing a role.
Code
function rolereference_widget($op, &$role, $field, &$role_field) {
if ($field['widget']['type'] == 'rolereference_select') {
switch ($op) {
case 'prepare form values':
$role_field_transposed = content_transpose_array_rows_cols($role_field);
$role_field['default rids'] = $role_field_transposed['rid'];
break;
case 'form':
$form = array();
$form[$field['field_name']] = array(
'#tree' => TRUE,
);
$form[$field['field_name']]['rids'] = array(
'#type' => 'select',
'#title' => t($field['widget']['label']),
'#default_value' => $role_field['default rids'],
'#multiple' => $field['multiple'],
'#options' => _rolereference_get_roles(),
'#required' => $field['required'],
'#description' => $field['widget']['description'],
);
return $form;
case 'process form values':
if ($field['multiple']) {
$role_field = content_transpose_array_rows_cols(array(
'rid' => $role_field['rids'],
));
}
else {
$role_field[0]['rid'] = $role_field['rids'];
}
// Remove the widget's data representation so it isn't saved.
unset($role_field['rids']);
}
}
}