Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ContentTranslationHandler.php

function ContentTranslationHandler::getTranslationAccess

Overrides ContentTranslationHandlerInterface::getTranslationAccess

File

core/modules/content_translation/src/ContentTranslationHandler.php, line 251

Class

ContentTranslationHandler
Base class for content translation handlers.

Namespace

Drupal\content_translation

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal