Skip to content

Commit 43e0da6

Browse files
aerniedalzell
andauthored
Timezone field not required in blueprint (#121)
Co-authored-by: Erin Dalzell <erin@silentz.co>
1 parent c754ed4 commit 43e0da6

2 files changed

Lines changed: 7 additions & 33 deletions

File tree

src/Exceptions/FieldNotFoundException.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/ServiceProvider.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
use Illuminate\Support\Facades\Artisan;
99
use Statamic\Facades\Collection;
1010
use Statamic\Facades\Site;
11+
use Statamic\Fields\Field;
1112
use Statamic\Providers\AddonServiceProvider;
1213
use Statamic\Statamic;
13-
use Statamic\Support\Arr;
14-
use TransformStudios\Events\Exceptions\FieldNotFoundException;
1514
use TransformStudios\Events\Fieldtypes\Timezones;
1615
use TransformStudios\Events\Modifiers\InMonth;
1716
use TransformStudios\Events\Modifiers\IsEndOfWeek;
@@ -81,27 +80,17 @@ private function bootCarbon(): self
8180

8281
private function bootFields(): self
8382
{
84-
$collectionHandle = config('events.collection', 'events');
83+
Collection::computed(config('events.collection', 'events'), 'timezone', function ($entry, $value) {
84+
$value ??= config('events.timezone', config('app.timezone'));
8585

86-
Collection::computed($collectionHandle, 'timezone', function ($entry, $value) use ($collectionHandle) {
87-
if ($value) {
86+
if ($entry->blueprint()->fields()->get('timezone')?->fieldtype() instanceof Timezones) {
8887
return $value;
8988
}
9089

91-
$timezone = config('events.timezone', config('app.timezone'));
92-
93-
$collection = Collection::findByHandle($collectionHandle);
94-
95-
$blueprint = Arr::first($collection->entryBlueprints());
96-
97-
if (is_null($tzField = $blueprint->field('timezone'))) {
98-
throw new FieldNotFoundException('timezone');
99-
}
100-
101-
return $tzField
102-
->setValue($timezone)
90+
return (new Field('timezone', ['type' => 'timezones', 'max_items' => 1]))
91+
->setValue($value)
92+
->setParent($entry)
10393
->augment()
104-
->value()
10594
->value();
10695
});
10796

0 commit comments

Comments
 (0)