22
33namespace Statamic \Http \Controllers \CP \Collections ;
44
5- use Illuminate \Support \Collection as SupportCollection ;
65use Statamic \Contracts \Entries \Collection ;
76use Statamic \Contracts \Query \Builder ;
87use Statamic \Facades \User ;
@@ -12,33 +11,35 @@ trait QueriesAuthorEntries
1211{
1312 protected function queryAuthorEntries (Builder $ query , Collection $ collection ): void
1413 {
15- $ blueprintsWithAuthor = $ this ->blueprintsWithAuthor ($ collection ->entryBlueprints ());
16- $ blueprintsWithoutAuthor = $ this ->blueprintsWithoutAuthor ($ collection ->entryBlueprints ());
14+ $ blueprintsWithAuthor = $ this ->blueprintsWithAuthor ($ collection );
1715
1816 if (empty ($ blueprintsWithAuthor )) {
1917 return ;
2018 }
2119
2220 $ query ->where (fn ($ query ) => $ query
23- ->whereNotIn ('collectionHandle ' , [$ collection ->handle ()]) // Needed for entries fieldtypes configured for multiple collections
21+ // Exclude entries from other collections (for entries fieldtypes with multiple collections)
22+ ->whereNotIn ('collectionHandle ' , [$ collection ->handle ()])
23+ // Include entries with blueprints where the current user is the author
2424 ->orWhere (fn ($ query ) => $ query
2525 ->whereIn ('blueprint ' , $ blueprintsWithAuthor )
26- ->whereHas ('author ' , fn ($ subquery ) => $ subquery ->where ('id ' , User::current ()->id ()))
26+ ->whereHas ('author ' , fn ($ query ) => $ query ->where ('id ' , User::current ()->id ()))
2727 )
28- ->orWhereIn ('blueprint ' , $ blueprintsWithoutAuthor )
28+ // Include entries with blueprints that don't have an author
29+ ->orWhereIn ('blueprint ' , $ this ->blueprintsWithoutAuthor ($ collection ))
2930 );
3031 }
3132
32- protected function blueprintsWithAuthor (SupportCollection $ blueprints ): array
33+ protected function blueprintsWithAuthor (Collection $ collection ): array
3334 {
34- return $ blueprints
35+ return $ collection -> entryBlueprints ()
3536 ->filter (fn (Blueprint $ blueprint ) => $ blueprint ->hasField ('author ' ))
3637 ->map ->handle ()->all ();
3738 }
3839
39- protected function blueprintsWithoutAuthor (SupportCollection $ blueprints ): array
40+ protected function blueprintsWithoutAuthor (Collection $ collection ): array
4041 {
41- return $ blueprints
42+ return $ collection -> entryBlueprints ()
4243 ->filter (fn (Blueprint $ blueprint ) => ! $ blueprint ->hasField ('author ' ))
4344 ->map ->handle ()->all ();
4445 }
0 commit comments