Skip to content

Commit f3c643b

Browse files
authored
[5.x] Make GetItemsContainingData hookable (#13302)
1 parent e763dd4 commit f3c643b

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/Listeners/Concerns/GetsItemsContainingData.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
use Statamic\Facades\GlobalSet;
88
use Statamic\Facades\Term;
99
use Statamic\Facades\User;
10+
use Statamic\Support\Traits\Hookable;
1011

1112
trait 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) {

tests/Listeners/UpdateAssetReferencesTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
use Illuminate\Support\Facades\Cache;
66
use Illuminate\Support\Facades\Storage;
7+
use Illuminate\Support\LazyCollection;
78
use Orchestra\Testbench\Attributes\DefineEnvironment;
89
use PHPUnit\Framework\Attributes\Test;
910
use Statamic\Assets\AssetFolder;
1011
use Statamic\Facades;
12+
use Statamic\Listeners\UpdateAssetReferences;
1113
use Statamic\Support\Arr;
1214
use Tests\PreventSavingStacheItemsToDisk;
1315
use 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();

0 commit comments

Comments
 (0)