When a ContentDM wrapper node it created, the author is always set to uid 0, the anonymous user. On our site it's important that wrapper nodes be owned by the user that created them, like other Drupal nodes, so contentdm_create_wrapper() should at least have that ability.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | contentdm-nodeauthor-1287976-3.patch | 1.45 KB | laken |
| #1 | contentdm-nodeauthor-1287976-1.patch | 1.33 KB | laken |
Comments
Comment #1
laken commentedHere's a simple patch that sets the wrapper node's author to the currently logged-in user. This should probably be expanded a bit to let the calling function pass in an $account parameter (which would default to $user->uid) for flexibility.
Comment #2
markj commentedThanks for the patch Andy, looks good. I'll test and push to -dev tomorrow some time.
Comment #3
laken commentedActually this patch was only working intermittently for me. If you look at node_submit() you'll see that, if the current user had 'administer nodes' permission, it checks $node->name and then sets $node->uid. Since we aren't setting $node->name in contentdm_create_wrapper(), this fails and $node->uid is set to 0 regardless of how we set it in contentdm_create_wrapper(). This also introduces different uid handling depending on whether it's an admin user or normal user, so it's kind of a mess.
A very experienced developer tells me the call to node_submit() is usually unnecessary, so I just removed it and everything seems to work, though I haven't tested with ContentDM Harvester yet. But here's a new patch.
Comment #4
markj commentedAndy, I'd rather populate $node->name in contentdm_create_wrapper() than omit node_submit(). With all respect to the developer who advised dropping node_submit(), I've learned that programatically creating nodes without calling that function leads to frustration. Would populating $node->name in contentdm_create_wrapper() solve the problem?
Comment #5
markj commentedAdmin option added to assign node ownership to user who first views the CONTENTdm item; pushed to -dev in commit d15c20f.