Skip to content

Notice: Trying to get property 'type' of non-object in node_node_access() #5473

Open
backdrop/backdrop
#3919
@argiepiano

Description

@argiepiano

Description of the bug

This notice is thrown when using entity_access to check node (and possibly other entities') "create" access for a user that doesn't have a "Bypass content access control" permission.

Steps To Reproduce

Create a user without Bypass permission. Then run the following in Devel:

$user = user_load(9); // In my case, this user has uid == 9.  To test, you must use the uid of the user you created.
dpm(entity_access('create', 'node', NULL, $user ));

Actual behavior

Backdrop throws the Notice in the subject of this issue.

Expected behavior

There shouldn't be a Notice.

Additional information

The third argument of entity_access can either be a node entity, or null (as in this case). entity_access invokes Node:createAccess which allows a null value for the $bundle (first) argument. All good so far.

The problem happens when Node:createAccess() invokes hook_node_access. At this point node_node_access() is invoked. The first argument is null. But node_node_access() doesn't know how to handle null and the notice is thrown.

I guess an important question is - what does it mean to pass null as the first argument of node_node_access()? In the example above with entity_access() (which is actually invoked by Rules), the goal was to know if a user can create any bundle of nodes. Currently there is no node permission that specifically refers to the creation of nodes of any bundle - rather they are tailored to specific bundles (e.g. create page, create post). The one that comes closest is administer content.

So, one way to fix this might be for node_node_access() to interpret a null value in $node to mean the creation of any type of content, i.e. 'administer content', and to perform a check on that and return either allow or deny. Another way may be to return NODE_ACCESS_IGNORE. But the status quo leads to the Notice.

THEN, there is another problem: lines 251 to 261 on Node:createAccess(), where $bundle (i.e. NULL) is used to set the $rights static cache array. Not sure if this is on purpose or if it's an oversight.

I will submit a PR for a potential fix following fix (1) above. But I'll appreciate any thoughts.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions