Skip to content

Commit

Permalink
Fix cross-site links when target site does not contain the current la…
Browse files Browse the repository at this point in the history
…nguage
  • Loading branch information
fwg committed Mar 31, 2023
1 parent 62231ce commit d73711f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
Expand Up @@ -470,12 +470,18 @@ protected function getSiteLanguageOfTargetPage(Site $siteOfTargetPage, string $t
} else {
$targetLanguageId = (int)$targetLanguageId;
}
try {
$siteLanguageOfTargetPage = $siteOfTargetPage->getLanguageById($targetLanguageId);
} catch (\InvalidArgumentException $e) {
throw new UnableToLinkException('The target page does not have a language with ID ' . $targetLanguageId . ' configured in its site configuration.', 1535477406);

$languageIds = array_merge([$targetLanguageId], $currentSiteLanguage->getFallbackLanguageIds());

foreach ($languageIds as $languageId) {
try {
return $siteOfTargetPage->getLanguageById($languageId);
} catch (\InvalidArgumentException $e) {
continue;
}
}
return $siteLanguageOfTargetPage;

throw new UnableToLinkException('The target page does not have a language with ID ' . $targetLanguageId . ' configured in its site configuration.', 1535477406);
}

/**
Expand Down

0 comments on commit d73711f

Please sign in to comment.