You are here

public function FillPdfAccessController::checkLink in FillPDF 8.4

Same name and namespace in other branches
  1. 5.0.x src/FillPdfAccessController.php \Drupal\fillpdf\FillPdfAccessController::checkLink()

Checks whether the current user has access to the current request.

Return value

\Drupal\Core\Access\AccessResultInterface Access result value object.

1 string reference to 'FillPdfAccessController::checkLink'
fillpdf.routing.yml in ./fillpdf.routing.yml
fillpdf.routing.yml

File

src/FillPdfAccessController.php, line 103

Class

FillPdfAccessController
Defines a custom access controller for the FillPDF generation route.

Namespace

Drupal\fillpdf

Code

public function checkLink() {
  try {
    $context = $this->linkManipulator
      ->parseRequest($this->requestStack
      ->getCurrentRequest());
  } catch (\InvalidArgumentException $exception) {
    $message = $exception
      ->getMessage();
    $is_admin = $this->currentUser
      ->hasPermission('administer pdfs');
    $this
      ->messenger()
      ->addError($is_admin ? $message : t('An error occurred. Please notify the administrator.'));
    $this
      ->getLogger('fillpdf')
      ->error($message);
    return AccessResult::forbidden();
  }
  $account = $this->currentUser;
  return $this->accessHelper
    ->canGeneratePdfFromContext($context, $account);
}