Index manyMany images (Fixes #172)

This commit is contained in:
Will Rossiter 2020-11-19 11:33:25 +13:00 committed by GitHub
parent 17b21683a2
commit 312b78f88b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -160,6 +160,32 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
} }
} }
foreach ($this->owner->manyMany() as $field => $type) {
$image = false;
if (is_array($type) && isset($type['through'])) {
if (singleton($type['through']) instanceof Image) {
$image = true;
}
} else {
if (singleton($type) instanceof Image) {
$image = true;
}
}
if ($image) {
$images = $this->owner->$field();
foreach ($images as $image) {
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
$cachedImages[$image->ID] = true;
$list->push($image);
}
}
}
}
$this->owner->extend('updateImagesForSitemap', $list); $this->owner->extend('updateImagesForSitemap', $list);
return $list; return $list;