Skip to content

Commit 45d0c9d

Browse files
authored
Support address and coordinates fields (#115)
1 parent 16418cf commit 45d0c9d

3 files changed

Lines changed: 24 additions & 27 deletions

File tree

DOCUMENTATION.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ 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-
],
15+
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:
16+
```
17+
'coordinates' => [
18+
'latitude' => 40,
19+
'longitude' => 50,
20+
],
2321
```
2422

2523
## Fieldset

src/Types/Event.php

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

112-
if (!is_null($location = $this->location($this->event))) {
113-
$iCalEvent->address($location);
112+
if (! is_null($address = $this->event->address ?? $this->location($this->event))) {
113+
$iCalEvent->address($address);
114114
}
115115

116-
if (!is_null($description = $this->event->description)) {
116+
if (! is_null($coords = $this->event->coordinates)) {
117+
$iCalEvent->coordinates($coords['latitude'], $coords['longitude']);
118+
}
119+
120+
if (! is_null($description = $this->event->description)) {
117121
$iCalEvent->description($description);
118122
}
119123

120-
if (!is_null($link = $this->event->link)) {
124+
if (! is_null($link = $this->event->link)) {
121125
$iCalEvent->url($link);
122126
}
123127

tests/Feature/IcsControllerTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ protected function setUp(): void
2222
'start_date' => Carbon::now()->toDateString(),
2323
'start_time' => '11:00',
2424
'end_time' => '12:00',
25+
'address' => '123 Main St',
2526
'location' => 'The Location',
27+
'coordinates' => [
28+
'latitude' => 40,
29+
'longitude' => 50,
30+
],
2631
'description' => 'The description',
27-
'link' => 'https://transformstudios.com'
2832
])->save();
2933
}
3034

@@ -38,10 +42,12 @@ public function can_create_single_day_event_ics_file()
3842
'event' => 'the-id',
3943
]))->assertDownload('single-event.ics');
4044

45+
$content = $response->streamedContent();
46+
4147
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
42-
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
43-
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
44-
$this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent());
48+
$this->assertStringContainsString('LOCATION:123 Main St', $content);
49+
$this->assertStringContainsString('DESCRIPTION:The description', $content);
50+
$this->assertStringContainsString('GEO:40;50', $content);
4551
}
4652

4753
#[Test]
@@ -61,7 +67,6 @@ public function can_create_single_day_recurring_event_ics_file()
6167
'recurrence' => 'weekly',
6268
'location' => 'The Location',
6369
'description' => 'The description',
64-
'link' => 'https://transformstudios.com'
6570
])->save();
6671

6772
$response = $this->get(route('statamic.events.ics.show', [
@@ -72,7 +77,6 @@ public function can_create_single_day_recurring_event_ics_file()
7277
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
7378
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
7479
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
75-
$this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent());
7680

7781
$this->get(route('statamic.events.ics.show', [
7882
'date' => now()->addDay()->toDateString(),
@@ -97,19 +101,16 @@ public function can_create_ics_with_single_date_recurrence()
97101
'recurrence' => 'weekly',
98102
'location' => 'The Location',
99103
'description' => 'The description',
100-
'link' => 'https://transformstudios.com'
101104
])->save();
102105

103106
$response = $this->get(route('statamic.events.ics.show', [
104107
'date' => now()->toDateString(),
105108
'event' => 'the-recurring-id',
106109
]))->assertDownload('recurring-event.ics');
107110

108-
109111
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
110112
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
111113
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
112-
$this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent());
113114

114115
}
115116

@@ -130,7 +131,6 @@ public function can_create_ics_with_recurrence()
130131
'recurrence' => 'weekly',
131132
'location' => 'The Location',
132133
'description' => 'The description',
133-
'link' => 'https://transformstudios.com'
134134
])->save();
135135

136136
$response = $this->get(route('statamic.events.ics.show', [
@@ -140,8 +140,6 @@ public function can_create_ics_with_recurrence()
140140
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
141141
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
142142
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
143-
$this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent());
144-
145143
}
146144

147145
#[Test]
@@ -158,7 +156,6 @@ public function can_create_single_day_multiday_event_ics_file()
158156
'multi_day' => true,
159157
'location' => 'The Location',
160158
'description' => 'The description',
161-
'link' => 'https://transformstudios.com',
162159
'days' => [
163160
[
164161
'date' => now()->toDateString(),
@@ -191,8 +188,6 @@ public function can_create_single_day_multiday_event_ics_file()
191188
$this->assertStringContainsString('DTSTART:'.now()->addDay()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
192189
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
193190
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
194-
$this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent());
195-
196191
}
197192

198193
#[Test]

0 commit comments

Comments
 (0)