function og_complex_widget_element_validate in Organic groups 7.2
Rebuild the element's values, using the default and admin if exists.
1 string reference to 'og_complex_widget_element_validate'
- og_field_widget_form in includes/
og.field.inc - Implements hook_field_widget_form().
File
- includes/
og.field.inc, line 276 - Field widget related code for Organic groups.
Code
function og_complex_widget_element_validate($element, &$form_state, $form) {
$subform = drupal_array_get_nested_value($form_state['values'], $element['#array_parents']);
$ids = array();
foreach (array(
'default',
'admin',
) as $field_mode) {
if (empty($subform[$field_mode])) {
continue;
}
foreach ($subform[$field_mode] as $value) {
if (!empty($value['target_id']) && is_numeric($value['target_id'])) {
$ids[] = array(
'target_id' => $value['target_id'],
// Add the field mode so we can later validate it in
// OgBehaviorHandler::validate()
'field_mode' => $field_mode,
);
}
}
}
$ids = array_merge($ids, $element['#other_groups_ids']);
// Set the form values by directly using drupal_array_set_nested_values(),
// which allows us to control the element parents. In this case we cut off the
// last element that contains the delta 0, as $ids is already keyed with
// deltas.
drupal_array_set_nested_value($form_state['values'], array_slice($element['#parents'], 0, -1), $ids, TRUE);
// If the element is required, ensure that at least one group has been chosen.
if ($element['#required']) {
$subform = drupal_array_get_nested_value($form_state['values'], $element['#array_parents']);
if (empty($subform)) {
form_error($element, t('!name field is required.', array(
'!name' => $element['#title'],
)));
}
}
}