From aaa8b620fb0cb128e90035440b20c8194243b541 Mon Sep 17 00:00:00 2001 From: Tiago Fernandes Date: Fri, 26 Aug 2022 10:37:09 +0100 Subject: [PATCH 1/3] done --- src/Widgets/Concerns/CanManageEvents.php | 4 ++-- src/Widgets/Forms/CreateEventForm.php | 1 + src/Widgets/Forms/EditEventForm.php | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Widgets/Concerns/CanManageEvents.php b/src/Widgets/Concerns/CanManageEvents.php index 99810e4..b6ada73 100644 --- a/src/Widgets/Concerns/CanManageEvents.php +++ b/src/Widgets/Concerns/CanManageEvents.php @@ -50,14 +50,14 @@ public function onEventClick($event): void return; } - $this->editEventForm->fill($event); - if (method_exists($this, 'resolveEventRecord')) { $this->event = $this->resolveEventRecord($event); } else { $this->event_id = $event['id'] ?? null; } + $this->editEventForm->fill($this->event?->getAttributes() ?? $event); + $this->dispatchBrowserEvent('open-modal', ['id' => 'fullcalendar--edit-event-modal']); } diff --git a/src/Widgets/Forms/CreateEventForm.php b/src/Widgets/Forms/CreateEventForm.php index 4469d6d..75bc424 100644 --- a/src/Widgets/Forms/CreateEventForm.php +++ b/src/Widgets/Forms/CreateEventForm.php @@ -36,6 +36,7 @@ protected function getCreateEventForm(): array { return [ 'createEventForm' => $this->makeForm() + ->model($this->getFormModel() ? $this->getFormModel()::getModel() : null) ->schema(static::getCreateEventFormSchema()) ->statePath('createEventFormState'), ]; diff --git a/src/Widgets/Forms/EditEventForm.php b/src/Widgets/Forms/EditEventForm.php index 09a2892..fecc532 100644 --- a/src/Widgets/Forms/EditEventForm.php +++ b/src/Widgets/Forms/EditEventForm.php @@ -36,6 +36,7 @@ protected function getEditEventForm(): array { return [ 'editEventForm' => $this->makeForm() + ->model($this->getFormModel()) ->schema(static::getEditEventFormSchema()) ->statePath('editEventFormState'), ]; From 17cebaf2cfb44707e5c7e89efe6328e747f86218 Mon Sep 17 00:00:00 2001 From: Tiago Fernandes Date: Tue, 30 Aug 2022 11:53:07 +0100 Subject: [PATCH 2/3] Fix relationship saving --- src/Widgets/Forms/CreateEventForm.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Widgets/Forms/CreateEventForm.php b/src/Widgets/Forms/CreateEventForm.php index 75bc424..1d74b61 100644 --- a/src/Widgets/Forms/CreateEventForm.php +++ b/src/Widgets/Forms/CreateEventForm.php @@ -3,6 +3,7 @@ namespace Saade\FilamentFullCalendar\Widgets\Forms; use Filament\Forms; +use Illuminate\Database\Eloquent\Model; trait CreateEventForm { @@ -10,14 +11,19 @@ trait CreateEventForm public function onCreateEventSubmit() { - $this->createEvent($this->createEventForm->getState()); + $eventModel = $this->createEvent($this->createEventForm->getState()); + if ($eventModel) { + $this->createEventForm->model($eventModel); + $this->createEventForm->saveRelationships(); + } $this->dispatchBrowserEvent('close-modal', ['id' => 'fullcalendar--create-event-modal']); } - public function createEvent(array $data): void + public function createEvent(array $data): ?Model { // Override this function and do whatever you want with $data + return null; } protected static function getCreateEventFormSchema(): array @@ -36,7 +42,7 @@ protected function getCreateEventForm(): array { return [ 'createEventForm' => $this->makeForm() - ->model($this->getFormModel() ? $this->getFormModel()::getModel() : null) + ->model($this->getFormModel()::getModel()) ->schema(static::getCreateEventFormSchema()) ->statePath('createEventFormState'), ]; From 8820eb0393a238006232b4357b11186ebf1194b7 Mon Sep 17 00:00:00 2001 From: Tiago Fernandes Date: Fri, 2 Sep 2022 12:15:07 +0100 Subject: [PATCH 3/3] Update CanManageEvents.php link the model to the edit form, when clicking and event --- src/Widgets/Concerns/CanManageEvents.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Widgets/Concerns/CanManageEvents.php b/src/Widgets/Concerns/CanManageEvents.php index b6ada73..1a6b02d 100644 --- a/src/Widgets/Concerns/CanManageEvents.php +++ b/src/Widgets/Concerns/CanManageEvents.php @@ -52,6 +52,7 @@ public function onEventClick($event): void if (method_exists($this, 'resolveEventRecord')) { $this->event = $this->resolveEventRecord($event); + $this->editEventForm->model($this->event); } else { $this->event_id = $event['id'] ?? null; }