From d2d93c590244489ff0e7c41f1a122e9c076db3d3 Mon Sep 17 00:00:00 2001 From: Markus Biberger Date: Thu, 16 Apr 2026 15:44:47 +0200 Subject: [PATCH] Add fallback_lang parameter to StoryRequest and StoriesRequest Adds an optional fallbackLanguage constructor parameter to both StoryRequest and StoriesRequest. When set, the Storyblok Content Delivery API parameter fallback_lang is included in the query, enabling field-level fallback for untranslated content. --- src/Request/StoriesRequest.php | 6 ++++++ src/Request/StoryRequest.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/Request/StoriesRequest.php b/src/Request/StoriesRequest.php index a9a7334..781ee4f 100644 --- a/src/Request/StoriesRequest.php +++ b/src/Request/StoriesRequest.php @@ -65,6 +65,7 @@ public function __construct( public SlugCollection $bySlugs = new SlugCollection(), public ?StoryLevel $level = null, public ?bool $isStartpage = null, + public ?string $fallbackLanguage = null, ) { Assert::stringNotEmpty($language); Assert::lessThanEq($this->pagination->perPage, self::MAX_PER_PAGE); @@ -95,6 +96,7 @@ public function __construct( * updated_at_lt?: string, * level?: int, * is_startpage?: bool, + * fallback_lang?: string, * } */ public function toArray(): array @@ -186,6 +188,10 @@ public function toArray(): array $array['is_startpage'] = $this->isStartpage ? 1 : 0; } + if (null !== $this->fallbackLanguage) { + $array['fallback_lang'] = $this->fallbackLanguage; + } + return $array; } } diff --git a/src/Request/StoryRequest.php b/src/Request/StoryRequest.php index b241b8f..3718d70 100644 --- a/src/Request/StoryRequest.php +++ b/src/Request/StoryRequest.php @@ -29,6 +29,7 @@ public function __construct( public ?Version $version = null, public RelationCollection $withRelations = new RelationCollection(), public ResolveLinks $resolveLinks = new ResolveLinks(), + public ?string $fallbackLanguage = null, ) { Assert::stringNotEmpty($language); } @@ -40,6 +41,7 @@ public function __construct( * resolve_relations?: string, * resolve_links?: string, * resolve_links_level?: int, + * fallback_lang?: string, * } */ public function toArray(): array @@ -61,6 +63,10 @@ public function toArray(): array $array['resolve_links_level'] = $this->resolveLinks->level->value; } + if (null !== $this->fallbackLanguage) { + $array['fallback_lang'] = $this->fallbackLanguage; + } + return $array; } }