From 11fbc6e38a83879a52365820c17db9f91abfe5e8 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Mon, 14 Oct 2024 16:59:10 +0700 Subject: [PATCH 1/2] Fix `$file::changeTemplate()` --- src/Cms/File.php | 2 +- src/Cms/FileActions.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Cms/File.php b/src/Cms/File.php index b91f6ee1c1..d508d03d38 100644 --- a/src/Cms/File.php +++ b/src/Cms/File.php @@ -584,7 +584,7 @@ public function site(): Site */ public function template(): string|null { - return $this->template ??= $this->content()->get('template')->value(); + return $this->template ??= $this->content('default')->get('template')->value(); } /** diff --git a/src/Cms/FileActions.php b/src/Cms/FileActions.php index 712291a6df..536f3c038a 100644 --- a/src/Cms/FileActions.php +++ b/src/Cms/FileActions.php @@ -137,7 +137,10 @@ public function changeTemplate(string|null $template): static $template = null; } - $file = $file->update(['template' => $template]); + $file = $file->update( + ['template' => $template], + 'default' + ); // resize the file if configured by new blueprint $create = $file->blueprint()->create(); From 162358a87a91828fc1c288ec0d41f7cf98a51254 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Tue, 15 Oct 2024 21:46:14 +0700 Subject: [PATCH 2/2] Add unit test --- tests/Cms/Files/FileActionsTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Cms/Files/FileActionsTest.php b/tests/Cms/Files/FileActionsTest.php index 7d6a5ddaf6..e8affa6494 100644 --- a/tests/Cms/Files/FileActionsTest.php +++ b/tests/Cms/Files/FileActionsTest.php @@ -367,6 +367,9 @@ public function testChangeTemplateMultilang() $modified = $file->changeTemplate('b'); $this->assertSame('b', $modified->template()); + $this->assertSame('b', $modified->content('default')->get('template')->value()); + $this->assertSame('b', $modified->content('en')->get('template')->value()); + $this->assertNull($modified->content('de')->get('template')->value()); $this->assertNull($modified->caption()->value()); $this->assertSame('This is the text', $modified->text()->value()); $this->assertSame(2, $calls);