I have a custom widget which can be used for a group audience field. Instead of being a dropdown like the OG_AUDIENCE_WIDGET it is made up of three multiple select list, and the group which is actually selected is the one which is picked in the third select list. I have the actual widget working but I am stuck on validation. I have been trying to set the gid in a couple of different ways which have failed in a couple different manors. First:
function multiselect_validate($element, &$form_state)
{
if($form_state['submitted'])
{
$index = array_shift(array_values($element['wrapper']['dropdown_assignment']['#value']));
$assignment_name = $element['wrapper']['dropdown_assignment']['#options'][$index];
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'assignment_group')
->propertyCondition('title',$assignment_name)
->execute();
$node = reset($result['node']);
$assignment_gid = og_get_group("node", $node->nid)->gid;
$value = $value[LANGUAGE_NONE][0]['gid'] = $assignment_gid;
form_set_value($element,array('gid'=>198), $form_state);
}
}
This kind of validation returns an error:
[11-Dec-2012 11:23:07] PHP Fatal error: Cannot unset string offsets in /Applications/MAMP/htdocs/arcade/modules/field/field.default.inc on line 41
I also tried something like this for the final form_set_value:
form_set_value($element,array('gid'=>$assignment_gid), $form_state);
But when I do this and then look at the result nothing actually gets set into the field.
What is the proper way to set the gid for the field?