You are here

protected function ContentTranslationManageAccessCheck::checkAccess in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php \Drupal\content_translation\Access\ContentTranslationManageAccessCheck::checkAccess()
  2. 10 core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php \Drupal\content_translation\Access\ContentTranslationManageAccessCheck::checkAccess()

Performs access checks for the specified operation.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity being checked.

\Drupal\Core\Language\LanguageInterface $language: For an update or delete operation, the language code of the translation being updated or deleted.

string $operation: The operation to be checked.

Return value

\Drupal\Core\Access\AccessResultInterface An access result object.

1 call to ContentTranslationManageAccessCheck::checkAccess()
ContentTranslationManageAccessCheck::access in core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php
Checks translation access for the entity and operation on the given route.

File

core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php, line 146

Class

ContentTranslationManageAccessCheck
Access check for entity translation CRUD operation.

Namespace

Drupal\content_translation\Access

Code

protected function checkAccess(ContentEntityInterface $entity, LanguageInterface $language, $operation) {

  /* @var \Drupal\content_translation\ContentTranslationHandlerInterface $handler */
  $handler = $this->entityTypeManager
    ->getHandler($entity
    ->getEntityTypeId(), 'translation');
  $translations = $entity
    ->getTranslationLanguages();
  $languages = $this->languageManager
    ->getLanguages();
  $has_translation = isset($languages[$language
    ->getId()]) && $language
    ->getId() != $entity
    ->getUntranslated()
    ->language()
    ->getId() && isset($translations[$language
    ->getId()]);
  return AccessResult::allowedIf($has_translation)
    ->cachePerPermissions()
    ->addCacheableDependency($entity)
    ->andIf($handler
    ->getTranslationAccess($entity, $operation));
}