entityTypeManager = $manager; $this->contentTranslationManager = $content_translation_manager; } /** * Checks access to translation deletion for the specified route match. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The parameterized route. * @param \Drupal\Core\Session\AccountInterface $account * The currently logged in account. * * @return \Drupal\Core\Access\AccessResultInterface * The access result. */ public function access(RouteMatchInterface $route_match, AccountInterface $account) { $requirement = $route_match->getRouteObject()->getRequirement('_access_content_translation_delete'); $entity_type_id = current(explode('.', $requirement)); $entity = $route_match->getParameter($entity_type_id); return $this->checkAccess($entity); } /** * Checks access to translation deletion for the specified entity. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity translation to be deleted. * * @return \Drupal\Core\Access\AccessResultInterface * The access result. */ 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; } }