|
21 | 21 | use SolutionForest\InspireCms\Filament\Actions\UpdateRouteAction; |
22 | 22 | use SolutionForest\InspireCms\Helpers\FilamentActionHelper; |
23 | 23 | use SolutionForest\InspireCms\Helpers\FilamentResourceHelper; |
| 24 | +use SolutionForest\InspireCms\Models\Contracts\Content; |
| 25 | +use SolutionForest\InspireCms\Models\Contracts\FieldGroup; |
24 | 26 |
|
25 | 27 | use function Filament\Support\is_app_url; |
26 | 28 |
|
@@ -158,8 +160,24 @@ protected function handleRecordUpdate(Model $record, array $data): Model |
158 | 160 |
|
159 | 161 | $record->fill(Arr::except($data, $translatableAttributes)); |
160 | 162 |
|
| 163 | + $currentFieldsForType = $record instanceof Content |
| 164 | + ? $record->documentType?->fieldGroups->whereInstanceOf(FieldGroup::class)->mapWithKeys(fn (FieldGroup $fg) => [$fg->name => $fg->fields->pluck('name')->all()])->all() |
| 165 | + : []; |
| 166 | + // Limit the propertyData to the current fields for the type |
| 167 | + $propertyData = Arr::only($data['propertyData'] ?? [], array_keys($currentFieldsForType)); |
| 168 | + foreach ($propertyData as $gpKey => $value) { |
| 169 | + if (!is_array($value)) { |
| 170 | + continue; |
| 171 | + } |
| 172 | + $targetFields = $currentFieldsForType[$gpKey] ?? null; |
| 173 | + if (is_null($targetFields) || !is_array($targetFields) || empty($targetFields)) { |
| 174 | + continue; |
| 175 | + } |
| 176 | + $propertyData[$gpKey] = Arr::only($value, $targetFields); |
| 177 | + } |
| 178 | + |
161 | 179 | // handle 'Property Data' translation here |
162 | | - $record->setTranslation('propertyData', '', $data['propertyData'] ?? []); |
| 180 | + $record->setTranslation('propertyData', '', $propertyData); |
163 | 181 |
|
164 | 182 | foreach (Arr::only($data, $translatableAttributes) as $key => $value) { |
165 | 183 | $record->setTranslation($key, $this->activeLocale, $value); |
|
0 commit comments