You are here

public function NodeTypeAccessService::hookNodeAccess in Nodetype access 8

Implements hook_node_access().

Why does this use forbiddenIf()? The main controller uses allowedIf() so if we want an AND conjunction we must use the stronger forbiddenIf(). (Which also means: If we want to OR this result with something else like OG access, we can not use independent node access hooks, but somehow must consolidate both results first.)

Parameters

\Drupal\node\NodeInterface $node:

string $op:

\Drupal\Core\Session\AccountInterface $account:

Return value

\Drupal\Core\Access\AccessResultInterface

See also

\Drupal\Core\Entity\EntityAccessControlHandler::access

\Drupal\Core\Entity\EntityAccessControlHandler::checkAccess

\Drupal\node\NodeAccessControlHandler::access

\Drupal\node\NodeAccessControlHandler::checkAccess

\Drupal\node\NodeGrantDatabaseStorage::access

File

src/NodeTypeAccessService.php, line 81

Class

NodeTypeAccessService

Namespace

Drupal\nodetype_access

Code

public function hookNodeAccess(NodeInterface $node, $op, AccountInterface $account) {
  if ($op === 'view') {
    $bundleIsPermitted = in_array($node
      ->bundle(), $this
      ->permittedBundleIds($account));
    return AccessResult::forbiddenIf(!$bundleIsPermitted)
      ->cachePerPermissions();
  }
}