Problem/Motivation

I have a node with a field_collection and have 2 entityreference field value tokens as such:

[field_collection_item:host:node:field-research-area:id]
[field_collection_item:host:node:field-year:id]

This fatal only happens on the first save of the host node's field because the value passed to the token is the stdClass object of the field collection through entityreference_field_validate and doesn't have access to the methods of FieldCollectionItemEntity.

The original stdClass object get's created here entity_form_field_validate which thinks it doesn't have a real object and passes it along as if it were and entity.

Proposed resolution

Ignore non-FieldCollectionItemEntity objects. Since it doesn't effect the first two normal calls to field_collection_tokens with real entities.

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Status: Active » Needs review
StatusFileSize
new859 bytes
joelpittet’s picture

bump, still an issue

joelpittet’s picture

StatusFileSize
new855 bytes

Sorry I put up the wrong patch with the helping code commented out in #2.

We ran the bug again today.

renatog’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for your patch, it really makes sense

renatog’s picture

Status: Reviewed & tested by the community » Fixed

It was moved to the dev branch in another issue with a similar way

if ($collection instanceof FieldCollectionItemEntity && $entity_tokens = token_find_with_prefix($tokens, $entity_type)) {
  $host = $collection->hostEntity();
  $replacements += token_generate($entity_type, $entity_tokens, array($entity_type => $host), $options);
}

Thank you so much for that

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.