function og_field_widget_form_validate in Organic groups 7
Validate handler; Re-add hidden selected group IDs if exist. Also, to be safe, check for and clean up duplicate entries.
1 string reference to 'og_field_widget_form_validate'
- og_form_alter in ./
og.module - Implements hook_form_alter().
File
- ./
og.field.inc, line 462 - Field module functionality for the Organic groups module.
Code
function og_field_widget_form_validate($form, &$form_state) {
// The hidden group IDs.
$gids = !empty($form[OG_AUDIENCE_FIELD][LANGUAGE_NONE]['#hidden_selected_gids']) ? $form[OG_AUDIENCE_FIELD][LANGUAGE_NONE]['#hidden_selected_gids'] : array();
if (!empty($form_state['values'][OG_AUDIENCE_FIELD][LANGUAGE_NONE])) {
foreach ($form_state['values'][OG_AUDIENCE_FIELD][LANGUAGE_NONE] as $key => $value) {
// Add the selected group IDs if it is not the "add more" element.
if ($key !== 'add_more') {
$gids[$value['gid']] = $value['gid'];
}
}
}
$delta = 0;
$value = array();
foreach ($gids as $gid) {
$value[LANGUAGE_NONE][$delta]['gid'] = $gid;
++$delta;
}
if (empty($value)) {
return;
}
// Set the new values.
form_set_value($form[OG_AUDIENCE_FIELD], $value, $form_state);
}