Skip to content

Commit

Permalink
Move globals to getGlobals function instead of constructor (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG authored May 2, 2024
1 parent a890d43 commit 1f4ba6b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Http/ViewComposers/StatamicGlobalDataComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@

class StatamicGlobalDataComposer
{
private $globals;

public function __construct()
public function getGlobals()
{
$this->globals = Cache::rememberForever('statamic-globals-'.Site::current()->handle(), function() {
return Cache::rememberForever('statamic-globals-'.Site::current()->handle(), function() {
$data = [];

foreach (GlobalSet::all() as $set) {
foreach ($set->localizations() as $locale => $variables) {
if ($locale == Site::current()->handle()) {
$data[$set->handle()] = $variables;
}
}
}
return ($data ?? []);

return $data;
});
}

public function compose(View $view) : View
{
if(!isset($view->globals)) {
$view->with('globals', optionalDeep((object)$this->globals));
$view->with('globals', optionalDeep((object)$this->getGlobals()));
}

return $view;
Expand Down

0 comments on commit 1f4ba6b

Please sign in to comment.