Skip to content

Commit

Permalink
Merge pull request #52 from flord22/custom_modal_labels
Browse files Browse the repository at this point in the history
Add ability for custom modal titles and button labels
  • Loading branch information
saade authored Sep 18, 2022
2 parents f810e53 + 115f47b commit 2ee7ff2
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 21 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,27 @@ protected static function getCreateEventFormSchema(): array
}
```

You can override the `getCreateEventModalTitle()` method to change the modal title to a custom one:
```php
public function getCreateEventModalTitle(): string
{
return __('filament::resources/pages/create-record.title', ['label' => $this->getModalLabel()]);
}
```

You can override the `getCreateEventModalSubmitButtonLabel()` and `getCreateEventModalCloseButtonLabel()` methods to change the modal button labels to custom labels:
```php
public function getCreateEventModalSubmitButtonLabel(): string
{
return __('filament::resources/pages/create-record.form.actions.create.label');
}

public function getCreateEventModalCloseButtonLabel(): string
{
return __('filament::resources/pages/create-record.form.actions.cancel.label');
}
```

<br>

## Editing Events
Expand Down Expand Up @@ -346,6 +367,29 @@ protected static function getEditEventFormSchema(): array
}
```

You can override the `getEditEventModalTitle()` method to change the modal title to a custom one:
```php
public function getCreateEventModalTitle(): string
{
return __('filament::resources/pages/create-record.title', ['label' => $this->getModalLabel()]);
}
```

You can override the `getEditEventModalSubmitButtonLabel()` and `getEditEventModalCloseButtonLabel()` methods to change the modal button labels to custom labels:
```php
public function getEditEventModalSubmitButtonLabel(): string
{
return __('filament::resources/pages/edit-record.form.actions.save.label');
}

public function getEditEventModalCloseButtonLabel(): string
{
return $this->editEventForm->isDisabled()
? __('filament-support::actions/view.single.modal.actions.close.label')
: __('filament::resources/pages/edit-record.form.actions.cancel.label');
}
```

<br>

## Authorizing actions
Expand Down
8 changes: 4 additions & 4 deletions resources/views/components/create-event-modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<x-filament::modal id="fullcalendar--create-event-modal" :width="$this->getModalWidth()">
<x-slot name="header">
<x-filament::modal.heading>
{{ __('filament::resources/pages/create-record.title', ['label' => $this->getModalLabel()]) }}
{{ $this->getCreateEventModalTitle() }}
</x-filament::modal.heading>
</x-slot>

Expand All @@ -14,16 +14,16 @@

<x-slot name="footer">
<x-filament::button type="submit" form="onCreateEventSubmit">
{{ __('filament::resources/pages/create-record.form.actions.create.label') }}
{{ $this->getCreateEventModalSubmitButtonLabel() }}
</x-filament::button>

@if($this->isListeningCancelledCreateModal())
<x-filament::button color="secondary" x-on:click="isOpen = false; Livewire.emit('cancelledFullcalendarCreateEventModal')">
{{ __('filament::resources/pages/create-record.form.actions.cancel.label') }}
{{ $this->getCreateEventModalCloseButtonLabel() }}
</x-filament::button>
@else
<x-filament::button color="secondary" x-on:click="isOpen = false">
{{ __('filament::resources/pages/create-record.form.actions.cancel.label') }}
{{ $this->getCreateEventModalCloseButtonLabel() }}
</x-filament::button>
@endif
</x-slot>
Expand Down
22 changes: 5 additions & 17 deletions resources/views/components/edit-event-modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
<x-filament::modal id="fullcalendar--edit-event-modal" :width="$this->getModalWidth()">
<x-slot name="header">
<x-filament::modal.heading>
{{
$this->editEventForm->isDisabled()
? __('filament::resources/pages/view-record.title', ['label' => $this->getModalLabel()])
: __('filament::resources/pages/edit-record.title', ['label' => $this->getModalLabel()])
}}
{{ $this->getEditEventModalTitle() }}
</x-filament::modal.heading>
</x-slot>

Expand All @@ -19,28 +15,20 @@
<x-slot name="footer">
@if(!$this->editEventForm->isDisabled())
<x-filament::button type="submit" form="onEditEventSubmit">
{{ __('filament::resources/pages/edit-record.form.actions.save.label') }}
{{ $this->getEditEventModalSubmitButtonLabel() }}
</x-filament::button>
@endif

@if($this->isListeningCancelledEditModal())
<x-filament::button color="secondary"
x-on:click="isOpen = false; Livewire.emit('cancelledFullcalendarEditEventModal')">
{{
$this->editEventForm->isDisabled()
? __('filament-support::actions/view.single.modal.actions.close.label')
: __('filament::resources/pages/edit-record.form.actions.cancel.label')
}}
{{ $this->getEditEventModalCloseButtonLabel() }}
</x-filament::button>
@else
<x-filament::button color="secondary" x-on:click="isOpen = false">
{{
$this->editEventForm->isDisabled()
? __('filament-support::actions/view.single.modal.actions.close.label')
: __('filament::resources/pages/edit-record.form.actions.cancel.label')
}}
{{ $this->getEditEventModalCloseButtonLabel() }}
</x-filament::button>
@endif
@endif
</x-slot>
</x-filament::modal>
</x-filament::form>
15 changes: 15 additions & 0 deletions src/Widgets/Forms/CreateEventForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,19 @@ protected function getCreateEventForm(): array
->statePath('createEventFormState'),
];
}

public function getCreateEventModalTitle(): string
{
return __('filament::resources/pages/create-record.title', ['label' => $this->getModalLabel()]);
}

public function getCreateEventModalSubmitButtonLabel(): string
{
return __('filament::resources/pages/create-record.form.actions.create.label');
}

public function getCreateEventModalCloseButtonLabel(): string
{
return __('filament::resources/pages/create-record.form.actions.cancel.label');
}
}
19 changes: 19 additions & 0 deletions src/Widgets/Forms/EditEventForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,23 @@ protected function getEditEventForm(): array
->statePath('editEventFormState'),
];
}

public function getEditEventModalTitle(): string
{
return $this->editEventForm->isDisabled()
? __('filament::resources/pages/view-record.title', ['label' => $this->getModalLabel()])
: __('filament::resources/pages/edit-record.title', ['label' => $this->getModalLabel()]);
}

public function getEditEventModalSubmitButtonLabel(): string
{
return __('filament::resources/pages/edit-record.form.actions.save.label');
}

public function getEditEventModalCloseButtonLabel(): string
{
return $this->editEventForm->isDisabled()
? __('filament-support::actions/view.single.modal.actions.close.label')
: __('filament::resources/pages/edit-record.form.actions.cancel.label');
}
}

0 comments on commit 2ee7ff2

Please sign in to comment.