Skip to content

Commit d061f8b

Browse files
scott graysonscott grayson
authored andcommitted
fix: preserve type field during editing
- Remove type field from mutateFormDataBeforeFill to keep it in form data - Add mutateFormDataBeforeSave to ensure type is preserved during save - Prevents type from becoming null when editing files/folders - Type is now immutable after creation but preserved during edits
1 parent b8801ba commit d061f8b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/Resources/Pages/EditLibraryItem.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ protected function getHeaderActions(): array
1919

2020
protected function mutateFormDataBeforeFill(array $data): array
2121
{
22-
// Remove fields that shouldn't be editable
23-
unset($data['type']);
22+
// Remove fields that shouldn't be editable, but preserve type
2423
unset($data['parent_id']);
2524
unset($data['created_by']);
26-
25+
2726
return $data;
2827
}
2928

@@ -38,4 +37,12 @@ protected function getForms(): array
3837
),
3938
];
4039
}
40+
41+
protected function mutateFormDataBeforeSave(array $data): array
42+
{
43+
// Preserve the original type - don't let it be changed
44+
$data['type'] = $this->getRecord()->type;
45+
46+
return $data;
47+
}
4148
}

src/Resources/Pages/ListLibraryItems.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ protected function getHeaderActions(): array
8484
])
8585
->action(function (array $data): void {
8686
$filePath = $data['file'];
87-
87+
8888
// Extract filename from the path
8989
$fileName = basename($filePath);
90-
90+
9191
LibraryItem::create([
9292
'name' => $fileName,
9393
'type' => 'file',
9494
'parent_id' => $this->parentId,
9595
'created_by' => auth()->user()?->id,
9696
]);
97-
97+
9898
$this->redirect(static::getResource()::getUrl('index', $this->parentId ? ['parent' => $this->parentId] : []));
9999
});
100100

0 commit comments

Comments
 (0)