You are here

public function ViewAccessCheck::access in Node Accessibility 8

A custom access check.

Parameters

\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The parametrized route

File

src/Access/ViewAccessCheck.php, line 70

Class

ViewAccessCheck
Determines access to for node add pages.

Namespace

Drupal\node_accessibility\Access

Code

public function access(AccountInterface $account, RouteMatchInterface $route_match) {
  if (!$account
    ->hasPermission('perform node accessibility validation')) {
    return AccessResult::forbidden();
  }
  $bag = $route_match
    ->getParameters();
  $nid = (int) $bag
    ->get('node');
  $vid = $bag
    ->get('node_revision');
  unset($bag);
  if ($nid == 0) {
    return AccessResult::forbidden();
  }
  $settings = TypeSettingsStorage::loadByNodeAsArray($nid);
  if (is_numeric($vid)) {
    if (!$this
      ->nodeRevisionIsValid($nid, (int) $vid)) {
      return AccessResult::forbidden();
    }
  }
  if (empty($settings['node_type'])) {
    return AccessResult::forbidden();
  }
  if (empty($settings['enabled']) || $settings['enabled'] == 'disabled') {
    return AccessResult::forbidden();
  }
  return AccessResult::allowed();
}