2

I have a custom module that hooks into a commerce extension module.

The function splits a payment for a product and splits it to beneficiaries who helped create the product.

I use user_referance module in a field collection field in the product content type to store the beneficiary users from the system. The drupal system log shows this when running through the function

Warning: array_flip(): Can only flip STRING and INTEGER values! in      EntityAPIController->load() (line 219 of /www/opigno/profiles/opigno_lms/modules/contrib/entity/includes/entity.controller.inc).

Drupals error back trace function showed the error came from this line

  if (!empty($item_id)){
      $split_pay = commerce_funds_object_to_array(entity_load('field_collection_item',
array($item_id)));
  }

The function does run through fine but I'd like to squash any bugs that are appearing, the $item_id array only contains the user_ids of beneficiary users so i don't really understand why a non integer value is being passed

  • 1
    What exactly is in $item_id? It should be integer, or integer-compatible string, if you have something else there, you will have problems. Have you tried to kpr($item_id) before calling entity_load? – Mołot Aug 20 '14 at 8:41
  • xdebug is showing this $item_id = {array}[2] 0 = "12" 1 = "14" – James Kirkby Aug 20 '14 at 10:47
  • 2
    So just don't wrap $item_id into array. It already is an array. Use it directly, entity_load('field_collection_item', $item_id) – Mołot Aug 20 '14 at 11:04
2

I had a similar issue, you just have to be sure it is an integer and not a string, also you can use entity_load_single:

if (!empty($item_id)){
$item_id = (int) $item_id;
  $split_pay = commerce_funds_object_to_array(entity_load_single('field_collection_item', $item_id));
}
  • Not worked for me – Yusef Jul 21 '15 at 18:34
  • "entity_load_single" only works for ECK , though. – PedroSP Jul 23 '15 at 6:22
0

If your $item_id is already array as you've mentioned:

$item_id = {array}[2] 0 = "12" 1 = "14"

then you don't need to wrap it again into array.

Use it directly, like:

entity_load('field_collection_item', $item_id);

as per @Mołot suggestion, or just make sure it's in the right expected format.

See: entity_load() API:

$ids: An array of entity IDs, or FALSE to load all entities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.