Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
A PHP warning is emitted when attempting to create a new node.
- Enable Organic groups moderation
- Start creating a new node. The node type must be set as group content.
- 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
Comment #1
shenzhuxi CreditAttribution: shenzhuxi commentedfixed.
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
Comment #2
mwallenberg CreditAttribution: mwallenberg commentedGreat! 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.
Comment #4
lord4gb CreditAttribution: lord4gb commentedThank you so much! Great fix.
Comment #5
jordisan CreditAttribution: jordisan commentedI hope this modification will be included in the next release
Comment #5.0
jordisan CreditAttribution: jordisan commentedfix typos