From 09f5f07eaed7131e66c46065767cac6b1d7320cd Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 5 Jun 2025 16:18:44 -0700 Subject: [PATCH 01/10] use `address` --- src/Types/Event.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Types/Event.php b/src/Types/Event.php index cb61c3c..6d8999f 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -109,8 +109,8 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent ->startsAt($immutableDate->setTimeFromTimeString($this->startTime())) ->endsAt($immutableDate->setTimeFromTimeString($this->endTime())); - if (!is_null($location = $this->location($this->event))) { - $iCalEvent->address($location); + if (! is_null($address = $this->event->address ?? $this->location($this->event))) { + $iCalEvent->address($address); } if (!is_null($description = $this->event->description)) { From 43d4298af318fe642ed80944c6beccb62d93dbe6 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 5 Jun 2025 16:19:00 -0700 Subject: [PATCH 02/10] support coordinates --- src/Types/Event.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Types/Event.php b/src/Types/Event.php index 6d8999f..1ed1776 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -113,7 +113,11 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent $iCalEvent->address($address); } - if (!is_null($description = $this->event->description)) { + if (! is_null($coordinates = $this->event->coordinates)) { + $iCalEvent->coordinates($coordinates->latitude, $coordinates->longitude); + } + + if (! is_null($description = $this->event->description)) { $iCalEvent->description($description); } From ee4f1f1ce0105eb5639b8a38ab0becd0136fd72c Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 5 Jun 2025 16:19:09 -0700 Subject: [PATCH 03/10] formatting --- src/Types/Event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Types/Event.php b/src/Types/Event.php index 1ed1776..de41e40 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -121,7 +121,7 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent $iCalEvent->description($description); } - if (!is_null($link = $this->event->link)) { + if (! is_null($link = $this->event->link)) { $iCalEvent->url($link); } From 80175f4187490bf6608be6c1936506a681895f58 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 5 Jun 2025 16:19:13 -0700 Subject: [PATCH 04/10] tests --- tests/Feature/IcsControllerTest.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/Feature/IcsControllerTest.php b/tests/Feature/IcsControllerTest.php index 3e60eef..94fae0b 100755 --- a/tests/Feature/IcsControllerTest.php +++ b/tests/Feature/IcsControllerTest.php @@ -22,9 +22,14 @@ protected function setUp(): void 'start_date' => Carbon::now()->toDateString(), 'start_time' => '11:00', 'end_time' => '12:00', + 'address' => '123 Main St', 'location' => 'The Location', + 'coordinates' => [ + 'latitude' => 40, + 'longitude' => 50, + ], 'description' => 'The description', - 'link' => 'https://transformstudios.com' + 'link' => 'https://transformstudios.com', ])->save(); } @@ -38,10 +43,13 @@ public function can_create_single_day_event_ics_file() 'event' => 'the-id', ]))->assertDownload('single-event.ics'); + $content = $response->streamedContent(); + $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); - $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); - $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); - $this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent()); + $this->assertStringContainsString('LOCATION:123 Main St', $content); + $this->assertStringContainsString('DESCRIPTION:The description', $content); + $this->assertStringContainsString('GEO:40;50', $content); + $this->assertStringContainsString('URL:https://transformstudios.com', $content); } #[Test] @@ -61,7 +69,7 @@ public function can_create_single_day_recurring_event_ics_file() 'recurrence' => 'weekly', 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com' + 'link' => 'https://transformstudios.com', ])->save(); $response = $this->get(route('statamic.events.ics.show', [ @@ -97,7 +105,7 @@ public function can_create_ics_with_single_date_recurrence() 'recurrence' => 'weekly', 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com' + 'link' => 'https://transformstudios.com', ])->save(); $response = $this->get(route('statamic.events.ics.show', [ @@ -105,7 +113,6 @@ public function can_create_ics_with_single_date_recurrence() 'event' => 'the-recurring-id', ]))->assertDownload('recurring-event.ics'); - $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); @@ -130,7 +137,7 @@ public function can_create_ics_with_recurrence() 'recurrence' => 'weekly', 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com' + 'link' => 'https://transformstudios.com', ])->save(); $response = $this->get(route('statamic.events.ics.show', [ From 11a7279daa65a5d930de9af669fae9460acaa088 Mon Sep 17 00:00:00 2001 From: edalzell Date: Fri, 6 Jun 2025 11:26:34 -0700 Subject: [PATCH 05/10] need this cuz we always get data back from coordinates --- src/Types/Event.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Types/Event.php b/src/Types/Event.php index de41e40..542d84a 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -113,8 +113,8 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent $iCalEvent->address($address); } - if (! is_null($coordinates = $this->event->coordinates)) { - $iCalEvent->coordinates($coordinates->latitude, $coordinates->longitude); + if (! is_null($this->event->coordinates->latitude) && ! is_null($this->event->coordinates->longitude)) { + $iCalEvent->coordinates($this->event->coordinates->latitude, $this->event->coordinates->longitude); } if (! is_null($description = $this->event->description)) { From eea0a1e657eb98313a937e2537b0bc9b97ebefbd Mon Sep 17 00:00:00 2001 From: edalzell Date: Fri, 6 Jun 2025 15:38:28 -0700 Subject: [PATCH 06/10] =?UTF-8?q?don=E2=80=99t=20set=20url,=20for=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Types/Event.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Types/Event.php b/src/Types/Event.php index 542d84a..79ef7cf 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -121,10 +121,6 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent $iCalEvent->description($description); } - if (! is_null($link = $this->event->link)) { - $iCalEvent->url($link); - } - return $iCalEvent; } From f9dd4160650478a30ddbf90720f75f62b63341b5 Mon Sep 17 00:00:00 2001 From: edalzell Date: Fri, 6 Jun 2025 15:52:08 -0700 Subject: [PATCH 07/10] assume array --- src/Types/Event.php | 4 ++-- tests/Feature/IcsControllerTest.php | 12 ------------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/Types/Event.php b/src/Types/Event.php index 79ef7cf..a84d62e 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -113,8 +113,8 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent $iCalEvent->address($address); } - if (! is_null($this->event->coordinates->latitude) && ! is_null($this->event->coordinates->longitude)) { - $iCalEvent->coordinates($this->event->coordinates->latitude, $this->event->coordinates->longitude); + if (! is_null($coords = $this->event->coordinates)) { + $iCalEvent->coordinates($coords['latitude'], $coords['longitude']); } if (! is_null($description = $this->event->description)) { diff --git a/tests/Feature/IcsControllerTest.php b/tests/Feature/IcsControllerTest.php index 94fae0b..2e43ae3 100755 --- a/tests/Feature/IcsControllerTest.php +++ b/tests/Feature/IcsControllerTest.php @@ -29,7 +29,6 @@ protected function setUp(): void 'longitude' => 50, ], 'description' => 'The description', - 'link' => 'https://transformstudios.com', ])->save(); } @@ -49,7 +48,6 @@ public function can_create_single_day_event_ics_file() $this->assertStringContainsString('LOCATION:123 Main St', $content); $this->assertStringContainsString('DESCRIPTION:The description', $content); $this->assertStringContainsString('GEO:40;50', $content); - $this->assertStringContainsString('URL:https://transformstudios.com', $content); } #[Test] @@ -69,7 +67,6 @@ public function can_create_single_day_recurring_event_ics_file() 'recurrence' => 'weekly', 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com', ])->save(); $response = $this->get(route('statamic.events.ics.show', [ @@ -80,7 +77,6 @@ public function can_create_single_day_recurring_event_ics_file() $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); - $this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent()); $this->get(route('statamic.events.ics.show', [ 'date' => now()->addDay()->toDateString(), @@ -105,7 +101,6 @@ public function can_create_ics_with_single_date_recurrence() 'recurrence' => 'weekly', 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com', ])->save(); $response = $this->get(route('statamic.events.ics.show', [ @@ -116,7 +111,6 @@ public function can_create_ics_with_single_date_recurrence() $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); - $this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent()); } @@ -137,7 +131,6 @@ public function can_create_ics_with_recurrence() 'recurrence' => 'weekly', 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com', ])->save(); $response = $this->get(route('statamic.events.ics.show', [ @@ -147,8 +140,6 @@ public function can_create_ics_with_recurrence() $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); - $this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent()); - } #[Test] @@ -165,7 +156,6 @@ public function can_create_single_day_multiday_event_ics_file() 'multi_day' => true, 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com', 'days' => [ [ 'date' => now()->toDateString(), @@ -198,8 +188,6 @@ public function can_create_single_day_multiday_event_ics_file() $this->assertStringContainsString('DTSTART:'.now()->addDay()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); - $this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent()); - } #[Test] From ddae4f867269309f0436825cc5406e0ccca2cd69 Mon Sep 17 00:00:00 2001 From: edalzell Date: Fri, 6 Jun 2025 16:01:40 -0700 Subject: [PATCH 08/10] update docs --- DOCUMENTATION.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 1e0f8b0..f0300b0 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -12,15 +12,7 @@ If you'd like to have a different event timezone default than the app default (u The default collection for your events is `events`, if you use a different one, publish the config file and then update it via the CP. -For the ICS downloads, you can have a "location" field. By default Events uses a field named 'location' but if you need something different add it to the config: - -```php - 'collections' => [ - 'events' => [ - 'location_field' => 'your_location_field', - ], - ], -``` +For the ICS downloads, it will use `address`, `coordinates`, and `description` fields if they exist. If your field is named something else, use a [Computed Value](https://statamic.dev/computed-values). ## Fieldset From 5a6246753ca58348302a464aa38e3ac04d20475d Mon Sep 17 00:00:00 2001 From: edalzell Date: Fri, 6 Jun 2025 16:04:29 -0700 Subject: [PATCH 09/10] document coordinates --- DOCUMENTATION.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index f0300b0..a2541f7 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -12,7 +12,13 @@ If you'd like to have a different event timezone default than the app default (u The default collection for your events is `events`, if you use a different one, publish the config file and then update it via the CP. -For the ICS downloads, it will use `address`, `coordinates`, and `description` fields if they exist. If your field is named something else, use a [Computed Value](https://statamic.dev/computed-values). +For the ICS downloads, it will use `address`, `coordinates`, and `description` fields if they exist. If your field is named something else, use a [Computed Value](https://statamic.dev/computed-values). `coordinates` must be a keyed array: +``` +'coordinates' => [ + 'latitude' => 40, + 'longitude' => 50, +], +``` ## Fieldset From 18aea56dfb4ba81f77a3fbed67cf3b2479b7d0f4 Mon Sep 17 00:00:00 2001 From: edalzell Date: Mon, 9 Jun 2025 11:45:35 -0700 Subject: [PATCH 10/10] do url --- src/Types/Event.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Types/Event.php b/src/Types/Event.php index a84d62e..06a23b4 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -121,6 +121,10 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent $iCalEvent->description($description); } + if (! is_null($link = $this->event->link)) { + $iCalEvent->url($link); + } + return $iCalEvent; }