This only began happening after I put alpha5 in to replace the old experimental version (the only change). Now we get several every time we save a node.

Comments

nancydru’s picture

In cer_get_field_collection_lineage_array(), $collection->hostEntityType() is returning nothing. You can duke it out with Field Collection as to who has the bug.

cer 7.x-3.0-alpha5
field_collection 7.x-1.0-beta7
entity 7.x-1.5
Drupal 7.30 (also on 7.28)

nancydru’s picture

This seems to avoid the problem for me.

  $data[0] = $collection->hostEntityType();
  $data[1] = $collection->hostEntity();
  if (empty($data[0])) {
    $query = "SELECT entity_id, entity_type FROM {field_data_" . $collection->field_name 
      . "} WHERE " . $collection->field_name . "_value = :id ";
    $result = db_query($query, array(':id' => $collection->item_id))->fetchAllKeyed();
    $type = reset($result);
    $data[0] = $type;
    $data[1] = array_pop(entity_load($type, array(key($result))));    
  }
  list (, , $host_bundle) = entity_extract_IDs($data[0], $data[1]);
nancydru’s picture

Priority: Normal » Major

This is driving my users crazy. Have you got any ideas?

phenaproxima’s picture

Looking at Field Collection's code, it appears that $collection->hostEntityType() will return NULL if the host entity's ID cannot be loaded by $collection->fetchHostDetails(). There seem to be a few reasons why that could happen, but the bottom line is that I don't think this is a bug in CER (or even necessarily in Field Collection). It may be site-specific, but without knowing more about your configuration I cannot say for sure.

One option is for you to override cer_get_field_collection_lineage_array() with your version from #2. You can do that by implementing hook_entity_property_info_alter() and modifying the getter callback for the lineage property (part of the cer struct) that CER exposes on field collection items. Does that make sense?

Hope this helps.

nancydru’s picture

Yes and no. I'm not doing anything super-fancy, so I am confused as to why this is failing.

phenaproxima’s picture

Is there any chance I could poke around on your dev site (assuming this is happening there too)?

nancydru’s picture

nancydru’s picture

Okay, back to this. Unfortunately, the dev site is behind a company firewall.

The node I am looking at has TWO field collections. In cer_get_field_collection_lineage_array() I stuck a dpm($collection, 'collection', 'error') right after the first line ($collection = $data[1];) and I see it displayed THREE times. The first two have valid HostEntity stuff, but the third one is empty.

The node does display an "Add Another" button, but there is not an extra one present. And when I build the node, I am adding only two field_collections.

recrit’s picture

Potential fix at #2458891: Host entity should be updated for revision changes. This issue and patch addresses the general issue of any module implementing hooks during the field collection update save.

amir simantov’s picture

Cross referencing with a similar issue: #2249067: Undefined index: entity keys in entity_extract_ids() on node_save()
If duplicated, one of them should be closed.

amir simantov’s picture

I have tested the patch from field_collection: #2458891: Host entity should be updated for revision changes
It seems to eliminate the error for me.
I leave it to the maintainer to decide whether to close it.

nancydru’s picture

Status: Active » Closed (duplicate)

I opened it, so I'm marking it duplicate.

BarisW’s picture

Version: 7.x-3.0-alpha5 » 7.x-3.0-alpha7
Status: Closed (duplicate) » Active

Can this be re-opened? I updated field_collection, which includes #2458891: Host entity should be updated for revision changes.
I'm still getting the following error:

Notice: Undefined index: entity keys in entity_extract_ids() (line 7783 of /includes/common.inc).

I'm using Field Collection and Corresponding Entity References.

BarisW’s picture

phenaproxima’s picture

@BarisW, did you update to the latest *dev* of Field Collection? AFAIK that patch is not in the stable release yet.

BarisW’s picture

Version: 7.x-3.0-alpha7 » 7.x-3.x-dev
Status: Active » Closed (fixed)

@phenaproxima; sigh. You were right. Updating to dev fixes the issue. Thanks!

miroslavbanov’s picture

Status: Closed (fixed) » Needs work

Notice: Undefined index: entity keys in entity_extract_ids()
I am still getting the error, with the latest version of field_collection module. I use workbench_moderation and other modules that add to the complexity, and may be related.
Patch #2458891-1: Host entity should be updated for revision changes makes it so the entity is returned, but the entity type is not.

  $data[0] = $collection->hostEntityType();
  $data[1] = $collection->hostEntity();

In my case $data[0] should be "node", but it is empty instead.

phenaproxima’s picture

Are you using the dev version of field_collection? I'm not certain, but I don't think that patch has been merged into the stable release.

miroslavbanov’s picture

I am using latest 7.x-1.x

miroslavbanov’s picture

Status: Needs work » Fixed

OK, this seems to be reproducible without CER (only field_collection), and seems to be related to Workbench moderation. Happens specifically when updating a revision-moderation-enabled content, that is published, and a new revision exists, and the revision is being updated, but it is still kept as Draft.

I am using 7.x-1.x version of Workbench moderation.

Closing task again as problem is not with CER.

phenaproxima’s picture

Status: Fixed » Closed (fixed)