public function ContentTranslationHandler::getTranslationAccess in Drupal 9
Same name and namespace in other branches
- 8 core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::getTranslationAccess()
- 10 core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::getTranslationAccess()
Checks if the user can perform the given operation on translations of the wrapped entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity whose translation has to be accessed.
$op: The operation to be performed on the translation. Possible values are:
- "create"
- "update"
- "delete"
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
Overrides ContentTranslationHandlerInterface::getTranslationAccess
File
- core/
modules/ content_translation/ src/ ContentTranslationHandler.php, line 286
Class
- ContentTranslationHandler
- Base class for content translation handlers.
Namespace
Drupal\content_translationCode
public function getTranslationAccess(EntityInterface $entity, $op) {
// @todo Move this logic into a translation access control handler checking also
// the translation language and the given account.
$entity_type = $entity
->getEntityType();
$translate_permission = TRUE;
// If no permission granularity is defined this entity type does not need an
// explicit translate permission.
if (!$this->currentUser
->hasPermission('translate any entity') && ($permission_granularity = $entity_type
->getPermissionGranularity())) {
$translate_permission = $this->currentUser
->hasPermission($permission_granularity == 'bundle' ? "translate {$entity->bundle()} {$entity->getEntityTypeId()}" : "translate {$entity->getEntityTypeId()}");
}
$access = AccessResult::allowedIf($translate_permission && $this->currentUser
->hasPermission("{$op} content translations"))
->cachePerPermissions();
if (!$access
->isAllowed()) {
return AccessResult::allowedIfHasPermission($this->currentUser, 'translate editable entities')
->andIf($entity
->access('update', $this->currentUser, TRUE));
}
return $access;
}