Problem/Motivation

A PHP warning is emitted when attempting to create a new node.

  1. Enable Organic groups moderation
  2. Start creating a new node. The node type must be set as group content.
  3. At the top of the node creation form, the following message is displayed: Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /drupal_root/includes/entity.inc).

The problem lies in line 28 in og_moderation.module, in function og_moderation_form_alter:

<?php
function og_moderation_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['#node_edit_form'])) {
    if ($form['#node_edit_form'] && og_is_group_content_type('node', $form['#bundle'])) {
      if ($gids = og_get_entity_groups('node', $form['#node'])) { // <---- This line causes the problem.
        foreach($gids as $gid) {
          if (og_user_access($gid, "access publishing options of " . $form['#bundle'] . " content")) {
            $form['options']['#access'] = TRUE;
          }
          if (og_user_access($gid, "access revisions options of " . $form['#bundle'] . " content")) {
            $form['revision_information']['#access'] = TRUE;
          }
        }
      }
    }
  }
}
?>

The function og_get_entity_groups is called with the node object stored in $form['#node']. Since this is a new node, this node object does not have the node ID set.

Proposed resolution

Add a check to see if the node object in $form['#node'] has nid set before calling og_get_entity_groups:

<?php
function og_moderation_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['#node_edit_form'])) {
    if ($form['#node_edit_form'] && og_is_group_content_type('node', $form['#bundle'])) {
        // Old line:
    	// if ($gids = og_get_entity_groups('node', $form['#node'])) {
    	if (isset($form['#node']->nid) && $gids = og_get_entity_groups('node', $form['#node'])) { // New line
        foreach($gids as $gid) {
          if (og_user_access($gid, "access publishing options of " . $form['#bundle'] . " content")) {
            $form['options']['#access'] = TRUE;
          }
          if (og_user_access($gid, "access revisions options of " . $form['#bundle'] . " content")) {
            $form['revision_information']['#access'] = TRUE;
          }
        }
      }
    }
  }
}
?>

Comments

shenzhuxi’s picture

Status: Needs review » Fixed

fixed.

But you need to pay attention that this is due to Drupal core http://drupal.org/node/1102570
It can also happen in other place. http://drupal.org/node/1368930

mwallenberg’s picture

Great! Thanks for a nice module, by the way - it allows for some really solid publishing workflows using og that just aren't possible without it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

lord4gb’s picture

Thank you so much! Great fix.

jordisan’s picture

I hope this modification will be included in the next release

jordisan’s picture

Issue summary: View changes

fix typos