You are here

class NodeGrantAccessCheck in Nodeaccess 8

Same name and namespace in other branches
  1. 8.2 src/AccessChecks/NodeGrantAccessCheck.php \Drupal\nodeaccess\AccessChecks\NodeGrantAccessCheck

A custom access check for grants form.

Hierarchy

Expanded class hierarchy of NodeGrantAccessCheck

1 string reference to 'NodeGrantAccessCheck'
services.yml in ./services.yml
services.yml

File

src/AccessChecks/NodeGrantAccessCheck.php, line 13

Namespace

Drupal\nodeaccess\AccessChecks
View source
class NodeGrantAccessCheck implements AccessInterface {

  /**
   * A custom access check.
   */
  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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NodeGrantAccessCheck::access public function A custom access check.