You are here

public function NodeGrantAccessCheck::access in Nodeaccess 8.2

Same name and namespace in other branches
  1. 8 src/AccessChecks/NodeGrantAccessCheck.php \Drupal\nodeaccess\AccessChecks\NodeGrantAccessCheck::access()

A custom access check.

1 string reference to 'NodeGrantAccessCheck::access'
nodeaccess.routing.yml in ./nodeaccess.routing.yml
nodeaccess.routing.yml

File

src/AccessChecks/NodeGrantAccessCheck.php, line 18

Class

NodeGrantAccessCheck
A custom access check for grants form.

Namespace

Drupal\nodeaccess\AccessChecks

Code

public function access($node, AccountInterface $account) {
  if (!$node) {
    return AccessResult::forbidden();
  }
  $nid = $node;
  $node = Node::load($nid);
  $config = \Drupal::configFactory()
    ->get('nodeaccess.settings');
  $allowed_types = $config
    ->get('allowed_types');
  if ($node && isset($allowed_types[$node
    ->getType()]) && !empty($allowed_types[$node
    ->getType()]) && ($account
    ->hasPermission('grant node permissions') || $account
    ->hasPermission('administer nodeaccess'))) {
    return AccessResult::Allowed();
  }
  return AccessResult::forbidden();
}