You are here

function entity_metadata_no_hook_node_access in Entity API 7

Access callback for the node entity.

This function does not implement hook_node_access(), thus it may not be called entity_metadata_node_access().

Parameters

$op: The operation being performed. One of 'view', 'update', 'create' or 'delete'.

$node: A node to check access for. Must be a node object. Must have nid, except in the case of 'create' operations.

$account: The user to check for. Leave it to NULL to check for the global user.

Return value

bool TRUE if access is allowed, FALSE otherwise.

Throws

EntityMalformedException

See also

entity_access()

2 string references to 'entity_metadata_no_hook_node_access'
entity_metadata_hook_entity_info in ./entity.api.php
Provide additional metadata for entities.
_entity_info_add_metadata in ./entity.module
Adds metadata and callbacks for core entities to the entity info.

File

modules/callbacks.inc, line 683
Provides various callbacks for the whole core module integration.

Code

function entity_metadata_no_hook_node_access($op, $node = NULL, $account = NULL) {

  // First deal with the case where a $node is provided.
  if (isset($node)) {
    if (empty($node->vid) && in_array($op, array(
      'create',
      'update',
    ))) {

      // This is a new node or the original node.
      if (isset($node->type)) {
        $op = empty($node->nid) || !empty($node->is_new) ? 'create' : 'update';
        return node_access($op, $op == 'create' ? $node->type : $node, $account);
      }
      else {
        throw new EntityMalformedException('Permission to create a node was requested but no node type was given.');
      }
    }

    // If a non-default revision is given, incorporate revision access.
    $default_revision = node_load($node->nid);
    if ($node->vid !== $default_revision->vid) {
      return _node_revision_access($node, $op, $account);
    }
    else {
      return node_access($op, $node, $account);
    }
  }

  // No node is provided. Check for access to all nodes.
  if (user_access('bypass node access', $account)) {
    return TRUE;
  }
  if (!user_access('access content', $account)) {
    return FALSE;
  }
  if ($op == 'view' && node_access_view_all_nodes($account)) {
    return TRUE;
  }
  return FALSE;
}