Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix $file::changeTemplate() #6739

Draft
wants to merge 2 commits into
base: develop-minor
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Cms/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Cms/FileActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/Cms/Files/FileActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@
$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());

Check failure on line 372 in tests/Cms/Files/FileActionsTest.php

View workflow job for this annotation

GitHub Actions / Unit tests - PHP 8.1

Failed asserting that 'a' is null.

Check failure on line 372 in tests/Cms/Files/FileActionsTest.php

View workflow job for this annotation

GitHub Actions / Unit tests - PHP 8.2

Failed asserting that 'a' is null.

Check failure on line 372 in tests/Cms/Files/FileActionsTest.php

View workflow job for this annotation

GitHub Actions / Unit tests - PHP 8.3

Failed asserting that 'a' is null.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bastianallgeier maybe you have an idea with your content class/caching knowledge why this still has a when a non-default language should never have a template field for a file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this stage, I believe that we merge it with the default language content.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is that the default language has been updated to b, but the secondary language still seems to be stuck with a.

$this->assertNull($modified->caption()->value());
$this->assertSame('This is the text', $modified->text()->value());
$this->assertSame(2, $calls);
Expand Down
Loading