From 218ecd079327ff8057d0690a9aa96613524a99e7 Mon Sep 17 00:00:00 2001 From: Viktor Artemyev Date: Wed, 21 Aug 2024 11:17:49 +0300 Subject: [PATCH] The issue with modifying the item list during saving has been fixed. --- src/Fields/Translatable.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Fields/Translatable.php b/src/Fields/Translatable.php index 7fba24a..1e29163 100644 --- a/src/Fields/Translatable.php +++ b/src/Fields/Translatable.php @@ -152,6 +152,21 @@ public function hasFields(): bool return true; } + protected function resolveOnApply(): ?Closure + { + return function ($item) { + $translations = $this->requestValue() !== false + ? collect($this->requestValue())->mapWithKeys(function ($item) { + return [$item['key'] => $item['value']]; + })->toArray() + : $item->getTranslations($this->column()); + + $item->replaceTranslations($this->column(), $translations); + + return $item; + }; + } + protected function resolvePreview(): View|string { return $this?->data?->{$this->column()} ?? '';