Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions Classes/LinkHandler/PageLinkHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,39 @@ public function getBodyTagAttributes()
}

/**
* Short-hand function to select all registered languages
* Short-hand function to select all registered languages with page translation
*
* @return SiteLanguage[]
*/
protected function getAllLanguages($pageId = null)
protected function getAllLanguages(int $pageId)
{
try {
$site = $this->siteFinder->getSiteByPageId($pageId ?? $this->linkParts['url']['pageuid'] ?? 0);
return $site->getAvailableLanguages($this->getBackendUser(), true);
$site = $this->siteFinder->getSiteByPageId($pageId);
$languages = $site->getAvailableLanguages($this->getBackendUser(), true);
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll()->add(new DeletedRestriction());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do that but it's not WS-aware.

In v14 we do have methods in LocalizationRepository I think for this, but we can use this at a later version then.

$translations = $queryBuilder->select('sys_language_uid')
->from('pages')
->where(
$queryBuilder->expr()->eq(
'l10n_parent',
$queryBuilder->createNamedParameter($pageId, ParameterType::INTEGER)
)
)
->executeQuery()
->fetchFirstColumn();
$availableLanguages = [];
/** @var SiteLanguage $language */
foreach ($languages as $language) {
if ($language->getLanguageId() < 1) {
$availableLanguages[$language->getLanguageId()] = $language;
continue;
}
if (in_array($language->getLanguageId(), $translations, true)) {
$availableLanguages[$language->getLanguageId()] = $language;
}
}
return $availableLanguages;
} catch (SiteNotFoundException $e) {
return [];
}
Expand Down
Loading