From 850adc6903b2e97858cf33b120d6adde03561ec0 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 6 Feb 2025 15:21:55 -0800 Subject: [PATCH 1/3] wip --- config/events.php | 7 +++++++ src/Types/Event.php | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config/events.php b/config/events.php index 527154c..c229b5e 100644 --- a/config/events.php +++ b/config/events.php @@ -2,5 +2,12 @@ return [ 'collection' => 'events', + + 'collections' => [ + 'events' => [ + 'location_field' => 'location', + ], + ], + 'timezone' => config('app.timezone'), ]; diff --git a/src/Types/Event.php b/src/Types/Event.php index 6697fcc..e79448f 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -109,7 +109,7 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent ->startsAt($immutableDate->setTimeFromTimeString($this->startTime())) ->endsAt($immutableDate->setTimeFromTimeString($this->endTime())); - if ($location = $this->event->location) { + if ($location = $this->location($this->event)) { $iCalEvent->address($location); } @@ -126,6 +126,15 @@ public function toICalendarEvents(): array ]; } + protected function location(Entry $event): ?string + { + $collectionHandle = $event->collectionHandle(); + + $locationField = config("events.collections.$collectionHandle.location_field", 'location'); + + return $event->get($locationField); + } + protected function supplement(CarbonInterface $date): ?Entry { return unserialize(serialize($this->event)) From e67d738bcb471dbf9950105918262448db0e5fff Mon Sep 17 00:00:00 2001 From: edalzell Date: Fri, 7 Feb 2025 11:26:30 -0800 Subject: [PATCH 2/3] use augmented value so computed fields work --- 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 e79448f..e07161f 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -132,7 +132,7 @@ protected function location(Entry $event): ?string $locationField = config("events.collections.$collectionHandle.location_field", 'location'); - return $event->get($locationField); + return $event->{$locationField}; } protected function supplement(CarbonInterface $date): ?Entry From 7e948acc7412c1e49712b0b60630d73d0f121ed5 Mon Sep 17 00:00:00 2001 From: edalzell Date: Fri, 7 Feb 2025 14:16:25 -0800 Subject: [PATCH 3/3] docs --- DOCUMENTATION.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index f0d611f..8bdb90f 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -12,6 +12,16 @@ 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', + ], + ], +``` + ## Fieldset In your collection's blueprint, make sure you have fields like in our sample [fieldset](https://github.com/transformstudios/statamic-events/blob/main/resources/fieldsets/event.yaml). @@ -218,7 +228,7 @@ Tag pair that returns the next X event dates. ### Download Links -Single Tag returns a url to the event data and add it to your calendar. +Single Tag returns a url to the event data and add it to your calendar. If there's a "location" field (see config above), it'll get added to the download. Parameters: