Skip to content

Commit

Permalink
Start to simplify ::content slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Jun 25, 2024
1 parent cf01d12 commit 6127ef3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
14 changes: 2 additions & 12 deletions src/Cms/ModelWithContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,11 @@ public function content(string|null $languageCode = null): Content
{
// single language support
if ($this->kirby()->multilang() === false) {
if ($this->content instanceof Content) {
return $this->content;
}

// don't normalize field keys (already handled by the `Data` class)
return $this->content = new Content($this->readContent(), $this, false);
return $this->content ??= $this->version()->content('default');
}

// get the targeted language
$language = $this->kirby()->language($languageCode);

// stop if the language does not exist
if ($language === null) {
throw new InvalidArgumentException('Invalid language: ' . $languageCode);
}
$language = Language::ensure($languageCode);

// only fetch from cache for the current language
if ($languageCode === null && $this->content instanceof Content) {
Expand Down
3 changes: 2 additions & 1 deletion tests/Cms/Models/ModelWithContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Kirby\Content\Version;
use Kirby\Content\VersionId;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\NotFoundException;
use Kirby\Panel\Page as PanelPage;
use Kirby\Uuid\PageUuid;
use Kirby\Uuid\SiteUuid;
Expand Down Expand Up @@ -155,7 +156,7 @@ public function testContentForInvalidTranslation()
]
]);

$this->expectException(InvalidArgumentException::class);
$this->expectException(NotFoundException::class);
$this->expectExceptionMessage('Invalid language: fr');

$app->page('foo')->content('fr');
Expand Down

0 comments on commit 6127ef3

Please sign in to comment.