Skip to content

Commit 08e1692

Browse files
committed
add rename action for TemaplteRelationManager
1 parent 7921952 commit 08e1692

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

resources/lang/en/buttons.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@
172172
],
173173
],
174174

175+
'rename' => [
176+
'label' => 'Rename',
177+
'messages' => [
178+
'success' => [
179+
'title' => 'Renamed successfully',
180+
],
181+
'failure' => [
182+
'title' => 'Failed to rename',
183+
],
184+
],
185+
],
186+
175187
'reorder_children' => [
176188
'label' => 'Reorder children',
177189
'messages' => [

resources/lang/zh_TW/buttons.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@
172172
],
173173
],
174174

175+
'rename' => [
176+
'label' => '重命名',
177+
'messages' => [
178+
'success' => [
179+
'title' => '重命名成功',
180+
],
181+
'failure' => [
182+
'title' => '重命名失敗',
183+
],
184+
],
185+
],
186+
175187
'reorder_children' => [
176188
'label' => '重新排序子項',
177189
'messages' => [

src/Filament/Resources/DocumentTypeResource/RelationManagers/TemplatesRelationManager.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static function getBuilderEditorSchema(string $builderName): \Filament\Fo
7676
Forms\Components\Tabs\Tab::make(__('inspirecms::resources/template.editor.tabs.content'))
7777
->schema([
7878
TemplateResourceHelper::getPageComponentInstructionsFormComponent(),
79-
TemplateResourceHelper::getContentFormComponent('html_content'),
79+
TemplateResourceHelper::getContentFormComponent('html_content')->hiddenLabel(),
8080
]),
8181
Forms\Components\Tabs\Tab::make(__('inspirecms::resources/template.editor.tabs.instructions'))
8282
->schema([
@@ -127,6 +127,12 @@ public function table(Table $table): Table
127127

128128
$this->dispatch('$refresh');
129129
}),
130+
Tables\Actions\EditAction::make('rename')
131+
->label(__('inspirecms::buttons.rename.label'))
132+
->icon(FilamentIcon::resolve('inspirecms::edit.simple'))
133+
->successNotificationTitle(__('inspirecms::buttons.rename.messages.success.title'))
134+
->failureNotificationTitle(__('inspirecms::buttons.rename.messages.failure.title'))
135+
->link(),
130136
Tables\Actions\ActionGroup::make([
131137
EditAndPreviewAction::make()->builderName('templateViewBuilder')->authorize(static fn (RelationManager $livewire, Model $record): bool => (! $livewire->isReadOnly()) && $livewire->canEdit($record)),
132138
Tables\Actions\EditAction::make(),
@@ -210,7 +216,18 @@ protected function configureEditAction(Tables\Actions\EditAction $action): void
210216
{
211217
parent::configureEditAction($action);
212218

213-
$this->configureViewOrEditAction($action);
219+
if ($action->getName() == 'rename') {
220+
$action
221+
->form(fn (Form $form): Form => $this->createForm($form->columns(1)))
222+
->using(function (array $data, Model | Template $record) {
223+
$record->update(['slug' => $data['slug']]);
224+
});
225+
} else {
226+
227+
$this->configureViewOrEditAction($action);
228+
229+
}
230+
214231
}
215232

216233
protected function configureViewOrEditAction(Tables\Actions\Action $action)

0 commit comments

Comments
 (0)