Skip to content

Commit

Permalink
Fix announcements and surveys for alt languages
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Sep 11, 2024
1 parent ae51b8d commit 7d22bc0
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Drupal\external_entities\StorageClient\ExternalEntityStorageClientBase;
use Drupal\helfi_api_base\Environment\Environment;
use Drupal\helfi_api_base\Environment\Project;
use Drupal\helfi_api_base\Language\DefaultLanguageResolver;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
Expand Down Expand Up @@ -62,6 +63,11 @@ abstract class EtusivuJsonApiEntityBase extends ExternalEntityStorageClientBase
*/
protected CacheBackendInterface $cache;

/**
* Default language resolver.
*/
protected DefaultLanguageResolver $defaultLanguageResolver;

/**
* {@inheritdoc}
*/
Expand All @@ -75,6 +81,7 @@ public static function create(
$instance->client = $container->get('http_client');
$instance->languageManager = $container->get('language_manager');
$instance->cache = $container->get('cache.default');
$instance->defaultLanguageResolver = $container->get(DefaultLanguageResolver::class);

/** @var \Drupal\helfi_api_base\Environment\EnvironmentResolver $environmentResolver */
$environmentResolver = $container->get('helfi_api_base.environment_resolver');
Expand Down Expand Up @@ -153,6 +160,10 @@ protected function request(string $endpoint, array $parameters, string $langcode
return [];
}

if ($this->defaultLanguageResolver->isAltLanguage($langcode)) {
$langcode = $this->defaultLanguageResolver->getFallbackLanguage();
}

$uri = vsprintf('%s/jsonapi%s?%s', [
$this->environment->getInternalAddress($langcode),
$endpoint,
Expand Down

0 comments on commit 7d22bc0

Please sign in to comment.