protected function LocalTaskAccessControlHandler::checkAccess in Translation Management Tool 8
Performs access checks.
This method is supposed to be overwritten by extending classes that do their own custom access checking.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.
string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.
\Drupal\Core\Session\AccountInterface $account: The user for which to check access.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
Overrides EntityAccessControlHandler::checkAccess
File
- translators/
tmgmt_local/ src/ Entity/ Controller/ LocalTaskAccessControlHandler.php, line 22
Class
- LocalTaskAccessControlHandler
- Access control handler for the task entity.
Namespace
Drupal\tmgmt_local\Entity\ControllerCode
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
if ($operation == 'delete') {
return AccessResult::forbidden();
}
if ($account
->hasPermission('administer tmgmt') || $account
->hasPermission('administer translation tasks')) {
// Administrators can do everything.
return AccessResult::allowed()
->cachePerPermissions();
}
switch ($operation) {
case 'view':
case 'update':
return AccessResult::allowedIfHasPermission($account, 'provide translation services');
// Custom operations.
case 'unassign':
return AccessResult::allowedIf($entity->tuid->target_id == $account
->id() && $account
->hasPermission('provide translation services'));
}
return AccessResult::neutral();
}