function ContentTranslationHandler::getTranslationAccess
Same name in other branches
- 8.9.x 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()
- 11.x core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::getTranslationAccess()
Overrides ContentTranslationHandlerInterface::getTranslationAccess
File
-
core/
modules/ content_translation/ src/ ContentTranslationHandler.php, line 287
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.