/** @var \Drupal\content_translation\ContentTranslationHandlerInterface $handler */
$handler =
$this->entityTypeManager->
getHandler($entity->
getEntityTypeId(), 'translation'
);
$translations =
$entity->
getTranslationLanguages();
$languages =
$this->languageManager->
getLanguages();
$source_language =
$this->languageManager->
getLanguage($source) ?:
$entity->
language();
$target_language =
$this->languageManager->
getLanguage($target) ?:
$this->languageManager->
getCurrentLanguage(LanguageInterface::TYPE_CONTENT
);
$is_new_translation =
($source_language->
getId() !=
$target_language->
getId() &&
isset($languages[$source_language->
getId()]) &&
isset($languages[$target_language->
getId()]) && !
isset($translations[$target_language->
getId()]));
return AccessResult::
allowedIf($is_new_translation)->
cachePerPermissions()->
addCacheableDependency($entity) ->
andIf($handler->
getTranslationAccess($entity,
$operation));
case 'delete':
// @todo Remove this in https://www.drupal.org/node/2945956.
/** @var \Drupal\Core\Access\AccessResultInterface $delete_access */
$delete_access = \Drupal::
service('content_translation.delete_access'
)->
checkAccess($entity);
$access =
$this->
checkAccess($entity,
$language,
$operation);
return $delete_access->
andIf($access);
case 'update':
return $this->
checkAccess($entity,
$language,
$operation);
} }