From bd343f45ca0f0069c425e7a0340b6953bd6ec7af Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 3 Dec 2024 18:38:19 +0100 Subject: [PATCH] Improve content and originals props --- src/Panel/Model.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Panel/Model.php b/src/Panel/Model.php index 8ed6732793..c22b489582 100644 --- a/src/Panel/Model.php +++ b/src/Panel/Model.php @@ -22,8 +22,6 @@ */ abstract class Model { - protected Reform $form; - public function __construct( protected ModelWithContent $model ) { @@ -43,10 +41,13 @@ public function content(): array $changes = []; if ($version->exists('current') === true) { - $changes = $version->content('current')->toArray(); + $changes = $version->read('current'); } - return $this->form()->fill($changes)->toFormValues(); + return [ + ...$this->originals(), + ...$changes + ]; } /** @@ -106,16 +107,10 @@ public function dropdownOption(): array public function form(): Reform { - if (isset($this->form) === true) { - return $this->form; - } - - $this->form = new Reform( + return new Reform( model: $this->model, - language: 'current' + language: 'current', ); - - return $this->form->fill($this->model); } /** @@ -345,7 +340,7 @@ public function options(array $unlock = []): array */ public function originals(): array { - return $this->form()->toFormValues(); + return $this->model->version('latest')->read('current'); } /** @@ -385,15 +380,22 @@ public function props(): array $request = $this->model->kirby()->request(); $tabs = $blueprint->tabs(); $tab = $blueprint->tab($request->get('tab')) ?? $tabs[0] ?? null; + $form = $this->form(); + + $originals = $this->originals(); + $content = [ + ...$originals, + ...$this->content() + ]; $props = [ 'api' => $link, 'buttons' => fn () => $this->buttons(), - 'content' => (object)$this->content(), + 'content' => (object)$form->fill($content)->toFormValues(), 'id' => $this->model->id(), 'link' => $link, 'lock' => $this->model->lock()->toArray(), - 'originals' => (object)$this->originals(), + 'originals' => (object)$form->fill($originals)->toFormValues(), 'permissions' => $this->model->permissions()->toArray(), 'tabs' => $tabs, 'uuid' => fn () => $this->model->uuid()?->toString()