public function EntityPrintController::checkAccess in Entity Print 8.2
Same name and namespace in other branches
- 8 src/Controller/EntityPrintController.php \Drupal\entity_print\Controller\EntityPrintController::checkAccess()
Validate that the current user has access.
We need to validate that the user is allowed to access this entity also the print version.
Parameters
string $export_type: The export type.
string $entity_type: The entity type.
int $entity_id: The entity id.
Return value
\Drupal\Core\Access\AccessResult The access result object.
1 string reference to 'EntityPrintController::checkAccess'
File
- src/
Controller/ EntityPrintController.php, line 132
Class
- EntityPrintController
- Print controller.
Namespace
Drupal\entity_print\ControllerCode
public function checkAccess($export_type, $entity_type, $entity_id) {
if (empty($entity_id)) {
return AccessResult::forbidden();
}
$account = $this
->currentUser();
// Invalid storage type.
if (!$this->entityTypeManager
->hasHandler($entity_type, 'storage')) {
return AccessResult::forbidden();
}
// Unable to find the entity requested.
if (!($entity = $this->entityTypeManager
->getStorage($entity_type)
->load($entity_id))) {
return AccessResult::forbidden();
}
// Ensure it's a valid export type.
if (!in_array($export_type, array_keys($this->exportTypeManager
->getDefinitions()))) {
return AccessResult::forbidden();
}
// Check if the user has the permission "bypass entity print access".
$access_result = AccessResult::allowedIfHasPermission($account, 'bypass entity print access');
if ($access_result
->isAllowed()) {
return $access_result
->andIf($entity
->access('view', $account, TRUE));
}
// Check if the user is allowed to view all bundles of the entity type.
$access_result = AccessResult::allowedIfHasPermission($account, 'entity print access type ' . $entity_type);
if ($access_result
->isAllowed()) {
return $access_result
->andIf($entity
->access('view', $account, TRUE));
}
// Check if the user is allowed to view that bundle type.
$access_result = AccessResult::allowedIfHasPermission($account, 'entity print access bundle ' . $entity
->bundle());
if ($access_result
->isAllowed()) {
return $access_result
->andIf($entity
->access('view', $account, TRUE));
}
return AccessResult::forbidden();
}