You are here

function private_node_access_records in Private 5

Same name and namespace in other branches
  1. 6 private.module \private_node_access_records()
  2. 7.2 private.module \private_node_access_records()
  3. 7 private.module \private_node_access_records()

Implementation of hook_node_access_records().

All node access modules must implement this hook. If the module is interested in the privacy of the node passed in, return a list of node access values for each grant ID we offer. Since this example module only offers 1 grant ID, we will only ever be returning one record.

File

./private.module, line 106
This is an example illustrating how to restrict access to nodes based on some criterion associated with the user.

Code

function private_node_access_records($node) {
  if (private_disabling()) {
    return;
  }

  // We only care about the node if it's been marked private. If not, it is
  // treated just like any other node and we completely ignore it.
  if ($node->private) {
    $grants = array();
    $grants[] = array(
      'realm' => 'example',
      'gid' => TRUE,
      'grant_view' => TRUE,
      'grant_update' => FALSE,
      'grant_delete' => FALSE,
      'priority' => 0,
    );

    // For the example_author array, the GID is equivalent to a UID, which
    // means there are many many groups of just 1 user.
    $grants[] = array(
      'realm' => 'example_author',
      'gid' => $node->uid,
      'grant_view' => TRUE,
      'grant_update' => TRUE,
      'grant_delete' => TRUE,
      'priority' => 0,
    );
    return $grants;
  }
}