Skip to content

Commit

Permalink
Merge pull request #553 from Yoast/bugfix/550-automatic-functionality…
Browse files Browse the repository at this point in the history
…-records

[BUGFIX] Added extra checks within the metatag generators in case fields do not exist, fixed hasSitemapFields method with correct property
  • Loading branch information
RinyVT authored Sep 12, 2023
2 parents 348138b + 04670a6 commit 4dc99b9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions Classes/MetaTag/AdvancedRobotsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Classes/MetaTag/Generator/OpenGraphGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions Classes/MetaTag/Generator/TwitterGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion Classes/Record/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4dc99b9

Please sign in to comment.