I am developing module, in which I need to let users create only one node of this type, if node of this type exists, user should be redirected to edit page of this node. Which hook I should use ?

Best Regards,
Cris

Comments

johngriffin’s picture

Hi,

You could try this module:

http://drupal.org/project/node_limit

I think it may only allow you to restrict the number of nodes that a user/role can create though, rather than limiting the number of nodes of a particular type.

If that's the case then you'll have to use hook_nodeapi (assuming your content type is created by another module, e.g. CCK) to perform a check when $op == validate and use form_set_error() if a node already exists.

John

John Griffin
Atchai Digital

kcybulski’s picture

I am using my module content type. Using hook_form and drupal_redirect_form or drupal_goto give me partial success.

Function

production_form(&$node) {
global $user;
$row = db_fetch_object(db_query("SELECT nid FROM {node} WHERE type in ('production') AND uid = %d", $user->uid));
if (isset($row->nid)) {
$redir = "node/$row->nid";
$form2['#redirect'] = $redir;

return drupal_redirect_form($form2);
//return drupal_goto($redir);
}
.... my actual form
}

This redirect me when I open 'node/add/production' to '/node/%nid', but when I try $redir = "node/$row->nid/edit"; i get browser error "redirection loop". Any ideas ?

EDIT:

if (!isset($node->nid)) {
return drupal_goto($redir);
}

solved problem

Best Regards,
Cris

Imaaxa-Cory’s picture

Test to see if drupal is going to /node/add/[content-type]. If so, then try to redirect to /node/[nid]/edit.