55use Composer \InstalledVersions ;
66use Illuminate \Support \Carbon ;
77use Illuminate \Support \Facades \Artisan ;
8+ use Statamic \Entries \Entry ;
89use Statamic \Facades \Collection ;
910use Statamic \Facades \Site ;
1011use Statamic \Fields \Field ;
12+ use Statamic \Fields \Value ;
1113use Statamic \Providers \AddonServiceProvider ;
1214use Statamic \Statamic ;
1315use TransformStudios \Events \Fieldtypes \Timezones ;
1416use TransformStudios \Events \Modifiers \InMonth ;
1517use TransformStudios \Events \Modifiers \IsEndOfWeek ;
1618use TransformStudios \Events \Modifiers \IsStartOfWeek ;
17- use TransformStudios \Events \Tags \Events ;
19+ use TransformStudios \Events \Tags \Events as EventsTag ;
1820
1921class ServiceProvider extends AddonServiceProvider
2022{
@@ -33,7 +35,7 @@ class ServiceProvider extends AddonServiceProvider
3335 ];
3436
3537 protected $ tags = [
36- Events ::class,
38+ EventsTag ::class,
3739 ];
3840
3941 public function bootAddon ()
@@ -72,23 +74,18 @@ private function bootCarbon(): self
7274
7375 private function bootFields (): self
7476 {
75- Collection::computed (config ('events.collection ' , 'events ' ), 'timezone ' , function ($ entry , $ value ) {
76- $ value ??= config ('events.timezone ' , config ('app.timezone ' ));
77-
78- if ($ entry ->blueprint ()->fields ()->get ('timezone ' )?->fieldtype() instanceof Timezones) {
79- return $ value ;
80- }
81-
82- return (new Field ('timezone ' , ['type ' => 'timezones ' , 'max_items ' => 1 ]))
83- ->setValue ($ value )
84- ->setParent ($ entry )
85- ->augment ()
86- ->value ();
87- });
77+ collect (Events::setting ('collections ' , [['collection ' => 'events ' ]]))
78+ ->each (fn (array $ collection ) => $ this
79+ ->defineComputedTimezoneField ($ collection ['collection ' ]));
8880
8981 return $ this ;
9082 }
9183
84+ private function defineComputedTimezoneField (string $ handle ): void
85+ {
86+ Collection::computed ($ handle , 'timezone ' , $ this ->timezone (...));
87+ }
88+
9289 private function publishConfig (): self
9390 {
9491 Statamic::afterInstalled (function ($ command ) {
@@ -97,4 +94,19 @@ private function publishConfig(): self
9794
9895 return $ this ;
9996 }
97+
98+ private function timezone (Entry $ entry , $ value ): string |Value
99+ {
100+ $ value ??= Events::timezone ();
101+
102+ if ($ entry ->blueprint ()->fields ()->get ('timezone ' )?->fieldtype() instanceof Timezones) {
103+ return $ value ;
104+ }
105+
106+ return (new Field ('timezone ' , ['type ' => 'timezones ' , 'max_items ' => 1 ]))
107+ ->setValue ($ value )
108+ ->setParent ($ entry )
109+ ->augment ()
110+ ->value ();
111+ }
100112}
0 commit comments