From 351301c2a8a4b080b3342fa74f9b025b79df435b Mon Sep 17 00:00:00 2001 From: stuartcusackie Date: Thu, 18 Aug 2022 16:58:22 +0100 Subject: [PATCH] Handle multisite entries. --- src/ServiceProvider.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 36e8206..faecdc8 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -29,13 +29,26 @@ protected function registerServices() } /** - * Extract the Statamic template data for the - * current entry and pass it to our singleton. + * Process the view data that has been set up + * by Statamic. This is very convoluted but + * it's efficient! */ protected function registerViewComposers() { // Append slash to path if necessary $path = substr(request()->path(), 0, 1) == '/' ? request()->path() : '/' . request()->path(); + + // Remove multisite url prefixes if necessary (we can't find entries by uri when they are prefixed) + foreach(\Statamic\Facades\Site::all() as $site) { + + $sitePrefix = str_replace(request()->root(), '', $site->url); + + if(strlen($sitePrefix) && str_starts_with($path, $sitePrefix)) { + $path = substr($path, strlen($sitePrefix)); + } + + } + $template = null; if($entry = Entry::findByUri($path)) {