You are here

public function ContentTranslationDeleteAccess::checkAccess in Drupal 10

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

Checks access to translation deletion for the specified entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity translation to be deleted.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

1 call to ContentTranslationDeleteAccess::checkAccess()
ContentTranslationDeleteAccess::access in core/modules/content_translation/src/Access/ContentTranslationDeleteAccess.php
Checks access to translation deletion for the specified route match.

File

core/modules/content_translation/src/Access/ContentTranslationDeleteAccess.php, line 81

Class

ContentTranslationDeleteAccess
Access check for entity translation deletion.

Namespace

Drupal\content_translation\Access

Code

public function checkAccess(ContentEntityInterface $entity) {
  $result = AccessResult::allowed();
  $entity_type_id = $entity
    ->getEntityTypeId();
  $result
    ->addCacheableDependency($entity);

  // Add the cache dependencies used by
  // ContentTranslationManager::isPendingRevisionSupportEnabled().
  if (\Drupal::moduleHandler()
    ->moduleExists('content_moderation')) {
    foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) {
      $result
        ->addCacheableDependency($workflow);
    }
  }
  if (!ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id, $entity
    ->bundle())) {
    return $result;
  }
  if ($entity
    ->isDefaultTranslation()) {
    return $result;
  }
  $config = ContentLanguageSettings::load($entity_type_id . '.' . $entity
    ->bundle());
  $result
    ->addCacheableDependency($config);
  if (!$this->contentTranslationManager
    ->isEnabled($entity_type_id, $entity
    ->bundle())) {
    return $result;
  }

  /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
  $storage = $this->entityTypeManager
    ->getStorage($entity_type_id);
  $revision_id = $storage
    ->getLatestTranslationAffectedRevisionId($entity
    ->id(), $entity
    ->language()
    ->getId());
  if (!$revision_id) {
    return $result;
  }

  /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
  $revision = $storage
    ->loadRevision($revision_id);
  if ($revision
    ->wasDefaultRevision()) {
    return $result;
  }
  $result = $result
    ->andIf(AccessResult::forbidden());
  return $result;
}