Skip to content

Commit

Permalink
If a collection was queried when getting terms, apply that collection…
Browse files Browse the repository at this point in the history
… to all of them.
  • Loading branch information
jasonvarga committed Dec 3, 2020
1 parent 6ade2a6 commit 175783d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Stache/Query/TermQueryBuilder.php
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Stache\Query;

use Statamic\Facades;
use Statamic\Facades\Collection;
use Statamic\Taxonomies\TermCollection;

class TermQueryBuilder extends Builder
Expand Down Expand Up @@ -128,4 +129,18 @@ protected function getOrderKeyValuesByIndex()
return $carry;
}, collect());
}

public function get($columns = ['*'])
{
$items = parent::get($columns);

// If a single collection has been queried, we'll supply it to the terms so
// things like URLs will be scoped to the collection. We can't do it when
// multiple collections are queried because it would be ambiguous.
if ($this->collections && count($this->collections) == 1) {
$items->each->collection(Collection::findByHandle($this->collections[0]));
}

return $items;
}
}

0 comments on commit 175783d

Please sign in to comment.