Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ ICS downloads read the following entry fields when present:
| ICS property | Source |
|---|---|
| `LOCATION` | `address`, falling back to `location` — only when the value is a string |
| `URL` | `link`, falling back to `location` when that string is a URL |
| `URL` | `online_url`, then deprecated `link`, then deprecated `location` when that string is a URL |
| `GEO` | `coordinates` (`latitude` / `longitude`) |
| `DESCRIPTION` | `description` |

A URL-valued `location` (with no separate `address` / `link`) currently emits **both** `LOCATION:` and `URL:`.
A URL-valued `location` (with no separate `address` / `online_url` / `link`) currently emits **both** `LOCATION:` and `URL:`. Prefer `online_url` for join links; `link` and the URL-valued `location` fallback are deprecated and will be removed in 7.0.

The `coordinates` field must be a keyed array:

Expand Down Expand Up @@ -79,6 +79,14 @@ Using the sample fieldset is the fastest way to get started.

## Fields

### Location & Online URL

| Field | Description |
|-------|-------------|
| `online_url` | Join link for online or hybrid events (Zoom, livestream, etc.). Optional; can be combined with a physical place once `location` is declared. |

`link` is deprecated in favour of `online_url` and will be removed in 7.0.

### Single-Day Events

| Field | Required | Description |
Expand Down
16 changes: 16 additions & 0 deletions resources/fieldsets/event.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,19 @@ fields:
field: 'events::event.all_day'
config:
width: 25
-
handle: location_section
field:
type: section
display: Location
-
handle: online_url
field:
type: text
input_type: url
display: 'Online URL'
localizable: false
validate:
- nullable
- url
instructions: 'Join link for online or hybrid events (Zoom, livestream, etc.).'
14 changes: 10 additions & 4 deletions src/Types/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,28 @@ protected function decorate(ICalendarEvent $iCalEvent): ICalendarEvent
$iCalEvent->description($description);
}

if (! is_null($link = $this->eventUrl())) {
$iCalEvent->url($link);
if (! is_null($url = $this->eventUrl())) {
$iCalEvent->url($url);
}

return $iCalEvent;
}

protected function eventUrl(): ?string
{
if (! is_null($link = $this->event->link)) {
if (is_string($url = $this->event->get('online_url')) && $url !== '') {
return $url;
}

// @deprecated Will be removed in 7.0. Use online_url.
if (is_string($link = $this->event->get('link')) && $link !== '') {
return $link;
}

// @deprecated Will be removed in 7.0. Use online_url.
$location = $this->event->get('location');

if (! is_string($location)) {
if (! is_string($location) || $location === '') {
return null;
}

Expand Down
175 changes: 175 additions & 0 deletions tests/Http/Contollers/IcsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,178 @@
$this->assertStringContainsString('LOCATION:123 Main St', $content);
$this->assertStringNotContainsString('GEO:', $content);
});

test('online_url emits URL', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

Entry::make()
->collection('events')
->slug('online-url-event')
->id('online-url-id')
->data([
'title' => 'Online URL Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'online_url' => 'https://zoom.us/j/123',
])->save();

$content = $this->get(route('statamic.events.ics.show', [
'date' => now()->toDateString(),
'event' => 'online-url-id',
]))->assertDownload('online-url-event.ics')->streamedContent();

$this->assertStringContainsString('URL:https://zoom.us/j/123', $content);
});

test('online_url wins over link when both are set', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

Entry::make()
->collection('events')
->slug('online-over-link-event')
->id('online-over-link-id')
->data([
'title' => 'Online Over Link Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'online_url' => 'https://zoom.us/j/123',
'link' => 'https://example.com/old-link',
])->save();

$content = $this->get(route('statamic.events.ics.show', [
'date' => now()->toDateString(),
'event' => 'online-over-link-id',
]))->assertDownload('online-over-link-event.ics')->streamedContent();

$this->assertStringContainsString('URL:https://zoom.us/j/123', $content);
$this->assertStringNotContainsString('URL:https://example.com/old-link', $content);
});

test('deprecated link alone still emits URL', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

Entry::make()
->collection('events')
->slug('link-only-event')
->id('link-only-id')
->data([
'title' => 'Link Only Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'link' => 'https://example.com/join',
])->save();

$content = $this->get(route('statamic.events.ics.show', [
'date' => now()->toDateString(),
'event' => 'link-only-id',
]))->assertDownload('link-only-event.ics')->streamedContent();

$this->assertStringContainsString('URL:https://example.com/join', $content);
});

test('deprecated URL-valued location alone still emits LOCATION and URL', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

Entry::make()
->collection('events')
->slug('url-location-event')
->id('url-location-id')
->data([
'title' => 'URL Location Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'location' => 'https://zoom.us/j/456',
])->save();

$content = $this->get(route('statamic.events.ics.show', [
'date' => now()->toDateString(),
'event' => 'url-location-id',
]))->assertDownload('url-location-event.ics')->streamedContent();

$this->assertStringContainsString('LOCATION:https://zoom.us/j/456', $content);
$this->assertStringContainsString('URL:https://zoom.us/j/456', $content);
});

test('online_url is included on all four download routes', function () {
Carbon::setTestNow(now());

Entry::make()
->collection('events')
->slug('online-single')
->id('online-single-id')
->data([
'title' => 'Online Single',
'start_date' => now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'online_url' => 'https://zoom.us/j/single',
])->save();

Entry::make()
->collection('events')
->slug('online-recurring')
->id('online-recurring-id')
->data([
'title' => 'Online Recurring',
'start_date' => now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'recurrence' => 'weekly',
'online_url' => 'https://zoom.us/j/recurring',
])->save();

Entry::make()
->collection('events')
->slug('online-multi-day')
->id('online-multi-day-id')
->data([
'title' => 'Online Multi Day',
'multi_day' => true,
'online_url' => 'https://zoom.us/j/multiday',
'days' => [
[
'date' => now()->toDateString(),
'start_time' => '19:00',
'end_time' => '21:00',
],
[
'date' => now()->addDay()->toDateString(),
'start_time' => '11:00',
'end_time' => '15:00',
],
],
])->save();

$single = $this->get(route('statamic.events.ics.show', [
'date' => now()->toDateString(),
'event' => 'online-single-id',
]))->assertDownload('online-single.ics')->streamedContent();

$recurringDate = $this->get(route('statamic.events.ics.show', [
'date' => now()->toDateString(),
'event' => 'online-recurring-id',
]))->assertDownload('online-recurring.ics')->streamedContent();

$recurringWhole = $this->get(route('statamic.events.ics.show', [
'event' => 'online-recurring-id',
]))->assertDownload('online-recurring.ics')->streamedContent();

$multiDate = $this->get(route('statamic.events.ics.show', [
'date' => now()->toDateString(),
'event' => 'online-multi-day-id',
]))->assertDownload('online-multi-day.ics')->streamedContent();

$multiWhole = $this->get(route('statamic.events.ics.show', [
'event' => 'online-multi-day-id',
]))->assertDownload('online-multi-day.ics')->streamedContent();

$this->assertStringContainsString('URL:https://zoom.us/j/single', $single);
$this->assertStringContainsString('URL:https://zoom.us/j/recurring', $recurringDate);
$this->assertStringContainsString('URL:https://zoom.us/j/recurring', $recurringWhole);
$this->assertStringContainsString('URL:https://zoom.us/j/multiday', $multiDate);
expect(substr_count($multiWhole, 'URL:https://zoom.us/j/multiday'))->toBe(2);
});