You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the switching language doesn't (updatedActiveLocale) doesn't trigger lifecycle hooks (hydrate/dehydrate) of fields, which causes problems with several fields (like FileUploader)
Expected behavior
When you fill translatable FileUpload field and switch local and submit the form, you get an error.
Steps to reproduce
1- Go to a form containing a translatable file
2- Choose a file
3- switch locale
4- Save => you get an error because the file dehydration wasn't called:
Filament\Forms\Components\BaseFileUpload::Filament\Forms\Components{closure}(): Argument #1 ($file) must be of type string, array given
(There are several other errors, I m just trying to give an example.)
As a fix, I updated the logic of updatedActiveLocale:
$translatableAttributes = static::getResource()::getTranslatableAttributes();
$this->otherLocaleData[$this->oldActiveLocale] = \Illuminate\Support\Arr::only($this->form->getState(), $translatableAttributes);
try {
$this->form->fill([ // fill() will trigger the hydrate hooks of the fields
...Arr::except($this->form->getState(), $translatableAttributes), // getState trigger the dehydrate hooks of the fields
...$this->otherLocaleData[$this->activeLocale] ?? [],
]);
unset($this->otherLocaleData[$this->activeLocale]);
}catch(ValidationException$e) {
// switch back to the old locale since the swithc failed due to the current state of the form$this->activeLocale = $this->oldActiveLocale;
throw$e;
}
If you think I m on the right path it would be my pleasure to create my first PR.
The text was updated successfully, but these errors were encountered:
Package
filament/spatie-laravel-translatable-plugin
Package Version
3.2.44
Laravel Version
10.47.0
Livewire Version
3.4.7
PHP Version
8.1
Problem description
Currently, the switching language doesn't (updatedActiveLocale) doesn't trigger lifecycle hooks (hydrate/dehydrate) of fields, which causes problems with several fields (like FileUploader)
Expected behavior
When you fill translatable FileUpload field and switch local and submit the form, you get an error.
Steps to reproduce
1- Go to a form containing a translatable file
2- Choose a file
3- switch locale
4- Save => you get an error because the file dehydration wasn't called:
(There are several other errors, I m just trying to give an example.)
Reproduction repository
https://github.com/mybouhssina/demo-issue-filamentphp-translatable
Relevant log output
Suggested solution
As a fix, I updated the logic of updatedActiveLocale:
If you think I m on the right path it would be my pleasure to create my first PR.
The text was updated successfully, but these errors were encountered: