You are here

function node_limit_node_prepare in Node Limit 7

Same name and namespace in other branches
  1. 8 old/node_limit.module \node_limit_node_prepare()

Implements hook_node_prepare().

This is where we'll determine if the user may create new nodes or not. We'll use hook_node_prepare, which is sent before the edit/add form is constructed.

File

./node_limit.module, line 204

Code

function node_limit_node_prepare($node) {
  if (empty($node->nid) && _node_limit_violates_limit($node)) {

    //we have a violation!

    //and this is a new node
    $nodetype = node_type_get_type($node);

    // Display message for user and redirect based on node limit settings.
    node_limit_message($nodetype);

    // Avoid redirection loop if there is just one content type
    $count = 0;
    foreach (node_type_get_types() as $type) {
      if (node_limit_access($type->name)) {
        $count++;
      }
    }
    if ($count > 1) {
      drupal_goto('node/add');
    }
    else {
      drupal_goto('');
    }
  }
}