Skip to content

Commit

Permalink
Merge pull request #114 from pboivin/fix/relationship-repeaters
Browse files Browse the repository at this point in the history
[2.x] fix: Don't call state hooks by default when opening the preview modal
  • Loading branch information
pboivin authored Jan 13, 2024
2 parents b28fb31 + d1dbd3e commit bec7275
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Pages/Concerns/HasPreviewModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ trait HasPreviewModal

protected ?Model $previewableRecord = null;

protected bool $shouldCallHooksBeforePreview = false;

protected function getPreviewModalUrl(): ?string
{
return null;
Expand Down Expand Up @@ -57,10 +59,14 @@ protected function preparePreviewModalData(): array
if ($this->previewableRecord) {
$record = $this->previewableRecord;
} elseif (method_exists($this, 'mutateFormDataBeforeCreate')) {
$data = $this->mutateFormDataBeforeCreate($this->form->getState());
$data = $this->mutateFormDataBeforeCreate(
$this->form->getState($this->shouldCallHooksBeforePreview)
);
$record = $this->getModel()::make($data);
} elseif (method_exists($this, 'mutateFormDataBeforeSave')) {
$data = $this->mutateFormDataBeforeSave($this->form->getState());
$data = $this->mutateFormDataBeforeSave(
$this->form->getState($this->shouldCallHooksBeforePreview)
);
$record = $this->getRecord();
$record->fill($data);
} elseif (method_exists($this, 'getRecord')) {
Expand Down

0 comments on commit bec7275

Please sign in to comment.