Skip to content

Commit

Permalink
use config
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed May 1, 2024
1 parent 93dbd31 commit 42ea932
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion config/events.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?php

return [];
return [
'collection' => 'events',
'timezone' => config('app.timezone'),
];
2 changes: 1 addition & 1 deletion src/Http/Controllers/IcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class IcsController extends Controller

public function __invoke(Request $request)
{
$handle = $request->get('collection', 'events');
$handle = $request->get('collection', config('events.collection'));
$date = $request->has('date') ? CarbonImmutable::parse($request->get('date')) : null;
$eventId = $request->get('event');
$entry = null;
Expand Down
12 changes: 8 additions & 4 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,26 @@ private function bootCarbon(): self

private function bootFields(): self
{
Collection::computed('events', 'recurrence', function ($entry, $value) {
if (is_null($collectionHandle = config('events.collection'))) {
return $this;
}

Collection::computed($collectionHandle, 'recurrence', function ($entry, $value) {
if ($value) {
return $value;
}

return $entry->multi_day ? 'multi_day' : 'none';
});

Collection::computed('events', 'timezone', function ($entry, $value) {
Collection::computed($collectionHandle, 'timezone', function ($entry, $value) use ($collectionHandle) {
if ($value) {
return $value;
}

$timezone = config('events.timezone', config('app.timezone'));
$timezone = config('events.timezone');

$collection = Collection::findByHandle(config('events.collection', 'events'));
$collection = Collection::findByHandle($collectionHandle);

$blueprint = Arr::first($collection->entryBlueprints());

Expand Down
4 changes: 2 additions & 2 deletions src/Tags/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function downloadLink(): string
return route(
'statamic.events.ics.show',
Arr::removeNullValues([
'collection' => $this->params->get('collection', 'events'),
'collection' => $this->params->get('collection', config('events.collection')),
'date' => $this->params->has('date') ? Carbon::parse($this->params->get('date'))->toDateString() : null,
'event' => $this->params->get('event'),
])
Expand Down Expand Up @@ -129,7 +129,7 @@ private function generator(): Generator
{
$generator = $this->params->has('event') ?
Generator::fromEntry($this->params->get('event')) :
Generator::fromCollection($this->params->get('collection', 'events'));
Generator::fromCollection($this->params->get('collection', config('events.collection')));

return $generator
->site($this->params->get('site'))
Expand Down

0 comments on commit 42ea932

Please sign in to comment.