Chris@14: entityTypeManager = $manager; Chris@14: $this->contentTranslationManager = $content_translation_manager; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Checks access to translation deletion for the specified route match. Chris@14: * Chris@14: * @param \Drupal\Core\Routing\RouteMatchInterface $route_match Chris@14: * The parameterized route. Chris@14: * @param \Drupal\Core\Session\AccountInterface $account Chris@14: * The currently logged in account. Chris@14: * Chris@14: * @return \Drupal\Core\Access\AccessResultInterface Chris@14: * The access result. Chris@14: */ Chris@14: public function access(RouteMatchInterface $route_match, AccountInterface $account) { Chris@14: $requirement = $route_match->getRouteObject()->getRequirement('_access_content_translation_delete'); Chris@14: $entity_type_id = current(explode('.', $requirement)); Chris@14: $entity = $route_match->getParameter($entity_type_id); Chris@14: return $this->checkAccess($entity); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Checks access to translation deletion for the specified entity. Chris@14: * Chris@14: * @param \Drupal\Core\Entity\ContentEntityInterface $entity Chris@14: * The entity translation to be deleted. Chris@14: * Chris@14: * @return \Drupal\Core\Access\AccessResultInterface Chris@14: * The access result. Chris@14: */ Chris@14: public function checkAccess(ContentEntityInterface $entity) { Chris@14: $result = AccessResult::allowed(); Chris@14: Chris@14: $entity_type_id = $entity->getEntityTypeId(); Chris@14: $result->addCacheableDependency($entity); Chris@14: // Add the cache dependencies used by Chris@14: // ContentTranslationManager::isPendingRevisionSupportEnabled(). Chris@14: if (\Drupal::moduleHandler()->moduleExists('content_moderation')) { Chris@14: foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) { Chris@14: $result->addCacheableDependency($workflow); Chris@14: } Chris@14: } Chris@14: if (!ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id, $entity->bundle())) { Chris@14: return $result; Chris@14: } Chris@14: Chris@14: if ($entity->isDefaultTranslation()) { Chris@14: return $result; Chris@14: } Chris@14: Chris@14: $config = ContentLanguageSettings::load($entity_type_id . '.' . $entity->bundle()); Chris@14: $result->addCacheableDependency($config); Chris@14: if (!$this->contentTranslationManager->isEnabled($entity_type_id, $entity->bundle())) { Chris@14: return $result; Chris@14: } Chris@14: Chris@14: /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */ Chris@14: $storage = $this->entityTypeManager->getStorage($entity_type_id); Chris@14: $revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id(), $entity->language()->getId()); Chris@14: if (!$revision_id) { Chris@14: return $result; Chris@14: } Chris@14: Chris@14: /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */ Chris@14: $revision = $storage->loadRevision($revision_id); Chris@14: if ($revision->wasDefaultRevision()) { Chris@14: return $result; Chris@14: } Chris@14: Chris@14: $result = $result->andIf(AccessResult::forbidden()); Chris@14: return $result; Chris@14: } Chris@14: Chris@14: }