From 8909e048d67211d70f21da00c120d75c8cb07769 Mon Sep 17 00:00:00 2001
From: Georgi Mateev <gmateev@exactag.com>
Date: Fri, 29 Oct 2021 00:48:17 +0300
Subject: [PATCH] [BUGFIX] Fix head tags: title, description, canonical and
 hreflang

---
 Classes/Controller/NewsByAuthorController.php | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/Classes/Controller/NewsByAuthorController.php b/Classes/Controller/NewsByAuthorController.php
index 3f280ad..4ace64d 100644
--- a/Classes/Controller/NewsByAuthorController.php
+++ b/Classes/Controller/NewsByAuthorController.php
@@ -32,6 +32,7 @@ use SGalinski\SgNews\Domain\Model\News;
 use SGalinski\SgNews\Domain\Repository\AuthorRepository;
 use SGalinski\SgNews\Domain\Repository\CategoryRepository;
 use SGalinski\SgNews\Domain\Repository\NewsRepository;
+use SGalinski\SgSeo\Service\HeadTagService;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -67,12 +68,18 @@ class NewsByAuthorController extends AbstractController {
 				continue;
 			}
 
-			$GLOBALS['TSFE']->page['titlebyextension'] = $author->getName();
-			$GLOBALS['TSFE']->page['description'] = \strip_tags(\substr($author->getDescription(), 0, 200));
-
-			if (version_compare(
-				ExtensionManagementUtility::getExtensionVersion('sg_seo'),
-							'5.0.0', '<')) {
+			if (version_compare(ExtensionManagementUtility::getExtensionVersion('sg_seo'), '5.0.0', '>=')) {
+				$headTagService = GeneralUtility::makeInstance(
+					HeadTagService::class,
+					TRUE,
+					$author->getName(),
+					$author->getDescription(),
+					'&tx_sgnews_newsbyauthor[authorId]=' . $author->getUid()
+				);
+				$headTagService->execute();
+			} else {
+				$GLOBALS['TSFE']->page['titlebyextension'] = $author->getName();
+				$GLOBALS['TSFE']->page['description'] = \strip_tags(\substr($author->getDescription(), 0, 200));
 				$GLOBALS['TSFE']->page['extensionArgumentsForCanonicalAndHrefLang'] =
 					'&tx_sgnews_newsbyauthor[authorId]=' . $author->getUid();
 			}
-- 
GitLab