public function CertificateController::accessTab in Certificate 4.x
Parameters
EntityInterface $entity: The entity this belongs to
AccountInterface $account: The user account to check
Return value
\Drupal\Core\Access\AccessResultInterface An access result
1 call to CertificateController::accessTab()
- CertificateController::accessPdf in src/
Controller/ CertificateController.php - Downloads
File
- src/
Controller/ CertificateController.php, line 53
Class
Namespace
Drupal\certificate\ControllerCode
public function accessTab(EntityInterface $entity = NULL, AccountInterface $user = NULL) {
$access = AccessResult::forbidden('No certificate access by default');
if (!($entity = $this
->getEntityFromRoute())) {
return AccessResult::neutral()
->setCacheMaxAge(0);
}
$currentUser = \Drupal::currentUser();
$requestedUser = $user ?? $currentUser;
$admin = $currentUser
->hasPermission('administer certificate');
$view_all = $currentUser
->hasPermission('view all user certificates');
if (!$requestedUser
->id()) {
return AccessResult::forbidden('Not a valid user.')
->setCacheMaxAge(0);
}
if ($currentUser
->id() !== $requestedUser
->id() && !($admin || $view_all)) {
return AccessResult::forbidden('Not an admin user.')
->setCacheMaxAge(0);
}
// Check that the user can access the certificate on this entity.
return $entity
->access('certificate', $requestedUser, TRUE)
->setCacheMaxAge(0);
}