|
8 | 8 | use Illuminate\Support\Facades\Artisan; |
9 | 9 | use Statamic\Facades\Collection; |
10 | 10 | use Statamic\Facades\Site; |
| 11 | +use Statamic\Fields\Field; |
11 | 12 | use Statamic\Providers\AddonServiceProvider; |
12 | 13 | use Statamic\Statamic; |
13 | | -use Statamic\Support\Arr; |
14 | | -use TransformStudios\Events\Exceptions\FieldNotFoundException; |
15 | 14 | use TransformStudios\Events\Fieldtypes\Timezones; |
16 | 15 | use TransformStudios\Events\Modifiers\InMonth; |
17 | 16 | use TransformStudios\Events\Modifiers\IsEndOfWeek; |
@@ -81,27 +80,17 @@ private function bootCarbon(): self |
81 | 80 |
|
82 | 81 | private function bootFields(): self |
83 | 82 | { |
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')); |
85 | 85 |
|
86 | | - Collection::computed($collectionHandle, 'timezone', function ($entry, $value) use ($collectionHandle) { |
87 | | - if ($value) { |
| 86 | + if ($entry->blueprint()->fields()->get('timezone')?->fieldtype() instanceof Timezones) { |
88 | 87 | return $value; |
89 | 88 | } |
90 | 89 |
|
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) |
103 | 93 | ->augment() |
104 | | - ->value() |
105 | 94 | ->value(); |
106 | 95 | }); |
107 | 96 |
|
|
0 commit comments