On a site I'm developing each user can have only 1 of a specific node type.

As I've been unable to find a module to handle it (profile isn't quite what I'm looking for) I'm beginning to make one myself, and it's my first.

One possible solution would be to just alter the menu so that the node create link for this node type redirects to the edit link for the users current node, however this still allows users to create nodes they shouldn't be able to with the node/create url, an XSS attack.

I would like to catch the drupal creation of the node create page itsself and then (Based on a query as to weather the user already has such a node type) either continue loading the node creation page, or instead load the edit page, to avoid url hacks like that.

My problem is that I don't know where to hook the node creation pipeline to do this.

Comments

nevets’s picture

I would implement hook_menu_alter() something like this

function yourmodule_menu_alter((&$items) {
  // You need to replace yourtype with the machine name you want to limit
  $path = 'node/add/yourtype';
  if ( !empty($items[$path]) ) {
    $items[$path]['page callback'] = 'yourmodule_node_add';
  }
}

and pseudo code yourmodule_node_add would be something like

function yourmodule_node_add($type) {
  if user already as a node of this type
     redirect the user to the edit page
  else
      return node_add($type);
}
jnvsor’s picture

So this allows me to serve a different page than the one normally provided at that url, or does it only alter actual menus?

nevets’s picture

It handles any use of the path node/add/yourtype

kuldeep k’s picture

I need a help about fbconnect for drupal.

nevets’s picture

You should open a new issue as this one has nothing to do with fbconnect