Skip to content

Commit

Permalink
Allow taxonomy show views to work automagically without mounting
Browse files Browse the repository at this point in the history
When the url matches the handle of the collection, everything will "just work".
  • Loading branch information
jackmcdade committed Dec 4, 2020
1 parent 05db1f3 commit 352772e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Stache/Repositories/TermRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Statamic\Contracts\Taxonomies\Term;
use Statamic\Contracts\Taxonomies\TermRepository as RepositoryContract;
use Statamic\Facades\Collection;
use Statamic\Facades\Site;
use Statamic\Facades\Taxonomy;
use Statamic\Stache\Query\TermQueryBuilder;
use Statamic\Stache\Stache;
Expand Down Expand Up @@ -45,13 +46,16 @@ public function find($id): ?Term
public function findByUri(string $uri, string $site = null): ?Term
{
$collection = Collection::all()
->filter->url()
->first(function ($collection) use ($uri) {
return Str::startsWith($uri, $collection->url());
if (Str::startsWith($uri, $collection->url())) {
return true;
}

return Site::hasMultiple() ? false : Str::startsWith($uri, '/'.$collection->handle());
});

if ($collection) {
$uri = Str::after($uri, $collection->url());
$uri = Str::after($uri, $collection->url() ?? $collection->handle());
}

$uri = Str::removeLeft($uri, '/');
Expand Down

0 comments on commit 352772e

Please sign in to comment.