File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77use Statamic \Facades \GlobalSet ;
88use Statamic \Facades \Term ;
99use Statamic \Facades \User ;
10+ use Statamic \Support \Traits \Hookable ;
1011
1112trait GetsItemsContainingData
1213{
14+ use Hookable;
15+
1316 /**
1417 * Get items containing data.
1518 *
@@ -30,6 +33,9 @@ public function getItemsContainingData()
3033 LazyCollection::make (function () {
3134 yield from User::query ()->lazy ();
3235 }),
36+ LazyCollection::make (function () {
37+ yield from ($ this ->runHooks ('additional ' ) ?? LazyCollection::make ());
38+ }),
3339 ];
3440
3541 return LazyCollection::make (function () use ($ collections ) {
Original file line number Diff line number Diff line change 44
55use Illuminate \Support \Facades \Cache ;
66use Illuminate \Support \Facades \Storage ;
7+ use Illuminate \Support \LazyCollection ;
78use Orchestra \Testbench \Attributes \DefineEnvironment ;
89use PHPUnit \Framework \Attributes \Test ;
910use Statamic \Assets \AssetFolder ;
1011use Statamic \Facades ;
12+ use Statamic \Listeners \UpdateAssetReferences ;
1113use Statamic \Support \Arr ;
1214use Tests \PreventSavingStacheItemsToDisk ;
1315use Tests \TestCase ;
@@ -1852,6 +1854,19 @@ public function it_only_saves_items_when_there_is_something_to_update()
18521854 $ this ->assetHoff ->path ('hoff-new.jpg ' )->save ();
18531855 }
18541856
1857+ #[Test]
1858+ public function it_gets_items_from_a_hook ()
1859+ {
1860+ UpdateAssetReferences::hook ('additional ' , function () {
1861+ return LazyCollection::make (['additional-1 ' , 'additional-2 ' ]);
1862+ });
1863+
1864+ $ items = ((new UpdateAssetReferences )->getItemsContainingData ())->all ();
1865+
1866+ $ this ->assertContains ('additional-1 ' , $ items );
1867+ $ this ->assertContains ('additional-2 ' , $ items );
1868+ }
1869+
18551870 protected function setSingleBlueprint ($ namespace , $ blueprintContents )
18561871 {
18571872 $ blueprint = tap (Facades \Blueprint::make ('single-blueprint ' )->setContents ($ blueprintContents ))->save ();
You can’t perform that action at this time.
0 commit comments