-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract missing image alt widget to addon
- Loading branch information
1 parent
1724e29
commit b915263
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Studio1902\PeakSeo\Widgets; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Support\Facades\Cache; | ||
use Statamic\Facades\Asset; | ||
use Statamic\Facades\AssetContainer; | ||
use Statamic\Widgets\Widget; | ||
|
||
class ImagesMissingAlt extends Widget | ||
{ | ||
/** | ||
* The HTML that should be shown in the widget. | ||
* | ||
* @return string|\Illuminate\View\View | ||
*/ | ||
public function html() | ||
{ | ||
$expiration = Carbon::now()->addMinutes($this->config('expiry', 0)); | ||
|
||
$assets = Cache::remember('widgets::ImagesMissingAlt', $expiration, function() { | ||
return Asset::query() | ||
->where('container', $this->config('container', 'assets')) | ||
->whereNull('alt') | ||
->whereIn('extension', $this->config('filetypes', ['jpg', 'jpeg', 'png', 'gif', 'webp', 'avif', 'bmp', 'tiff', 'svg'])) | ||
->orderBy('last_modified', 'desc') | ||
->limit(100) | ||
->get() | ||
->toAugmentedArray(); | ||
}); | ||
|
||
$assets = collect($assets); | ||
|
||
return view('statamic-peak-seo::widgets.images-missing-alt', [ | ||
'assets' => $assets->slice(0, $this->config('limit', 5)), | ||
'amount' => count($assets), | ||
'container' => AssetContainer::findByHandle($this->config('container', 'assets'))->title(), | ||
]); | ||
} | ||
} |