class FillPdfAccessHelper in FillPDF 8.4
Same name and namespace in other branches
- 5.0.x src/FillPdfAccessHelper.php \Drupal\fillpdf\FillPdfAccessHelper
Class FillPdfAccessHelper.
@package Drupal\fillpdf
Hierarchy
- class \Drupal\fillpdf\FillPdfAccessHelper implements FillPdfAccessHelperInterface
Expanded class hierarchy of FillPdfAccessHelper
1 string reference to 'FillPdfAccessHelper'
1 service uses FillPdfAccessHelper
File
- src/
FillPdfAccessHelper.php, line 14
Namespace
Drupal\fillpdfView source
class FillPdfAccessHelper implements FillPdfAccessHelperInterface {
/**
* The FillPDF link manipulator.
*
* @var \Drupal\fillpdf\Service\FillPdfLinkManipulator
*/
protected $linkManipulator;
/**
* The FillPDF context manager.
*
* @var \Drupal\fillpdf\Service\FillPdfContextManager
*/
protected $contextManager;
/**
* Constructs a FillPdfAccessManager object.
*
* @param \Drupal\fillpdf\FillPdfLinkManipulatorInterface $link_manipulator
* The FillPDF link manipulator.
* @param \Drupal\fillpdf\FillPdfContextManagerInterface $context_manager
* The FillPDF context manager.
*/
public function __construct(FillPdfLinkManipulatorInterface $link_manipulator, FillPdfContextManagerInterface $context_manager) {
$this->linkManipulator = $link_manipulator;
$this->contextManager = $context_manager;
}
/**
* {@inheritdoc}
*/
public function canGeneratePdfFromUrlString($url, AccountInterface $account) {
$context = $this->linkManipulator
->parseUrlString($url);
return $this
->canGeneratePdfFromContext($context, $account);
}
/**
* {@inheritdoc}
*/
public function canGeneratePdfFromLink(Url $link, AccountInterface $account) {
$context = $this->linkManipulator
->parseLink($link);
return $this
->canGeneratePdfFromContext($context, $account);
}
/**
* {@inheritdoc}
*/
public function canGeneratePdfFromContext(array $context, AccountInterface $account) {
$is_admin = $account
->hasPermission('administer pdfs');
$can_publish_all = $account
->hasPermission('publish all pdfs');
$cachedAllowed = AccessResult::allowed()
->cachePerUser()
->cachePerPermissions();
if ($can_publish_all || $is_admin) {
return $cachedAllowed;
}
$is_sample = $context['sample'];
if ($is_sample && $is_admin) {
return $cachedAllowed;
}
$cachedForbidden = AccessResult::forbidden()
->cachePerUser()
->cachePerPermissions();
$can_publish = $account
->hasPermission('publish own pdfs');
if (!$is_sample && $can_publish) {
$entities = $this->contextManager
->loadEntities($context);
/** @var \Drupal\Core\Entity\EntityInterface[] $type_entities */
foreach ($entities as $type_entities) {
foreach ($type_entities as $entity) {
// If there are any entities in the context that the user can't view,
// deny access.
if (!$entity
->access('view', $account)) {
return $cachedForbidden;
}
}
}
return $cachedAllowed;
}
return $cachedForbidden;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FillPdfAccessHelper:: |
protected | property | The FillPDF context manager. | |
FillPdfAccessHelper:: |
protected | property | The FillPDF link manipulator. | |
FillPdfAccessHelper:: |
public | function |
This is the main access checking function of this class. Overrides FillPdfAccessHelperInterface:: |
|
FillPdfAccessHelper:: |
public | function |
Provides a way to check access from a link argument. Overrides FillPdfAccessHelperInterface:: |
|
FillPdfAccessHelper:: |
public | function |
Provides a way to pass in a FillPDF Link string to check access. Overrides FillPdfAccessHelperInterface:: |
|
FillPdfAccessHelper:: |
public | function | Constructs a FillPdfAccessManager object. |