Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Listeners/Concerns/GetsItemsContainingData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
use Statamic\Facades\GlobalSet;
use Statamic\Facades\Term;
use Statamic\Facades\User;
use Statamic\Support\Traits\Hookable;

trait GetsItemsContainingData
{
use Hookable;

/**
* Get items containing data.
*
Expand All @@ -30,6 +33,9 @@ public function getItemsContainingData()
LazyCollection::make(function () {
yield from User::query()->lazy();
}),
LazyCollection::make(function () {
yield from ($this->runHooks('additional') ?? LazyCollection::make());
}),
];

return LazyCollection::make(function () use ($collections) {
Expand Down
15 changes: 15 additions & 0 deletions tests/Listeners/UpdateAssetReferencesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\LazyCollection;
use Orchestra\Testbench\Attributes\DefineEnvironment;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Assets\AssetFolder;
use Statamic\Facades;
use Statamic\Listeners\UpdateAssetReferences;
use Statamic\Support\Arr;
use Tests\PreventSavingStacheItemsToDisk;
use Tests\TestCase;
Expand Down Expand Up @@ -1852,6 +1854,19 @@ public function it_only_saves_items_when_there_is_something_to_update()
$this->assetHoff->path('hoff-new.jpg')->save();
}

#[Test]
public function it_gets_items_from_a_hook()
{
UpdateAssetReferences::hook('additional', function () {
return LazyCollection::make(['additional-1', 'additional-2']);
});

$items = ((new UpdateAssetReferences)->getItemsContainingData())->all();

$this->assertContains('additional-1', $items);
$this->assertContains('additional-2', $items);
}

protected function setSingleBlueprint($namespace, $blueprintContents)
{
$blueprint = tap(Facades\Blueprint::make('single-blueprint')->setContents($blueprintContents))->save();
Expand Down