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: 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..e07161f 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->{$locationField}; + } + protected function supplement(CarbonInterface $date): ?Entry { return unserialize(serialize($this->event))