class FillPdfAccessController in FillPDF 5.0.x
Same name and namespace in other branches
- 8.4 src/FillPdfAccessController.php \Drupal\fillpdf\FillPdfAccessController
Defines a custom access controller for the FillPDF generation route.
Hierarchy
- class \Drupal\fillpdf\FillPdfAccessController implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait
Expanded class hierarchy of FillPdfAccessController
File
- src/
FillPdfAccessController.php, line 16
Namespace
Drupal\fillpdfView source
class FillPdfAccessController implements ContainerInjectionInterface {
use MessengerTrait;
use LoggerChannelTrait;
/**
* The FillPDF access helper.
*
* @var \Drupal\fillpdf\FillPdfAccessHelperInterface
*/
protected $accessHelper;
/**
* The FillPDF link manipulator.
*
* @var \Drupal\fillpdf\FillPdfLinkManipulatorInterface
*/
protected $linkManipulator;
/**
* The FillPDF context manager.
*
* @var \Drupal\fillpdf\FillPdfContextManagerInterface
*/
protected $contextManager;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructs a FillPdfAccessManager object.
*
* @param \Drupal\fillpdf\FillPdfAccessHelperInterface $access_helper
* The FillPDF access helper.
* @param \Drupal\fillpdf\FillPdfLinkManipulatorInterface $link_manipulator
* The FillPDF link manipulator.
* @param \Drupal\fillpdf\FillPdfContextManagerInterface $context_manager
* The FillPDF context manager.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct(FillPdfAccessHelperInterface $access_helper, FillPdfLinkManipulatorInterface $link_manipulator, FillPdfContextManagerInterface $context_manager, RequestStack $request_stack, AccountInterface $current_user) {
$this->accessHelper = $access_helper;
$this->linkManipulator = $link_manipulator;
$this->contextManager = $context_manager;
$this->requestStack = $request_stack;
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('fillpdf.access_helper'), $container
->get('fillpdf.link_manipulator'), $container
->get('fillpdf.context_manager'), $container
->get('request_stack'), $container
->get('current_user'));
}
/**
* Checks whether the current user has access to the current request.
*
* @return \Drupal\Core\Access\AccessResultInterface
* Access result value object.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FillPdfAccessController:: |
protected | property | The FillPDF access helper. | |
FillPdfAccessController:: |
protected | property | The FillPDF context manager. | |
FillPdfAccessController:: |
protected | property | The current user. | |
FillPdfAccessController:: |
protected | property | The FillPDF link manipulator. | |
FillPdfAccessController:: |
protected | property | The request stack. | |
FillPdfAccessController:: |
public | function | Checks whether the current user has access to the current request. | |
FillPdfAccessController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
FillPdfAccessController:: |
public | function | Constructs a FillPdfAccessManager object. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. |