Skip to content

Commit

Permalink
Improve content and originals props
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Dec 3, 2024
1 parent cb74a5e commit bd343f4
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/Panel/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/
abstract class Model
{
protected Reform $form;

public function __construct(
protected ModelWithContent $model
) {
Expand All @@ -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
];
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit bd343f4

Please sign in to comment.