You are here

function node_limit_access in Node Limit 7

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

Custom access callback for node/add/TYPE pages.

Parameters

$type: Content type to check

$account: User account to check (default to current user)

3 calls to node_limit_access()
node_limit_init in ./node_limit.module
Implements hook_init().
node_limit_node_prepare in ./node_limit.module
Implements hook_node_prepare().
_node_limit_add_access in ./node_limit.module
Rewriten access callback for node/add page. Avoid access to this page when the user does not have the right to add any content type.
1 string reference to 'node_limit_access'
node_limit_menu_alter in ./node_limit.module
Implements hook_menu_alter().

File

./node_limit.module, line 159

Code

function node_limit_access($type, $context = '', $account = NULL) {
  global $user;
  if (empty($account)) {
    $account = $user;
  }
  $access =& drupal_static(__FUNCTION__, array());
  if (!array_key_exists($account->uid, $access)) {
    $access[$account->uid] = array();
  }
  if (!array_key_exists($type, $access[$account->uid])) {
    $node = new stdClass();
    $node->uid = $account->uid;
    $node->type = $type;
    $oldCallback = variable_get('node_limit_' . $type . '_access_callback');
    $oldArguments = variable_get('node_limit_' . $type . '_access_arguments', array());
    $oldAccess = function_exists($oldCallback) ? call_user_func_array($oldCallback, $oldArguments) : TRUE;
    $access[$account->uid][$type] = !_node_limit_violates_limit($node, $context) && $oldAccess;
  }
  return $access[$account->uid][$type];
}