Skip to content

Commit d5329e6

Browse files
Fix view composer logic again.
1 parent a88d08b commit d5329e6

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/ServiceProvider.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,21 @@ protected function registerServices()
3636
*/
3737
protected function registerViewComposers()
3838
{
39-
// Append slash to path if necessary
40-
$path = substr(request()->path(), 0, 1) == '/' ? request()->path() : '/' . request()->path();
41-
42-
// Remove multisite url prefixes if necessary (we can't find entries by uri when they are prefixed)
43-
foreach(\Statamic\Facades\Site::all() as $site) {
44-
45-
if(strlen($site->url) > 1 && str_starts_with($path, $site->url)) {
46-
$path = substr($path, strlen($sitePrefix));
47-
}
39+
$template = null;
40+
$uri = '/' . request()->path();
41+
$sitePrefix = \Statamic\Facades\Site::current()->url;
4842

43+
if(str_starts_with($uri, $sitePrefix)) {
44+
$uri = substr($uri, strlen($sitePrefix));
4945
}
5046

51-
$template = null;
52-
53-
if($entry = Entry::findByUri($path)) {
47+
// findByUri requires leading slashes
48+
$uri = str_starts_with($uri, '/') ? $uri : '/' . $uri;
49+
50+
if($entry = Entry::findByUri($uri)) {
5451
$template = $entry->template();
5552
}
56-
else if($term = Term::findByUri($path)) {
53+
else if($term = Term::findByUri($uri)) {
5754
$template = $term->template();
5855
}
5956

0 commit comments

Comments
 (0)