Skip to content

Commit

Permalink
Handle multisite entries.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcusackie committed Aug 18, 2022
1 parent 7d9e738 commit 351301c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 351301c

Please sign in to comment.