From acfc9d96e9872a0be13419628255d972adf82255 Mon Sep 17 00:00:00 2001 From: Lara van Diemen Date: Wed, 8 Apr 2026 12:04:48 +0200 Subject: [PATCH] fix: dont add terms when they are empty in taxonomyTermSlugs --- src/Block/BlockAttributes.php | 4 ++++ tests/Block/BlockAttributesTest.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/Block/BlockAttributes.php b/src/Block/BlockAttributes.php index bf3b4bf..0ee313e 100644 --- a/src/Block/BlockAttributes.php +++ b/src/Block/BlockAttributes.php @@ -257,6 +257,10 @@ public function taxonomyTermSlugs(): array { $taxonomyTermSlugs = []; foreach ($this->taxonomyTerms as $taxonomy => $terms) { + if (! is_array($terms) || [] === $terms) { + continue; + } + $taxonomyTermSlugs[$taxonomy] = array_column($terms, 'value'); } diff --git a/tests/Block/BlockAttributesTest.php b/tests/Block/BlockAttributesTest.php index 28826ce..2069117 100644 --- a/tests/Block/BlockAttributesTest.php +++ b/tests/Block/BlockAttributesTest.php @@ -194,6 +194,11 @@ expect($attributes->taxonomyTermSlugs())->toBe(['category' => ['news', 'events']]); }); +it('returns the taxonomy term slugs excluding empty terms', function () { + $attributes = BlockAttributes::from(['taxonomyTerms' => ['category' => [['value' => 'news'], ['value' => 'events']], 'type' => []]]); + expect($attributes->taxonomyTermSlugs())->toBe(['category' => ['news', 'events']]); +}); + it('returns an empty array if no taxonomy term slugs are set', function () { $attributes = BlockAttributes::from([]); expect($attributes->taxonomyTermSlugs())->toBe([]);