Skip to content

Commit

Permalink
Merge pull request #172 from City-of-Helsinki/UHF-9708
Browse files Browse the repository at this point in the history
UHF-9708: Add type argument to getCurrentOrFallbackLanguage
  • Loading branch information
hyrsky authored Jun 25, 2024
2 parents bb8b9a1 + 9be6c51 commit 4165398
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Language/DefaultLanguageResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Drupal\helfi_api_base\Language;

use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

Expand Down Expand Up @@ -78,11 +79,14 @@ public function isAltLanguage(string $langcode = NULL): bool {
/**
* Get current or fallback langcode.
*
* @param string $type
* (optional) The language type.
*
* @return string
* Current or fallback language ID if current doesn't have full support.
*/
public function getCurrentOrFallbackLanguage(): string {
$langcode = $this->languageManager->getCurrentLanguage()->getId();
public function getCurrentOrFallbackLanguage(string $type = LanguageInterface::TYPE_INTERFACE): string {
$langcode = $this->languageManager->getCurrentLanguage($type)->getId();
if ($this->isAltLanguage($langcode)) {
return $this->getFallbackLanguage();
}
Expand Down

0 comments on commit 4165398

Please sign in to comment.