Skip to content

Commit

Permalink
Globals support (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobWez98 authored Aug 10, 2022
1 parent 8a1ee44 commit 3000b90
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions routes/fallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

if ($entry = Data::findByRequestUrl(request()->url())) {
if (View::exists($entry->get('template'))) {
echo view($entry->get('template'), $entry->data());
echo view($entry->get('template'), $entry);
} else if (View::exists(str($entry->structure()->handle())->singular()->toString())) {
echo view(str($entry->structure()->handle())->singular()->toString(), $entry->data());
echo view(str($entry->structure()->handle())->singular()->toString(), $entry);
}
}
28 changes: 28 additions & 0 deletions src/RapidezStatamicServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,39 @@

use Illuminate\Support\ServiceProvider;
use TorMorten\Eventy\Facades\Eventy;
use Statamic\Facades\GlobalSet;
use Illuminate\Support\Facades\View;
use Statamic\Facades\Site;

class RapidezStatamicServiceProvider extends ServiceProvider
{
public function boot()
{
$this->bootRoutes()
->bootGlobals();
}

public function bootRoutes() : self
{
Eventy::addFilter('routes', fn ($routes) => array_merge($routes ?: [], [__DIR__.'/../routes/fallback.php']));

return $this;
}

public function bootGlobals() : self
{
View::composer('rapidez::layouts.app', function ($view) {
foreach (GlobalSet::all() as $set) {
foreach ($set->localizations() as $locale => $variables) {
if ($locale == Site::current()->handle()) {
$data[$set->handle()] = $variables;
}
}
}

$view->with('globals', (object)$data);
});

return $this;
}
}

0 comments on commit 3000b90

Please sign in to comment.