You are here

function views_node_access_filter_node_grants in Views Node Access Filter 8

Implements hook_node_grants().

See also

node_query_node_access_alter()

node_node_access()

File

./views_node_access_filter.access_records.inc, line 41
Node access hooks.

Code

function views_node_access_filter_node_grants(AccountInterface $account, $op) {
  $grants = [];
  if ($op == 'update') {
    foreach (array_keys(NodeType::loadMultiple()) as $type) {
      if ($account
        ->hasPermission('edit any ' . $type . ' content')) {
        $grants['edit any ' . $type . ' content'] = [
          0,
        ];
      }
      elseif ($account
        ->id() && $account
        ->hasPermission('edit own ' . $type . ' content')) {
        $grants['edit own ' . $type . ' content'] = [
          $account
            ->id(),
        ];
      }
    }
  }
  elseif ($op == 'view') {
    if ($account
      ->hasPermission('view own unpublished content')) {
      $grants['view own unpublished content'] = [
        $account
          ->id(),
      ];
    }
  }
  return $grants;
}