diff --git a/includes/og.field.inc b/includes/og.field.inc index cdf02bc..f260cc7 100644 --- a/includes/og.field.inc +++ b/includes/og.field.inc @@ -72,11 +72,17 @@ function og_field_widget_form(&$form, &$form_state, $field, $instance, $langcode } } $target_type = $field['settings']['target_type']; - $user_gids = og_get_entity_groups(); - $user_gids = !empty($user_gids[$target_type]) ? $user_gids[$target_type] : array(); - // Get the "Other group" group IDs. - $other_groups_ids = array_diff($entity_gids, $user_gids); + $mocked_instance = og_get_mocked_instance($instance, 'default'); + // Get the group ids available for selection in the audience field. + $ids = entityreference_get_selection_handler($field, $mocked_instance)->getReferencableEntities(); + // The field can only target one entity_type, key the available gids by the + // field's target type. + $field_gids = array(); + $field_gids = !empty($ids) ? $field_gids[$target_type] = array_keys($ids) : array(); + + // Groups not shown in the audience field. + $other_groups_ids = array_diff($entity_gids, $field_gids); foreach ($field_modes as $field_mode) { $mocked_instance = og_get_mocked_instance($instance, $field_mode); @@ -108,7 +114,7 @@ function og_field_widget_form(&$form, &$form_state, $field, $instance, $langcode } else { // Keep only the groups that belong to the user and to the entity. - $my_group_ids = array_values(array_intersect($user_gids, $entity_gids)); + $my_group_ids = array_values(array_intersect($field_gids, $entity_gids)); $valid_ids = $my_group_ids ? entityreference_get_selection_handler($field, $mocked_instance, $entity_type, $dummy_entity)->validateReferencableEntities($my_group_ids) : array(); $valid_ids = $field['cardinality'] == 1 ? reset($valid_ids) : $valid_ids;