You are here

function private_content_node_grants in Private 8

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

Implements hook_node_grants().

File

./private_content.module, line 79
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) {

  // First grant a grant to the author for own content.
  $grants['private_author'] = array(
    $account
      ->id(),
  );
  if ($op == 'view' && $account
    ->hasPermission('access private content')) {
    $grants['private_view'] = array(
      PRIVATE_GRANT_ALL,
    );
  }
  if (($op == 'update' || $op == 'delete') && $account
    ->hasPermission('edit private content')) {
    $grants['private_edit'] = array(
      PRIVATE_GRANT_ALL,
    );
  }
  return $grants;
}