From 04670a6c40decb1bd3936ee3b38602d5a36ef55e Mon Sep 17 00:00:00 2001 From: Riny van Tiggelen Date: Thu, 31 Aug 2023 12:02:12 +0200 Subject: [PATCH] [BUGFIX] Added extra checks within the metatag generators in case fields do not exist, fixed hasSitemapFields method with correct property --- CHANGELOG.md | 2 ++ Classes/MetaTag/AdvancedRobotsGenerator.php | 10 +++++----- Classes/MetaTag/Generator/OpenGraphGenerator.php | 2 +- Classes/MetaTag/Generator/TwitterGenerator.php | 4 ++-- Classes/Record/Record.php | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6ae66f9..4fc6387a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ 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 +- Added extra checks within the metatag generators in case fields do not exist (opengraph, twitter, robots) +- `hasSitemapFields` now correctly returns the `sitemapFields` instead of `yoastSeoFields` ## 9.0.1 July 6, 2023 ### Fixed diff --git a/Classes/MetaTag/AdvancedRobotsGenerator.php b/Classes/MetaTag/AdvancedRobotsGenerator.php index 8007f769..1be866aa 100644 --- a/Classes/MetaTag/AdvancedRobotsGenerator.php +++ b/Classes/MetaTag/AdvancedRobotsGenerator.php @@ -30,11 +30,11 @@ public function generate(array $params): void $record = $params['page']; } - $noImageIndex = (bool)$record['tx_yoastseo_robots_noimageindex']; - $noArchive = (bool)$record['tx_yoastseo_robots_noarchive']; - $noSnippet = (bool)$record['tx_yoastseo_robots_nosnippet']; - $noIndex = (bool)$record['no_index']; - $noFollow = (bool)$record['no_follow']; + $noImageIndex = (bool)($record['tx_yoastseo_robots_noimageindex'] ?? false); + $noArchive = (bool)($record['tx_yoastseo_robots_noarchive'] ?? false); + $noSnippet = (bool)($record['tx_yoastseo_robots_nosnippet'] ?? false); + $noIndex = (bool)($record['no_index'] ?? false); + $noFollow = (bool)($record['no_follow'] ?? false); if ($noImageIndex || $noArchive || $noSnippet || $noIndex || $noFollow) { $metaTagManagerRegistry = GeneralUtility::makeInstance(MetaTagManagerRegistry::class); diff --git a/Classes/MetaTag/Generator/OpenGraphGenerator.php b/Classes/MetaTag/Generator/OpenGraphGenerator.php index 3b079076..4d8220d9 100644 --- a/Classes/MetaTag/Generator/OpenGraphGenerator.php +++ b/Classes/MetaTag/Generator/OpenGraphGenerator.php @@ -26,7 +26,7 @@ public function generate(Record $record): void $manager->addProperty('og:description', $ogDescription); } - if ($record->getRecordData()['og_image']) { + if ($record->getRecordData()['og_image'] ?? false) { $fileCollector = GeneralUtility::makeInstance(FileCollector::class); $fileCollector->addFilesFromRelation($record->getTableName(), 'og_image', $record->getRecordData()); $manager = $this->managerRegistry->getManagerForProperty('og:image'); diff --git a/Classes/MetaTag/Generator/TwitterGenerator.php b/Classes/MetaTag/Generator/TwitterGenerator.php index 1e6276d6..641e9580 100644 --- a/Classes/MetaTag/Generator/TwitterGenerator.php +++ b/Classes/MetaTag/Generator/TwitterGenerator.php @@ -26,14 +26,14 @@ public function generate(Record $record): void $manager->addProperty('twitter:title', $twitterTitle); } - $twitterDescription = $record->getRecordData()['twitter_description']; + $twitterDescription = $record->getRecordData()['twitter_description'] ?? ''; if (!empty($twitterDescription)) { $manager = $this->managerRegistry->getManagerForProperty('twitter:description'); $manager->removeProperty('twitter:description'); $manager->addProperty('twitter:description', $twitterDescription); } - if ($record->getRecordData()['twitter_image']) { + if ($record->getRecordData()['twitter_image'] ?? false) { $fileCollector = GeneralUtility::makeInstance(FileCollector::class); $fileCollector->addFilesFromRelation($record->getTableName(), 'twitter_image', $record->getRecordData()); $manager = $this->managerRegistry->getManagerForProperty('twitter:image'); diff --git a/Classes/Record/Record.php b/Classes/Record/Record.php index a3585008..930dcbd8 100644 --- a/Classes/Record/Record.php +++ b/Classes/Record/Record.php @@ -59,7 +59,7 @@ public function setYoastSeoFields(bool $yoastSeoFields): self public function hasSitemapFields(): bool { - return $this->yoastSeoFields; + return $this->sitemapFields; } public function setSitemapFields(bool $sitemapFields): self