From 35cf5d8ab2f4c6c4e95766d1321d0eed487351a4 Mon Sep 17 00:00:00 2001 From: edalzell Date: Wed, 15 Jul 2026 20:21:26 -0700 Subject: [PATCH 1/3] failing test --- tests/Tags/EventsTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Tags/EventsTest.php b/tests/Tags/EventsTest.php index 6a3b859..0817c5a 100755 --- a/tests/Tags/EventsTest.php +++ b/tests/Tags/EventsTest.php @@ -30,6 +30,18 @@ test('can generate between occurrences of a specific event', function () { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); + Entry::make() + ->collection('events') + ->slug('single-event') + ->id('single-event') + ->data([ + 'title' => 'Single Event', + 'start_date' => Carbon::now()->toDateString(), + 'start_time' => '11:00', + 'end_time' => '12:00', + 'categories' => ['one'], + ])->save(); + $this->tag ->setContext([]) ->setParameters([ From ed18b31c268007fcae3d5b339f18ec2c989ba22d Mon Sep 17 00:00:00 2001 From: edalzell Date: Wed, 15 Jul 2026 20:21:35 -0700 Subject: [PATCH 2/3] pass test --- src/Entries.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Entries.php b/src/Entries.php index 907c1d8..36e71c3 100644 --- a/src/Entries.php +++ b/src/Entries.php @@ -3,6 +3,7 @@ namespace TransformStudios\Events; use Statamic\Facades\Entry; +use Statamic\Support\Arr; use Statamic\Tags\Collection\Entries as BaseEntries; class Entries extends BaseEntries @@ -16,7 +17,11 @@ class Entries extends BaseEntries protected function query() { $query = Entry::query() - ->whereIn('collection', $this->collections->map->handle()->all()); + ->whereIn('collection', $this->collections->map->handle()->all()) + ->when( + $this->params->get('event'), + fn ($query, $id) => $query->whereIn('id', Arr::wrap($id)) + ); $this->querySite($query); $this->queryPublished($query); From e9afc938fe8669fdd90ba761f6475239138320c7 Mon Sep 17 00:00:00 2001 From: edalzell Date: Wed, 15 Jul 2026 20:47:39 -0700 Subject: [PATCH 3/3] tidy up and document --- DOCUMENTATION.md | 21 +++++++++++++-------- src/Entries.php | 4 ++-- src/Events.php | 5 +++++ tests/Tags/EventsTest.php | 11 +++++++++++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 8e5723c..b1f2579 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -193,13 +193,18 @@ sort="desc" ## Tag Reference +> **Note:** `collection` and `event` are mutually exclusive. Pass `collection` to +> list occurrences from a whole collection, or `event` to get occurrences for a +> single entry — not both. Using them together throws an exception. (This does not +> apply to `events:download_link`, which accepts both.) + ### events:between Returns events within a date range. **Parameters:** -- `collection` (optional, defaults to 'events') -- `event` (optional) Pass `id` of the event you want occurrences for +- `collection` (optional, defaults to 'events'; cannot be combined with `event`) +- `event` (optional) Pass `id` of the event you want occurrences for; cannot be combined with `collection` - `from` (optional, defaults to now) - `to` (required) @@ -221,8 +226,8 @@ Additional flags: Returns events within a future time window. **Parameters:** -- `collection` (optional, defaults to 'events') -- `event` (optional) Pass `id` of the event you want occurrences for +- `collection` (optional, defaults to 'events'; cannot be combined with `event`) +- `event` (optional) Pass `id` of the event you want occurrences for; cannot be combined with `collection` Example: @@ -235,8 +240,8 @@ next="90 days" Returns events occurring today. **Parameters:** -- `collection` (optional, defaults to 'events') -- `event` (optional) Pass `id` of the event you want occurrences for +- `collection` (optional, defaults to 'events'; cannot be combined with `event`) +- `event` (optional) Pass `id` of the event you want occurrences for; cannot be combined with `collection` - `ignore_past` (optional, defaults to 'false') ### events:upcoming @@ -245,8 +250,8 @@ Returns the next set of event occurrences. **Parameters:** - `limit` (required) -- `collection` (optional, defaults to 'events') -- `event` (optional) Pass `id` of the event you want occurrences for +- `collection` (optional, defaults to 'events'; cannot be combined with `event`) +- `event` (optional) Pass `id` of the event you want occurrences for; cannot be combined with `collection` - `collapse_multi_days` (optional) - `offset` (optional) diff --git a/src/Entries.php b/src/Entries.php index 36e71c3..ab0e60d 100644 --- a/src/Entries.php +++ b/src/Entries.php @@ -17,10 +17,10 @@ class Entries extends BaseEntries protected function query() { $query = Entry::query() - ->whereIn('collection', $this->collections->map->handle()->all()) ->when( $this->params->get('event'), - fn ($query, $id) => $query->whereIn('id', Arr::wrap($id)) + fn ($query, $id) => $query->whereIn('id', Arr::wrap($id)), + fn ($query) => $query->whereIn('collection', $this->collections->map->handle()->all()) ); $this->querySite($query); diff --git a/src/Events.php b/src/Events.php index 33e74b3..99f488d 100644 --- a/src/Events.php +++ b/src/Events.php @@ -57,6 +57,11 @@ public static function fromEntry(string $id): self public function __construct(Parameters $params) { + throw_if( + $params->has('collection') && $params->has('event'), + new Exception('The [collection] and [event] parameters cannot be used together.') + ); + $this ->params($params) // gotta be first cuz some of the later one push to it ->collection($params->get('collection', 'events')) diff --git a/tests/Tags/EventsTest.php b/tests/Tags/EventsTest.php index 0817c5a..52079f0 100755 --- a/tests/Tags/EventsTest.php +++ b/tests/Tags/EventsTest.php @@ -55,6 +55,17 @@ expect($occurrences)->toHaveCount(4); }); +test('throws when both collection and event params are used', function () { + $this->tag + ->setContext([]) + ->setParameters([ + 'collection' => 'events', + 'event' => 'recurring-event', + ]); + + $this->tag->between(); +})->throws(\Exception::class, 'The [collection] and [event] parameters cannot be used together.'); + test('can generate between occurrences', function () { Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));