Hey all,

I need some help with what should be a simple matter: what is the way to differentiate between a user creating a new node vs editing an existing one? I'm trying to limit a certain content type to one per user, and thus I want to stop the creation of new nodes of that type if one by that user exists already.

I've tried hooking hook_nodeapi() and processing the 'prepare' operation, but as far as I can tell there is no way to distinguish between an add and an edit there. Can someone please shed some light? perhaps I should be looking at a different hook instead?

Thanks in advance for any advice!

Comments

nevets’s picture

You might want to check out the Node Limit module which already provide the functionality.

As for you question check $node->nid which should be non zero for existing nodes and zero/unset for new nodes for any operation that occur before the node is saved.

skourak’s picture

Excellent information, exactly what I needed. Much appreciated!