Skip to content

Commit

Permalink
[BUGFIX] Show warning on linking suggestions when content element is …
Browse files Browse the repository at this point in the history
…set to 'All Languages' instead of fatal exception
  • Loading branch information
RinyVT committed Jul 7, 2023
1 parent 9cb9480 commit 2e9ba03
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This changelog is according to [Keep a Changelog](http://keepachangelog.com).
All notable changes to this project will be documented in this file.
We will follow [Semantic Versioning](http://semver.org/).

## UNRELEASED
### Fixed
- Show warning on linking suggestions when content element is set to "All Languages" instead of fatal exception

## 9.0.1 July 6, 2023
### Fixed
- Content Security Policy issues in CMS12 by adding extra parameter within BackendYoastConfig and removing unnecessary inline code within FocusKeywordAnalysis.html
Expand Down
14 changes: 10 additions & 4 deletions Classes/Form/Element/InternalLinkingSuggestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public function __construct(NodeFactory $nodeFactory, array $data)

public function render(): array
{
$locale = $this->getLocale($this->currentPage);
if ($locale === null) {
$this->templateView->assign('languageError', true);
$resultArray['html'] = $this->templateView->render();
return $resultArray;
}

$publicResourcesPath = PathUtility::getPublicPathToResources();

$resultArray = $this->initializeResultArray();
Expand All @@ -67,7 +74,7 @@ public function render(): array
],
'linkingSuggestions' => [
'excludedPage' => $this->currentPage,
'locale' => $this->getLocale($this->currentPage)
'locale' => $locale
],
'urls' => [
'workerUrl' => $workerUrl,
Expand Down Expand Up @@ -95,10 +102,9 @@ protected function getLocale(int $pageId): ?string
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
try {
$site = $siteFinder->getSiteByPageId($pageId);
} catch (SiteNotFoundException $e) {
return $site->getLanguageById($this->languageId)->getTwoLetterIsoCode();
} catch (SiteNotFoundException|\InvalidArgumentException $e) {
return null;
}
$siteLanguage = $site->getLanguageById($this->languageId);
return $siteLanguage->getTwoLetterIsoCode();
}
}
6 changes: 6 additions & 0 deletions Resources/Private/Language/BackendModule.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@
<trans-unit id="tx_yoastseo_linking_suggestions.intro" resname="tx_yoastseo_linking_suggestions.intro">
<source>To improve your site structure, consider linking to other relevant pages or records on your website. In the list below you'll find suggestions, cornerstone content is highlighted with an asterisk (*).</source>
</trans-unit>
<trans-unit id="tx_yoastseo_linking_suggestions.languageError.title" resname="tx_yoastseo_linking_suggestions.languageError.title">
<source>Unable to determine linking suggestions.</source>
</trans-unit>
<trans-unit id="tx_yoastseo_linking_suggestions.languageError" resname="tx_yoastseo_linking_suggestions.languageError">
<source>This content element does not have a language to analyze.</source>
</trans-unit>

<trans-unit id="page" xml:space="preserve">
<source>Page</source>
Expand Down
30 changes: 28 additions & 2 deletions Resources/Private/Templates/TCA/InternalLinkingSuggestion.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
<div><p><f:translate key="LLL:EXT:yoast_seo/Resources/Private/Language/BackendModule.xlf:tx_yoastseo_linking_suggestions.intro" /></p></div>
<div data-yoast-linking-suggestions />
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">

<f:if condition="{languageError}">
<f:then>
<div class="alert alert-warning">
<h5 class="alert-heading alert-title">
<f:translate
key="LLL:EXT:yoast_seo/Resources/Private/Language/BackendModule.xlf:tx_yoastseo_linking_suggestions.languageError.title" />
</h5>
<div class="alert-body">
<f:translate
key="LLL:EXT:yoast_seo/Resources/Private/Language/BackendModule.xlf:tx_yoastseo_linking_suggestions.languageError" />
</div>
</div>
</f:then>
<f:else>
<div>
<p>
<f:translate
key="LLL:EXT:yoast_seo/Resources/Private/Language/BackendModule.xlf:tx_yoastseo_linking_suggestions.intro" />
</p>
</div>
<div data-yoast-linking-suggestions />
</f:else>
</f:if>

</html>

0 comments on commit 2e9ba03

Please sign in to comment.