public function CertificateController::viewAccess in Opigno certificate 8
Same name and namespace in other branches
- 3.x src/Controller/CertificateController.php \Drupal\opigno_certificate\Controller\CertificateController::viewAccess()
Checks access for the controller.
Parameters
string $entity_type: The entity type.
string $entity_id: The entity ID.
Return value
\Drupal\Core\Access\AccessResult The access result object.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 string reference to 'CertificateController::viewAccess'
File
- src/
Controller/ CertificateController.php, line 105
Class
- CertificateController
- Defines a controller to render a single opigno_certificate.
Namespace
Drupal\opigno_certificate\ControllerCode
public function viewAccess($entity_type, $entity_id) {
$entity = $this->entityManager
->getStorage($entity_type)
->load($entity_id);
if ($entity && ($opigno_certificate = $entity->field_certificate->entity)) {
$opigno_certificate
->set('referencing_entity', $entity);
$access_result = AccessResult::allowedIfHasPermission($this->currentUser, 'administer certificates');
if ($access_result
->isAllowed()) {
return $access_result;
}
// Check access against the entity referencing the opigno_certificate
// instead of the opigno_certificate itself,
// so that each entity can have its own access check,
// but use 'view opigno_certificate'
// so that the access is specific to viewing opigno_certificates.
return $entity
->access('view certificate', $this->currentUser, TRUE);
}
return AccessResult::forbidden();
}