Skip to content

Commit

Permalink
Improved checking of images
Browse files Browse the repository at this point in the history
  • Loading branch information
martyf committed Oct 30, 2024
1 parent 6c3dee8 commit d3d1bd7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Listeners/ImagesWithoutAltListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,31 @@ class ImagesWithoutAltListener
{
public function handleSaving(AssetSaving $event)
{
if (!$this->hasImagesWithoutAltWidget()) {
return;
}

if ($event->asset->isDirty('alt')) {
Cache::forget(FuseUtilities::getImagesMissingAltCache());
}
}

public function handleChange(AssetDeleted|AssetUploaded $event)
{
if (!$this->hasImagesWithoutAltWidget()) {
return;
}

Cache::forget(FuseUtilities::getImagesMissingAltCache());
}

protected function hasImagesWithoutAltWidget() {
return collect(config('statamic.cp.widgets', []))->contains('type', 'images_without_alt');
}

public function subscribe(Dispatcher $events)
{
if (! collect(config('statamic.cp.widgets', []))->contains('type', 'images_missing_alt')) {
if (!$this->hasImagesWithoutAltWidget()) {
return;
}

Expand Down

0 comments on commit d3d1bd7

Please sign in to comment.