By jnvsor on
I'm writing a small one-use, hardcoded module to allow a user to only create one of a type of node (No, profile module won't work)
As it is, I can get it to return the node creation page when the user doesn't have one of that type of node yet, but not the edit page when the user does have one.
function bedrijven_node_add($type) {
$result = db_select('node', 'n')
->fields('n', array('nid','title','type'))
->condition('uid', $GLOBALS['user']->uid)
->condition('type', 'bedrijven')
->orderBy('created', 'DESC')
->range(0,1)
->execute();
if ($result->rowCount()) # If user already has a node of this type
return node_page_edit($result->fetchAssoc()); # Redirect the user
# This part here isn't working, I don't know how to get the result I want to node_page_edit, it wants a $node object
else # Otherwise
return node_add($type); # Just add a new one
}Edit: This works, but I doubt it's the most efficient or "Correct" way of doing it:
$result = $result->fetchAssoc();
$result = node_load($result['nid']);
return node_page_edit($result);