It looks like there is an issue with the og_menu_node_form_validate function. This is checking the value in the 'group_audience' field which does not exist. I think this should check both the og_group_ref and the og_group_ref_other_groups (or whatever other group fields there may be).

Something like this? Line 604 of og_menu.module

  if (isset($form_state['values']['og_group_ref'][LANGUAGE_NONE]) || isset($form_state['values']['og_group_ref_other_groups'][LANGUAGE_NONE])) {
    if (isset($form_state['values']['og_group_ref'][LANGUAGE_NONE])) {
      foreach ($form_state['values']['og_group_ref'][LANGUAGE_NONE] as $item => $gid) {
        $gids[] = $gid['target_id'];
      }
    }
    if (isset($form_state['values']['og_group_ref_other_groups'][LANGUAGE_NONE])) {
      foreach ($form_state['values']['og_group_ref_other_groups'][LANGUAGE_NONE] as $item => $gid) {
        $gids[] = $gid['target_id'];
      }
    }
  }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zipymonkey’s picture

Status: Active » Needs review
FileSize
1.42 KB

Found a better fix for this that uses the og_get_group_audience_fields function. Patch is attached.

rv0’s picture

Status: Needs review » Closed (fixed)

your patch had mixed line endings and didn't apply due to previous patches, so I had to manually edit

zipymonkey’s picture

Thanks rv0. I think I need take a look at my eclipse settings...

jvieille’s picture

This issue dates back D6 or earlier.
Actually, when the adience selection is disabled, no groups are available for checking, so it fails
(the $gids variable then contains one item 0=>0)

In D6, I have simply modiifed the function og_menu_node_form_validate. It test that the first GID is 0=> 0 (not an empty array actually)

    foreach ($menus as $menu) {
      if ($menu['menu_name'] == $parent) {
        // Check if user has access to the chosen menu parent
        $has_menu_access = TRUE;
        // Check if menu belongs to one of the selected groups
-        if (!in_array($menu['gid'], $gids)) {
+        if (($gids[0] !== 0) and !in_array($menu['gid'], $gids)) {
          form_set_error('og_groups', t('The menus you chose does not belong to the selected groups.'));
        }
      }
    }
osopolar’s picture

Issue summary: View changes
FileSize
1 KB

In case of max group limit = 1 together with issue #707114: Improve group post node form for a max-groups limit of 1. the $form_state['values']['og_groups'] will be a string, not an array. This case will result in the same error.

@jvieille: Can't see the case in which $gids[0] !== 0. How to you disable the audience selection? If you use ['#access'] = FALSE for the field the og_groups will be there. You just disable the validation for your case. If there are no gids in the form_state I guess the node already exists, so you will get the gids by calling og_get_node_groups($node), won't you? I'd like to add this case to the patch, but I don't know how to test it (because I don't know how to disable the audience selection).

rv0’s picture

what is this patch for ? D6?

osopolar’s picture

Sorry for not mentioning, yes it's for D6 and only when patch in #707114: Improve group post node form for a max-groups limit of 1. is used. In the end I'm not sure if it's worth to use patch in #707114, because there are some more problems there.