From 1e9b604de63f47cb5ab8a57262e083a4a77615c0 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 2 Oct 2026 09:33:42 +0100 Subject: [PATCH] exclude alternate locales without urls from the cascade --- src/Cascade.php | 4 +++- tests/Localized/CascadeTest.php | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Cascade.php b/src/Cascade.php index 007cc32e..99800cd8 100644 --- a/src/Cascade.php +++ b/src/Cascade.php @@ -465,7 +465,9 @@ private function isAvailableIn(string $locale): bool && (! $this->taxonomy->collection() || $this->taxonomy->collection()->sites()->contains($locale)); } - return $this->model->in($locale)?->status() === 'published'; + $localization = $this->model->in($locale); + + return $localization?->status() === 'published' && $localization->url(); } private function absoluteUrlIn(SiteInstance $site): string diff --git a/tests/Localized/CascadeTest.php b/tests/Localized/CascadeTest.php index ac22a1ad..b36a676c 100644 --- a/tests/Localized/CascadeTest.php +++ b/tests/Localized/CascadeTest.php @@ -3,6 +3,7 @@ namespace Tests\Localized; use PHPUnit\Framework\Attributes\Test; +use Statamic\Facades\Collection; use Statamic\Facades\Config; use Statamic\Facades\Entry; use Statamic\SeoPro\Cascade; @@ -45,6 +46,24 @@ public function it_reindexes_alternate_locales_after_filtering() $this->assertSame('it', $data['alternate_locales'][0]['hreflang']); } + /** + * @see https://github.com/statamic/seo-pro/issues/687 + */ + #[Test] + public function it_excludes_alternate_locales_without_urls() + { + $collection = tap(Collection::make('snippets')->sites(['default', 'french']))->save(); + $entry = tap(Entry::make()->collection($collection)->locale('default')->slug('banner'))->save(); + $entry->makeLocalization('french')->save(); + + $data = (new Cascade) + ->withSiteDefaults(SiteDefaults::in('default')->all()) + ->withCurrent($entry) + ->get(); + + $this->assertEmpty($data['alternate_locales']); + } + #[Test] public function it_generates_seo_cascade_for_canonical_url_and_handles_duplicate_alternate_hreflangs() {