When field collections are viewed in the node (in this case, user) display, an error is generated:

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in EntityAPIController->load() (line 202 of /localhost/Sites/acq-dpl/drupal-7.0/sites/all/modules/entity/includes/entity.controller.inc).

I have confirmed that the error appears with all List Field and View Field collections. Only if it is hidden does it the error disappear. Which sort of defeats the purpose of the seeing the field.

Comments

mariagwyn’s picture

This also seems to be an issue on beta1.

RobW’s picture

Project: Field collection » Entity API
Component: Code » Code - misc

Looks like this is an entity bug. I ran into something similar using entity_load(), when I accidentally provided a nested array as the value for the loaded $ids, throwing errors as it tried to use the nested array as a key - might be a similar mistake in entity.controller.inc.

RobW’s picture

Project: Entity API » Field collection
Component: Code - misc » Code

Sorry, after looking closer this probably is a field collection bug.

mariagwyn’s picture

I am not a coder, so I can't help on that end, but I can patch and test, and am happy to do so.

fago’s picture

Status: Active » Postponed (maintainer needs more info)

Does the error appear with the latest module versions of entity API & field-collection? If yes, does it appear for newly created host-entities + field-collections too? If still yes, please provide some more details about your configuration (field settings, formatter settings).

mariagwyn’s picture

I just upgraded to the dev versions of Fiel Collection and Entity API. I then reset the field to display as both View and List. In both cases, I received the same set of errors as above.

I have two field collections. One (Institution) has two text fields, plain format, one value allowed. The other (Education) has two text fields, one date field. In both cases, only one value for each field is allowed, but the collection itself allows multiple values. The number of warnings increases if there are values in the fields. With no values, there are six warnings. If there is data in the fields, I get eleven warnings (perhaps for the 5 fields within the two collections?).

What more can I tell you that will help?

One note: if I use a view to output these fields, the fields display just fine. It is likely that I will use a view to do this. However, since these field collections are not available on the node (again, in this case a user) edit area, there is no way to add data to these fields without showing them, which causes the error.

mariagwyn’s picture

oops, I missed your second question. I went back, tested further by creating two new collections with simple test fields. They worked just fine, added just fine, displayed just fine.

I am going to recreate my problem fields, and if all works with no further error, I will mark this closed.

mariagwyn’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)
nylin’s picture

Status: Closed (fixed) » Needs work

I've updated the Entity API and the Field Collection modules to their dev releases, do I have to delete all of my already existing field collections and add them again for this to work normally? The problem is that I have ALOT of them, is there any onther way?

I would't say this issue is not quite fixed yet :)

gbernier’s picture

To chime in we are getting this error use Field collection 7.x.1.0-beta4 and entity api 7.x.1.0-rc3

The field collections we are loading get loaded but still the warning gets thrown

Cheers,
Gene Bernier

TBarina’s picture

I have the same error with 7x.1.0-dev + entity api 7.x.1.0-rc3

Best regards
Tommaso

kscheirer’s picture

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

#9 -through #11 reopened this issue - can you provide details on how to reproduce this bug? According to the original post, this occurs when you have "with all List Field and View Field collections." I've been able to create a field collection with just list values without any error. Using field-collection-7.x-1.0-beta4+14-dev and entity-7.x-1.0-rc3+11-dev.

sokrplare’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

I was running into this with field_collection-7.x-1.0-beta3 and entity-7.x-1.0-rc1 - had the entity part of the patch from http://drupal.org/node/1003788#comment-6110312 applied to fix this.

Just upgraded to field_collection-7.x-1.0-beta3 and entity-7.x-1.0 and this error seems to have gone away so closing this ticket for now - if anyone else is on latest versions of these and still seeing it please reopen!

alienzed’s picture

Status: Closed (cannot reproduce) » Active

I'm getting this with field-collection-7.x-1.0-beta5 and entity-7.x-1.1 :(

biff45452’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta5
Issue summary: View changes

I was getting this error and I found out that it was because I was putting the field value into entity_load like so:

$entity_id = $node->field_some_collection['und'][0]['value'];
$entities = entity_load('field_collection_item', array($entity_id));

It seems the error came from the fact that the value was a string and should actually be an integer so changing my code to this cleared up the errors:

$entity_id = (int) $node->field_some_collection['und'][0]['value'];
$entities = entity_load('field_collection_item', array($entity_id));

Hope this helps.

jmuzz’s picture

Status: Active » Postponed (maintainer needs more info)

I was not able to reproduce this. I installed the Viewfield module, created a page view for a simple content type with a few items, made a content type with a field collection that contained a viewfield, and made an instance of that content referencing my view. I was able to view the node without errors. I did not test the list field module.

Can you provide more specific steps to reproduce this error?

Barto.G’s picture

#15 is the magic number.
I had the same problem and converting the entity id from string to integer fixed the problem

Thanks

prabeen.giri’s picture

I had the same problem , I also solved converting the entity ids that I got from EntityFieldQuery to integer.
From:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'dashboard_layout');
$result = $query->execute();
return entity_load('dashboard_layout', $result['dashboard_layout']);

To:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'dashboard_layout');
$result = $query->execute();
$layouts = array_map(function($layout_id) {
    return (int)$layout_id;
}, array_keys($result['dashboard_layout']));

return entity_load('dashboard_layout', $layouts);
jmuzz’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
Guito339’s picture

I ran into this when trying to load a full entity as opposed to an id. Silly mistake, but it happens.

My menu used the auto load arguments syntax like so:

function my_module_hook_menu() {
  $items = array();

  $items['my/path/%my_entity'] = array(
    'title' => t('My Title'),
    'page_callback' => 'my_module_my_callback',
    'page arguments' => array(2),
    'access arguments' => TRUE, // You should not do this as this is for the purpose of this code example
  );

  return $items;
}

The callback function:

function my_module_my_callback($my_entity_id) {
  $my_entity = my_entity_load($my_entity_id);
  // This line caused the warning as I have a full fledged entity already in $my_entity_id
  // based on the load argument from my menu item /my/path/%my_entity
  // Moreover $my_entity_id is a bad parameter name as I have a full entity already as opposed to just an id.
}

Two ways to get rid of the warning:

  1. change the menu path to my/path/% (remove the load argument)
    function my_module_hook_menu() {
      $items = array();
    
      $items['my/path/%'] = array(
        'title' => t('My Title'),
        'page_callback' => 'my_module_my_callback',
        'page arguments' => array(2),
        'access arguments' => TRUE, // You should not do this as this is for the purpose of this code example
      );
    
      return $items;
    }
    
    function my_module_my_callback($my_entity_id) {
      $my_entity = my_entity_load($my_entity_id);
      // This will now work and not issue the warning as you do have an an id and not an entity.
      // Of course you should add some validation before using the parameter as it does come from the url.
    }
    
  2. change the parameter in the

    my_module_my_callback

    function to

    $my_entity

    and remove the line

    $my_entity = my_entity_load($my_entity_id);

    as you already have the full entity in $my_entity as per the auto load argument in the menu path.
    function my_module_hook_menu() {
      $items = array();
    
      $items['my/path/%my_entity'] = array(
        'title' => t('My Title'),
        'page_callback' => 'my_module_my_callback',
        'page arguments' => array(2),
        'access arguments' => TRUE, // You should not do this as this is for the purpose of this code example
      );
    
      return $items;
    }
    
    function my_module_my_callback($my_entity) {
      // just use $my_entity as needed as the fully fledged entity object you get from the auto loader
      echo $my_entity->some_property.
    }
    

I'd use the second option and let drupal make the my_entity_load function call for me, but I'm lazy.

The documentation for this is available at:
https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_menu/7

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Auto-Loader Wildcards

Registered paths may also contain special "auto-loader" wildcard components in the form of '%mymodule_abc', where the '%' part means that this path component is a wildcard, and the 'mymodule_abc' part defines the prefix for a load function, which here would be named mymodule_abc_load(). When a matching path is requested, your load function will receive as its first argument the path component in the position of the wildcard; load functions may also be passed additional arguments (see "load arguments" in the return value section below). For example, your module could register path 'my-module/%mymodule_abc/edit':

$items['my-module/%mymodule_abc/edit'] = array(
'page callback' => 'mymodule_abc_edit',
'page arguments' => array(1),
);

When path 'my-module/123/edit' is requested, your load function mymodule_abc_load() will be invoked with the argument '123', and should load and return an "abc" object with internal id 123:

function mymodule_abc_load($abc_id) {
return db_query("SELECT * FROM {mymodule_abc} WHERE abc_id = :abc_id", array(':abc_id' => $abc_id))->fetchObject();
}

This 'abc' object will then be passed into the callback functions defined for the menu item, such as the page callback function mymodule_abc_edit() to replace the integer 1 in the argument array. Note that a load function should return FALSE when it is unable to provide a loadable object. For example, the node_load() function for the 'node/%node/edit' menu item will return FALSE for the path 'node/999/edit' if a node with a node ID of 999 does not exist. The menu routing system will return a 404 error in this case.

drupalgideon’s picture

Version: 7.x-1.0-beta5 » 7.x-1.0-beta8

I had this error when the field_collection_item_load() function was being called in a custom module with an empty ID. I solved it by checking that to see if the value was an integer or not and then ran the function if it was.

However, I think that the field_collection_item_load_multiple or field_collection_item_load functions should contain some basic checking to see that the passed value is an integer.

So

function field_collection_item_load($item_id, $reset = FALSE) {
  $result = field_collection_item_load_multiple(array($item_id), array(), $reset);
  return $result ? reset($result) : FALSE;
}

could become

function field_collection_item_load($item_id, $reset = FALSE) {
  if (is_integer($item_id)) {
    $result = field_collection_item_load_multiple(array($item_id), array(), $reset);
    return $result ? reset($result) : FALSE;
  }
  return FALSE;
}

for example. Happy to create a patch if you'd like.