You are here

function private_content_node_grants in Private 8.2

Same name and namespace in other branches
  1. 8 private_content.module \private_content_node_grants()

Implements hook_node_grants().

Tell the node access system what GIDs the user belongs to for each realm.

File

./private_content.module, line 92
A tremendously simple access control module -- it allows users to mark individual nodes as private; users with 'access private content' perms can read these nodes, while others cannot.

Code

function private_content_node_grants(AccountInterface $account, $op) {
  $grants = array();
  if ($op == 'view') {
    if (!$account
      ->isAnonymous()) {

      // Grant to the author for own content.
      $grants['private_author'] = array(
        $account
          ->id(),
      );
    }

    // Grant for private content.
    if ($account
      ->hasPermission('access private content')) {
      $grants['private_view'] = array(
        PRIVATE_GRANT_ALL,
      );
    }
  }
  return $grants;
}