Skip to content

Commit

Permalink
fix: Call beforeStateDehydrated hook by default to handle image uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
pboivin committed Jan 29, 2024
1 parent d5fc848 commit 830299c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Pages/Concerns/HasPreviewModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ trait HasPreviewModal

protected bool $shouldCallHooksBeforePreview = false;

protected bool $shouldDehydrateBeforePreview = true;

protected function getPreviewModalUrl(): ?string
{
return null;
Expand Down Expand Up @@ -45,10 +47,28 @@ protected function renderPreviewModalView(?string $view, array $data): string
);
}

protected function getShouldCallHooksBeforePreview(): bool
{
return $this->shouldCallHooksBeforePreview;
}

protected function getShouldDehydrateBeforePreview(): bool
{
return $this->shouldDehydrateBeforePreview;
}

/** @internal */
protected function preparePreviewModalData(): array
{
$data = $this->form->getState($this->shouldCallHooksBeforePreview);
$shouldCallHooks = $this->getShouldCallHooksBeforePreview();
$shouldDehydrate = $this->getShouldDehydrateBeforePreview();

if (! $shouldCallHooks && $shouldDehydrate) {
$this->form->validate();
$this->form->callBeforeStateDehydrated();
}

$data = $this->form->getState($shouldCallHooks);
$record = null;

if (method_exists($this, 'mutateFormDataBeforeCreate')) {
Expand Down

0 comments on commit 830299c

Please sign in to comment.