Skip to content

Commit 043d64e

Browse files
authored
Make location field configurable (#104)
* use augmented value so computed fields work * docs
1 parent 4f47ed0 commit 043d64e

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

DOCUMENTATION.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ If you'd like to have a different event timezone default than the app default (u
1212

1313
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.
1414

15+
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:
16+
17+
```php
18+
'collections' => [
19+
'events' => [
20+
'location_field' => 'your_location_field',
21+
],
22+
],
23+
```
24+
1525
## Fieldset
1626

1727
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.
218228

219229
### Download Links
220230

221-
Single Tag returns a url to the event data and add it to your calendar.
231+
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.
222232

223233
Parameters:
224234

config/events.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@
22

33
return [
44
'collection' => 'events',
5+
6+
'collections' => [
7+
'events' => [
8+
'location_field' => 'location',
9+
],
10+
],
11+
512
'timezone' => config('app.timezone'),
613
];

src/Types/Event.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent
109109
->startsAt($immutableDate->setTimeFromTimeString($this->startTime()))
110110
->endsAt($immutableDate->setTimeFromTimeString($this->endTime()));
111111

112-
if ($location = $this->event->location) {
112+
if ($location = $this->location($this->event)) {
113113
$iCalEvent->address($location);
114114
}
115115

@@ -126,6 +126,15 @@ public function toICalendarEvents(): array
126126
];
127127
}
128128

129+
protected function location(Entry $event): ?string
130+
{
131+
$collectionHandle = $event->collectionHandle();
132+
133+
$locationField = config("events.collections.$collectionHandle.location_field", 'location');
134+
135+
return $event->{$locationField};
136+
}
137+
129138
protected function supplement(CarbonInterface $date): ?Entry
130139
{
131140
return unserialize(serialize($this->event))

0 commit comments

Comments
 (0)