Files
landing-api/app/Filament/Support/PreviewAction.php
Josep Piguillem 3897113313 Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer
collective, backed by the Pireon OAuth identity server. The public site is a
separate, server-rendered application consuming /api/public/v1.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 17:55:27 +02:00

46 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Support;
use App\Support\PreviewLink;
use Filament\Actions\Action;
use Illuminate\Database\Eloquent\Model;
/**
* A button that produces a shareable link to a draft.
*
* The shared preview secret still works, but using it meant pasting a token
* into a curl command. This is a link somebody can send: scoped to one record
* and one language, and dead a few hours later.
*/
final class PreviewAction
{
public static function for(string $type): Action
{
return Action::make('preview')
->label(__('panel.preview.label'))
->icon('heroicon-o-eye')
->color('gray')
->modalHeading(__('panel.preview.heading'))
->modalDescription(__('panel.preview.hint', ['hours' => PreviewLink::HOURS]))
->modalSubmitAction(false)
// Nothing to preview without a public address to preview it at.
->visible(fn (Model $record) => filled(array_filter(
array_map(
fn (string $locale) => $record->getTranslation('slug', $locale, false),
array_keys((array) config('locales.supported')),
),
)))
->modalContent(fn (Model $record) => view('filament.partials.preview-links', [
'links' => collect(config('locales.supported'))
->mapWithKeys(fn (array $meta, string $locale) => [
($meta['native'] ?? $locale) => PreviewLink::for($record, $type, $locale),
])
->filter()
->all(),
]));
}
}