To reproduce this, add an entity reference field to an entity and have it target nodes of some bundle. You should start to see the error on the field edit page, and you will also see it on the create/edit form that has the IEF widget.

The problem seems to be that IEF is passing the bundle name into the $entity argument of entity_access when in fact this argument expects either NULL or a real entity.

This happens with Entity module version 7.x-1.1. Patch is attached.

Comments

dave reid’s picture

We're actually pretty sure this is a bug in entity's access system: #1780646: entity_access() fails to check node type specific create access

dpolant’s picture

StatusFileSize
new664 bytes

You are right. The new patch that creates a special case for nodes and just calls node_access instead of entity_access.

Its hard to make this fix generic for all entities because who knows how their entity access callbacks work. I think the best we can do now is just to make this work for nodes. In theory the individual entity modules can craft their entity access callbacks to accept a string for "create" checks like node_access does, and thus the entity_access call in IEF should work for them.

Not sure I like this ad-hoc approach, but short of creating some kind of hook/plugin structure through which modules that want to use IEF can say which way their access function works, there isn't a whole lot we can do. Just fixing node support seems like the best thing for IEF right now, until the community decides on a consistent approach for doing "create" access checks.

bojanz’s picture

I am not interested in committing a workaround for what is obviously an Entity API issue (and which already has patches).
Still, keeping the issue open for now.

JvE’s picture

Good thing you did.

Apparently the bug is in Inline Entity Form after all now that fago documented the 'create' case in #1780646: entity_access() fails to check node type specific create access:

$node = entity_create('node', array('type' => 'page'));
$access = entity_access('create', 'node', $node);

Pretty much exactly what's already in place for commerce entities.

mile23’s picture

JvE: That patch doesn't apply cleanly.

Here's a re-do. Apologies for not adding tests.

bojanz’s picture

Title: Notice: Trying to get property of non-object in entity_metadata_no_hook_node_access() .. when using IEF with entity reference » Invoke entity_access() properly for create operations
Status: Needs review » Fixed

Okay, committed, now it's up to Entity API to fix its bug :)

Status: Fixed » Closed (fixed)

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

RobertoGA’s picture

I'm using 7.x-1.3 version of Inline Entity Form where this patch has been applied and the errors continue appearing.

Apparently this error is not from IEF, is from Entity module. My issue has been solved at this entry appling the last patch at this moment:

1780646-202-entity-node-access.patch

I apologize for open the issue, I'm going to close it.