Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Jan 5, 2024
1 parent b8ddd66 commit f0729c2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Fieldtypes/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,6 @@ protected function applyIndexQueryScopes($query, $params)
collect(Arr::wrap($this->config('query_scopes')))
->map(fn ($handle) => Scope::find($handle))
->filter()
->each(fn ($class) => app($class)->apply($query, $params));
->each(fn ($scope) => $scope->apply($query, $params));
}
}
2 changes: 1 addition & 1 deletion src/Http/Controllers/CP/Assets/BrowserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ protected function applyQueryScopes($query, $params)
collect(Arr::wrap($params['queryScopes'] ?? null))
->map(fn ($handle) => Scope::find($handle))
->filter()
->each(fn ($class) => app($class)->apply($query, $params));
->each(fn ($scope) => $scope->apply($query, $params));
}
}
22 changes: 18 additions & 4 deletions src/Query/Scopes/ScopeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,25 @@ public function all()

public function find($key, $context = [])
{
if ($scope = app('statamic.scopes')->get($key)) {
if (! in_array($scope->handle(), $this->removed)) {
return app($scope)?->context($context);
}
if (in_array($key, $this->removed)) {
return;
}

if (! $scope = app('statamic.scopes')->get($key)) {
return;
}

$scope = app($scope);

if (! $scope) {
return;
}

if (! method_exists($scope, 'context')) {
return $scope;
}

return $scope->context($context);
}

public function filters($key, $context = [])
Expand Down
3 changes: 1 addition & 2 deletions src/Tags/Concerns/QueriesScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public function queryScopes($query)
return Scope::find($handle);
})
->filter()
->each(function ($class) use ($query) {
$scope = app($class);
->each(function ($scope) use ($query) {
$scope->apply($query, $this->params);
});
}
Expand Down

0 comments on commit f0729c2

Please sign in to comment.