I get this notice when I try to embed a node (add it as a header in a view) by using its URL instead of its ID:

Notice: Trying to get property of non-object in entity_metadata_no_hook_node_access() (line 682 of /www/sites/all/modules/entity/modules/callbacks.inc).

Say I have a content node with ID 3 (under /node/3) and this node has a custom URL (pathauto) of /page/views_header_page,

Create a view and add a header to it. In the header settings, select "node" as entity type and for entity id set page/views_header_page (instead of 3). Save the view...

Expected result: the view should be rendered correctly with the node attached as header.

Actual result: the view is rendered, but the node is not rendered as header and there is a series of the above-mentioned notices.

PS: I realize that the field says "Entity ID" and that it is obvious that it expects a node ID, so this issue here might not be considered a bug but a feature request instead. In that case, feel free to change the issue type to "feature". If implemented, the field label should then be changed to "Entity ID or path" (or simply "Entity").

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

klonos’s picture

Issue summary: View changes
marcoscano’s picture

emmonsaz’s picture

https://www.drupal.org/node/1957266 didn't fix it for me :(

emmonsaz’s picture

jdhildeb’s picture

I get this same error when trying to preview a node which contains a field collection (field_collection module).

In my situation, after this line executes:
$default_revision = node_load($node->nid);

$default_revision is FALSE. This causes the next line:

if ($node->vid !== $default_revision->vid) {

to fail because $default_revision is not an object.

Though the error is the same as emmonsaz gets, the cause is slightly different - in his case it is because $node is not set.

I am attaching a patch which checks both $node and $default_revision - it fixes both variants of this bug.

jdhildeb’s picture

Sorry - removed some unintended cruft from the previous patch. Attaching a new version.

MegaChriz’s picture

In my case this error occurs when passing FALSE for the node parameter:

// Load a node that does not exist.
$node = entity_load_single('node', 1234);
// Check access.
entity_access('view', 'node', $node);

I think that in this case the calling code is wrong. It should not call entity_access() for a non-existing node. This can sometimes happen when access is checked for entities referenced in an entityreference field. References are not automatically cleaned up when the entity in question gets deleted, see #1368386: Delete references to deleted entities.

I think that the function should throw an exception if FALSE is passed as $node parameter.

See also the attached tests only patch.

Status: Needs review » Needs work

The last submitted patch, 7: entity-entity-metadata-no-hook-node-access-warning-2473987-7-tests-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.