You are here

public function NodeCloneFormController::access in Node clone 8

Parameters

\Drupal\Core\Session\AccountInterface $account:

\Drupal\node\NodeInterface:

Return value

bool

File

src/Controller/NodeCloneFormController.php, line 107

Class

NodeCloneFormController
Wrapping controller for entity forms that serve as the main page body.

Namespace

Drupal\node_clone\Controller

Code

public function access(AccountInterface $account, NodeInterface $node) {
  if ($account
    ->hasPermission('clone node') || $node->uid->value === $account
    ->id() && $account
    ->hasPermission('clone own nodes')) {
    $access = new AccessResultAllowed();
  }
  else {
    $access = new AccessResultForbidden();
  }
  $access
    ->addCacheableDependency($node);
  $access
    ->cachePerPermissions();
  if ($access
    ->isAllowed()) {
    $access = $access
      ->andIf($node
      ->access('view', $account, TRUE));
  }
  if ($access
    ->isAllowed()) {
    $node_type = NodeType::load($node
      ->getType());
    $access = $access
      ->andIf($this->nodeAddAccessCheck
      ->access($account, $node_type));
  }
  return $access;
}