mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
fix: Double file upload state update hooks
This commit is contained in:
@@ -13,6 +13,7 @@ use Filament\Support\Contracts\TranslatableContentDriver;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\Renderless;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
use Livewire\WithFileUploads;
|
||||
@@ -28,6 +29,9 @@ trait InteractsWithForms
|
||||
*/
|
||||
public array $componentFileAttachments = [];
|
||||
|
||||
#[Locked]
|
||||
public bool $areFormStateUpdateHooksDisabledForTesting = false;
|
||||
|
||||
/**
|
||||
* @var array<string, Form>
|
||||
*/
|
||||
@@ -306,11 +310,33 @@ trait InteractsWithForms
|
||||
|
||||
public function updatedInteractsWithForms(string $statePath): void
|
||||
{
|
||||
if (app()->runningUnitTests() && $this->areFormStateUpdateHooksDisabledForTesting) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->getCachedForms() as $form) {
|
||||
$form->callAfterStateUpdated($statePath);
|
||||
}
|
||||
}
|
||||
|
||||
public function disableFormStateUpdateHooksForTesting(): void
|
||||
{
|
||||
if (! app()->runningUnitTests()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->areFormStateUpdateHooksDisabledForTesting = true;
|
||||
}
|
||||
|
||||
public function enableFormStateUpdateHooksForTesting(): void
|
||||
{
|
||||
if (! app()->runningUnitTests()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->areFormStateUpdateHooksDisabledForTesting = false;
|
||||
}
|
||||
|
||||
protected function cacheForm(string $name, Form | Closure | null $form): ?Form
|
||||
{
|
||||
$this->isCachingForms = true;
|
||||
|
||||
@@ -45,6 +45,8 @@ class TestsForms
|
||||
$state = Arr::undot([$formStatePath => $state]);
|
||||
}
|
||||
|
||||
$this->call('disableFormStateUpdateHooksForTesting');
|
||||
|
||||
foreach (Arr::dot($state) as $key => $value) {
|
||||
if ($value instanceof UploadedFile ||
|
||||
(is_array($value) && isset($value[0]) && $value[0] instanceof UploadedFile)
|
||||
@@ -54,6 +56,8 @@ class TestsForms
|
||||
}
|
||||
}
|
||||
|
||||
$this->call('enableFormStateUpdateHooksForTesting');
|
||||
|
||||
$this->call('fillFormDataForTesting', $state);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user