Skip to content

Commit

Permalink
Use the new render mode in models and activate it in the panel
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Jul 31, 2024
1 parent 5a5d495 commit 41df035
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/Cms/ModelWithContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,25 @@ abstract protected function commit(
*/
public function content(string|null $languageCode = null): Content
{
// get the targeted language
$language = Language::ensure($languageCode);

// fetch a specific version in preview render mode
// @todo this entire block can be radically simplified as soon
// as the models use the versions exclusively.
if (VersionId::$render ?? null) {
$version = $this->version(VersionId::render($this));

if ($version->exists($language) === true) {
return $version->content($language);
}
}

// single language support
if ($this->kirby()->multilang() === false) {
return $this->content ??= $this->version()->content('default');
return $this->content ??= $this->version()->content($language);
}

// get the targeted language
$language = Language::ensure($languageCode);

// only fetch from cache for the current language
if ($languageCode === null && $this->content instanceof Content) {
return $this->content;
Expand Down
15 changes: 14 additions & 1 deletion src/Panel/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Kirby\Cms\File as CmsFile;
use Kirby\Cms\ModelWithContent;
use Kirby\Content\VersionId;
use Kirby\Filesystem\Asset;
use Kirby\Panel\Ui\Buttons\ViewButtons;
use Kirby\Toolkit\I18n;
Expand Down Expand Up @@ -373,11 +374,23 @@ public function view(): array
{
$page = $this->model;

return [
// This is placed here as a proof of concept
// @todo we need to find a better place for it
// to switch into changes mode in the panel
VersionId::$render = VersionId::changes();

$view = [
'breadcrumb' => $page->panel()->breadcrumb(),
'component' => 'k-page-view',
'props' => $this->props(),
'title' => $page->title()->toString(),
];

// The render mode needs to be undone here to keep unit tests working
// That's the downside of such static properties. They are likely to
// cause side-effects
VersionId::$render = null;

return $view;
}
}

0 comments on commit 41df035

Please sign in to comment.