1 node.entity.inc public static Node::createAccess($bundle = NULL, $account = NULL)

Overrides Entity::createAccess().

Overrides Entity::createAccess

File

core/modules/node/node.entity.inc, line 212
Entity controller and class for nodes.

Class

Node
Defines the node entity class.

Code

public static function createAccess($bundle = NULL, $account = NULL) {
  $rights = &backdrop_static('node_access', array());

  // If no user object is supplied, the access check is for the current user.
  if (empty($account)) {
    $account = $GLOBALS['user'];
  }

  // If we've already checked access for this node, user and op, return from
  // cache.
  if (isset($rights[$account->uid][$bundle])) {
    return $rights[$account->uid][$bundle];
  }

  if (user_access('bypass node access', $account)) {
    $rights[$account->uid][$bundle] = TRUE;
    return $rights[$account->uid][$bundle];
  }
  if (!user_access('access content', $account)) {
    $rights[$account->uid][$bundle] = FALSE;
    return $rights[$account->uid][$bundle];
  }

  // We grant access to the node if both of the following conditions are met:
  // - No modules say to deny access.
  // - At least one module says to grant access.
  // If no module specified either allow or deny, we fall back to the
  // node_access table.
  $access = module_invoke_all('node_access', $bundle, 'create', $account);
  if (in_array(NODE_ACCESS_DENY, $access, TRUE)) {
    $rights[$account->uid][$bundle] = FALSE;
    return $rights[$account->uid][$bundle];
  }
  elseif (in_array(NODE_ACCESS_ALLOW, $access, TRUE)) {
    $rights[$account->uid][$bundle] = TRUE;
    return $rights[$account->uid][$bundle];
  }

  $rights[$account->uid][$bundle] = FALSE;
  return $rights[$account->uid][$bundle];
}