Came across a minor bug in node.pages.inc on line 367:
if (node_access('create', $node) || node_access('update', $node)) {
According to the API, the second argument of the node_access function should be:
The node object (or node array) on which the operation is to be performed, or node type (e.g. 'forum') for "create" operation.
Here, however, the node object is passed for the create operation while it should have been the node type:
if (node_access('create', $node->type) || node_access('update', $node)) {
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 655288-5.node-access-node-parameter.patch | 6.58 KB | rszrama |
| #4 | 655288.node-access-node-parameter.patch | 7.73 KB | rszrama |
| node.pages-node_preview_node_access.patch | 529 bytes | folkertdv |
Comments
Comment #1
thedavidmeister commentedyup, that's a bug.
unfortunately changing it means that a different data type will be passed to hook_access() implementations, which could cause downstream errors in contrib code that might outweigh any benefits in D6.
Hopefully everyone that this is causing a problem for has discovered this example in node_content_access().:
$type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);However, the bug technically still exists in D8:
That said, node_access() is now more defensive about how it handles passed in $node values:
so this issue exists in D8 but is even more minor than it was in D6.
Comment #2
thedavidmeister commentedComment #3
rszrama commentedWould it be untoward to reframe the issue like so? Generally speaking, it isn't good API design for the type of one function parameter to vary based on the value of another parameter. If we call that variable $node, it should always be a node! : )
Especially since node_access() is doing the conversion anyways... which means the docs for hook_node_access() must be wrong: $node will never be a string by that time, because:
If we decide it's too cumbersome to require invokers of node_access() to first create an empty node object, then we should make a wrapper along the lines of node_type_create_access() (or push "entity creation by type" access up the food chain).
Comment #4
rszrama commentedPatch attached moves forward with a small wrapper for create access. I wasn't sure on the parameter docs if I was specifying the type properly, though. i.e. I don't know for sure that $account always implements
Drupal\Core\Session\AccountInterface, I just saw that other modules documented $account parameters as such. Additionally, in some places there's a preceding \, in other places there isn't. Is there a standard?Also, I wasn't sure if the $account variable is actually supposed the be AccountInterface or some User related interface... went with account since that's what the access controller uses. And I saw that we specified in the .api.php an object for $langcode, but I'm pretty sure that's always a string.
Note that this fixes the OP by simply always making this a node entity. Confusion be gone.
Comment #5
rszrama commentedAnd here's another take that just uses
entity_create()inline in our calls tonode_access('create', ...).Comment #7
berdirnode_access() is just a deprecated wrapper that does this already internally, I think this issue is a duplicate of #1947880: Replace node_access() by $entity->access() and #1979094: Separate create access operation entity access controllers to avoid costly EntityNG instantiation.
If anything, something could be improved in 7.x/6.x but the other way round, as the initial bug report said, but I think that's unlikely to happen, as it is to be expected that the arguments differ, this can't be enforced, so doesn't seem worth the effort.
Comment #8
rszrama commentedGreat, didn't realize there were duplicates around. Saves me the trouble of finding out why the tests were failing. : )