Szenario:
You have a nodetype with 2 view modes. Both should be displayed on the same page.
When you use token_insert_entity to do this, you will get a nasty fatal error:

"Fatal error: Unsupported operand types in /.../modules/node/node.module on line 1415"

Solution:
Clone the entity before calling entity_view(). A patch is attached.

Comments

jcnventura’s picture

Version: 7.x-1.x-dev » 7.x-1.1
StatusFileSize
new733 bytes

Update for v1.1

johnpitcairn’s picture

While it may work for you, is a clone appropriate here? The entity being rendered should be the same entity throughout the lifetime of the page, there shouldn't be a cloned copy hanging around. There is a drupal_alter() call from node_view(), then hook_field_attach_view_alter() runs, etc, and modules may have implemented earlier hooks, expecting to be altering the same entity each time, who knows what they may try to do? That clone makes me nervous.

There is a bug filed against node.module: #2385683: Ensure node content is an array before concatenating attached fields which proposes a clone. I have proposed a far more simple solution there.

johnpitcairn’s picture

johnpitcairn’s picture

Status: Needs review » Closed (works as designed)

@axe312: The patch against core in the related issue may work for you?

My thinking here is that this is not token_insert_entity's bug, it should be fixed in node module.