Skip to content

Commit c00fbd2

Browse files
authored
Merge pull request #7 from lara-zeus/fix-none-translatable-repeater
fix none translatable repeater when switch locale
2 parents f9b04fa + 272666b commit c00fbd2

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

src/Resources/Pages/CreateRecord/Concerns/Translatable.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,9 @@ protected function handleRecordCreation(array $data): Model
4242
$record->setTranslation($key, $this->activeLocale, $value);
4343
}
4444

45-
$originalData = $data;
46-
4745
foreach ($this->otherLocaleData as $locale => $localeData) {
48-
$this->data = [
49-
...$this->data,
50-
...$localeData,
51-
];
52-
5346
try {
54-
$this->form->fill($this->data);
47+
$this->form->fill($this->form->getRawState());
5548
$this->form->validate();
5649
} catch (ValidationException $exception) {
5750
continue;
@@ -64,8 +57,6 @@ protected function handleRecordCreation(array $data): Model
6457
}
6558
}
6659

67-
$data = $originalData;
68-
6960
if (
7061
static::getResource()::isScopedToTenant() &&
7162
($tenant = Filament::getTenant())
@@ -93,14 +84,10 @@ public function updatedActiveLocale(string $newActiveLocale): void
9384

9485
$translatableAttributes = static::getResource()::getTranslatableAttributes();
9586

96-
// Form::getState triggers the dehydrate hooks of the fields
97-
// the before hooks are skipped to allow relationships to be translated
98-
// without making it a hassle
9987
$state = $this->form->getState();
100-
$this->otherLocaleData[$this->oldActiveLocale] = Arr::only($state, $translatableAttributes);
88+
$this->otherLocaleData[$this->oldActiveLocale] = Arr::only($this->data, $translatableAttributes);
10189

10290
try {
103-
// Form::fill triggers the hydrate hooks of the fields
10491
$this->form->fill([
10592
...Arr::except($state, $translatableAttributes),
10693
...$this->otherLocaleData[$this->activeLocale] ?? [],

src/Resources/Pages/EditRecord/Concerns/Translatable.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ protected function handleRecordUpdate(Model $record, array $data): Model
2626
{
2727
$translatableAttributes = static::getResource()::getTranslatableAttributes();
2828

29-
$record->fill(Arr::except($data, $translatableAttributes));
29+
$record->fill(
30+
Arr::except($data, $translatableAttributes)
31+
);
3032

3133
foreach (Arr::only($data, $translatableAttributes) as $key => $value) {
3234
$record->setTranslation($key, $this->activeLocale, $value);
@@ -40,7 +42,7 @@ protected function handleRecordUpdate(Model $record, array $data): Model
4042
->all();
4143

4244
try {
43-
$this->form->fill($this->data);
45+
$this->form->fill($this->form->getState());
4446
$this->form->validate();
4547
} catch (ValidationException $exception) {
4648
if (! array_key_exists($locale, $existingLocales)) {
@@ -79,16 +81,12 @@ public function updatedActiveLocale(): void
7981

8082
$translatableAttributes = static::getResource()::getTranslatableAttributes();
8183

82-
// Form::getState triggers the dehydrate hooks of the fields
83-
// the before hooks are skipped to allow relationships to be translated
84-
// without making it a hassle
8584
$state = $this->form->getState();
8685
$this->otherLocaleData[$this->oldActiveLocale] = Arr::only($state, $translatableAttributes);
8786

8887
try {
89-
// Form::fill triggers the hydrate hooks of the fields
9088
$this->form->fill([
91-
...Arr::except($state, $translatableAttributes),
89+
...Arr::except($this->form->getRawState(), $translatableAttributes),
9290
...$this->otherLocaleData[$this->activeLocale] ?? [],
9391
]);
9492

0 commit comments

Comments
 (0)