|
2 | 2 |
|
3 | 3 | namespace TransformStudios\Events; |
4 | 4 |
|
5 | | -use Statamic\Entries\Entry; |
6 | 5 | use Statamic\Facades\Collection; |
7 | | -use Statamic\Fields\Field; |
8 | | -use Statamic\Fields\Fields; |
9 | | -use Statamic\Fields\Value; |
10 | | -use Statamic\Fieldtypes\Dictionary; |
| 6 | +use Statamic\Facades\Field; |
11 | 7 | use Statamic\Providers\AddonServiceProvider; |
12 | 8 | use Statamic\Statamic; |
13 | 9 |
|
14 | 10 | class ServiceProvider extends AddonServiceProvider |
15 | 11 | { |
16 | 12 | public function bootAddon() |
17 | 13 | { |
18 | | - // Fields::default('events_timezone', fn () => Statamic::displayTimezone()); |
19 | | - collect(Events::setting('collections', [['collection' => 'events']])) |
20 | | - ->each(fn (array $collection) => Collection::computed( |
21 | | - $collection['collection'], |
22 | | - 'timezone', |
23 | | - $this->timezone(...) |
24 | | - )); |
25 | | - } |
26 | | - |
27 | | - private function timezone(Entry $entry, $value): string|Value |
28 | | - { |
29 | | - $value ??= Events::defaultTimezone(); |
30 | | - |
31 | | - if ($entry->blueprint()->fields()->get('timezone')?->fieldtype() instanceof Dictionary) { |
32 | | - return $value; |
33 | | - } |
| 14 | + Field::computedDefault('default-events-timezone', fn () => Statamic::displayTimezone()); |
| 15 | + Field::computedDefault('default-event-timezone', fn () => Events::defaultTimezone()); |
34 | 16 |
|
35 | | - return (new Field('timezone', ['type' => 'timezones', 'max_items' => 1])) |
36 | | - ->setValue($value) |
37 | | - ->setParent($entry) |
38 | | - ->augment() |
39 | | - ->value(); |
| 17 | + collect(Events::setting('collections', ['events'])) |
| 18 | + ->each(function (string $collection) { |
| 19 | + Collection::findByHandle($collection)->entryBlueprint()->ensureField( |
| 20 | + 'timezone', |
| 21 | + [ |
| 22 | + 'dictionary' => 'timezones', |
| 23 | + 'max_items' => '1', |
| 24 | + 'type' => 'dictionary', |
| 25 | + 'default' => 'computed:default-event-timezone', |
| 26 | + ]); |
| 27 | + }); |
40 | 28 | } |
41 | 29 | } |
0 commit comments