Skip to content

Commit

Permalink
Assets and terms
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Dec 2, 2024
1 parent 4a82284 commit 1ab9585
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Fieldtypes/Assets/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Statamic\Fields\Fieldtype;
use Statamic\GraphQL\Types\AssetInterface;
use Statamic\Http\Resources\CP\Assets\Asset as AssetResource;
use Statamic\Query\EmptyQueryBuilder;
use Statamic\Query\Scopes\Filter;
use Statamic\Support\Arr;
use Statamic\Support\Str;
Expand Down Expand Up @@ -257,13 +258,17 @@ public function augment($values)
return Blink::get($key);
}

$ids = collect($values)
->map(fn ($value) => $this->container()->handle().'::'.$value)
->all();
if (! $values) {
$query = new EmptyQueryBuilder();
} else {
$ids = collect($values)
->map(fn ($value) => $this->container()->handle().'::'.$value)
->all();

$query = $this->container()->queryAssets()->whereIn('path', $values);
$query = $this->container()->queryAssets()->whereIn('path', $values);

$query = new OrderedQueryBuilder($query, $ids);
$query = new OrderedQueryBuilder($query, $ids);
}

return $single && ! config('statamic.system.always_augment_to_query', false)
? Blink::once($key, fn () => $query->first())
Expand Down
5 changes: 5 additions & 0 deletions src/Fieldtypes/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Statamic\Facades\User;
use Statamic\GraphQL\Types\TermInterface;
use Statamic\Http\Resources\CP\Taxonomies\TermsFieldtypeTerms as TermsResource;
use Statamic\Query\EmptyQueryBuilder;
use Statamic\Query\OrderedQueryBuilder;
use Statamic\Query\Scopes\Filter;
use Statamic\Query\Scopes\Filters\Fields\Terms as TermsFilter;
Expand Down Expand Up @@ -130,6 +131,10 @@ public function augment($values)

private function queryBuilder($values)
{
if (! $values) {
return new EmptyQueryBuilder();
}

// The parent is the item this terms fieldtype exists on. Most commonly an
// entry, but could also be something else, like another taxonomy term.
$parent = $this->field->parent();
Expand Down

0 comments on commit 1ab9585

Please sign in to comment.