Symptom

When attempting to create a new node with the OG prepopulated, I get the following PHP Warning:

Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 173 of /Volumes/Macintosh_HD/Users/samueloltz/Sites/rapid/crcna/includes/entity.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 350 of /Volumes/Macintosh_HD/Users/samueloltz/Sites/rapid/crcna/includes/entity.inc).

Cause

At first I thought it was an error with Entityreference prepopulate, but I traced the issue back to how og_context_handler_url() uses entityreference_prepopulate_get_values_from_url() on line 412. The function uses these values and puts them right into entity_load() on line 421. The problem is that entity_load() expects a single dimensional numeric array of entity ids to load, but the value return from entityreference_prepopulate_get_values_from_url() is a multi-dimensional, string keyed array.

Solution

The solution is to modify $ids, which is the value returned from entityreference_prepopulate_get_values_from_url(), before sending it to entity_load().

CommentFileSizeAuthor
#1 og_context.module-2118719-2.patch619 bytespianomansam
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pianomansam’s picture

Version: 7.x-2.3 » 7.x-2.x-dev
Status: Active » Needs review
FileSize
619 bytes

Quick attempt at a patch. Applied an array_map to prepare the $ids value for entity_load(). This will only work on PHP 5.3, however since it uses a lambda function.

shushu’s picture

Assigned: Unassigned » shushu
Issue summary: View changes
shushu’s picture

Status: Needs review » Postponed (maintainer needs more info)

First, I wasn't able to reproduce the error.
Second, entityreference_prepopulate_get_values_from_url() return an array of values taken from the URL:

/**
 * Get values for prepopulating fields via URL.
 *
 * @param $field
 *   The field info array.
 * @param $instance
 *   The instance info array.
 *
 * @see
 *   entityreference_prepopulate_get_values()
 */
function entityreference_prepopulate_get_values_from_url($field, $instance) {
  $field_name = $field['field_name'];
  if (!empty($_GET[$field_name]) && is_string($_GET[$field_name])) {
    return explode(',', $_GET[$field_name]);
  }
}

So I can't see a situation in which array_flip will get into troubles.

Still, in case you do encounter this problem, please send more info and I will try to reproduce it.

shushu’s picture

Assigned: shushu » Unassigned
fago’s picture

ran into this as well, ust be sure to have entityreference_prepopulate upgraded to a latest release.