Skip to content

Commit

Permalink
Fix view composer logic again.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcusackie authored Sep 3, 2022
1 parent a88d08b commit d5329e6
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,21 @@ protected function registerServices()
*/
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) {

if(strlen($site->url) > 1 && str_starts_with($path, $site->url)) {
$path = substr($path, strlen($sitePrefix));
}
$template = null;
$uri = '/' . request()->path();
$sitePrefix = \Statamic\Facades\Site::current()->url;

if(str_starts_with($uri, $sitePrefix)) {
$uri = substr($uri, strlen($sitePrefix));
}

$template = null;

if($entry = Entry::findByUri($path)) {
// findByUri requires leading slashes
$uri = str_starts_with($uri, '/') ? $uri : '/' . $uri;

if($entry = Entry::findByUri($uri)) {
$template = $entry->template();
}
else if($term = Term::findByUri($path)) {
else if($term = Term::findByUri($uri)) {
$template = $term->template();
}

Expand Down

0 comments on commit d5329e6

Please sign in to comment.