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").
Comments
Comment #1
klonosComment #2
marcoscanoMight be related to #1957266: Rendered entity in views header accepting arguments from URL
Comment #3
emmonsaz CreditAttribution: emmonsaz commentedhttps://www.drupal.org/node/1957266 didn't fix it for me :(
Comment #4
emmonsaz CreditAttribution: emmonsaz commentedQuick hack to suppress the warning
Comment #5
jdhildeb CreditAttribution: jdhildeb commentedI 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.
Comment #6
jdhildeb CreditAttribution: jdhildeb commentedSorry - removed some unintended cruft from the previous patch. Attaching a new version.
Comment #7
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedIn my case this error occurs when passing
FALSE
for the node parameter: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.