Loheide-eu-mitarbeiterplatt.../app/Filament/Pages/QuickLinksSettings.php
Friederich Loheide a618927a52
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m7s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m30s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 8m6s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 8m21s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 17m13s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 17m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m52s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 9m29s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m23s
Schnellzugriffe mit Logo, Kategorien und Sichtbar für (0.51.0)
Untertitel, Logo, Kategorie, Rollen und Anheften je Eintrag; Knopf
„Anwendungen“ in der Kopfzeile mit allen sichtbaren Einträgen.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-29 18:44:53 +00:00

140 lines
6.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Filament\Pages;
use App\Filament\Clusters\HomepageCluster;
use App\Filament\Components\SafeUpload;
use App\Models\Role;
use App\Support\Icons;
use App\Support\QuickLinks;
use App\Support\Settings;
use BackedEnum;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
class QuickLinksSettings extends Page
{
protected string $view = 'filament.pages.settings-form';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedSquares2x2;
protected static ?int $navigationSort = 2;
protected static ?string $cluster = HomepageCluster::class;
protected static ?string $navigationLabel = 'Schnellzugriffe';
protected static ?string $title = 'Schnellzugriffe';
public static function canAccess(): bool
{
return auth()->user()?->can('appearance.manage') ?? false;
}
protected static ?string $slug = 'schnellzugriffe';
/** @var array<string, mixed>|null */
public ?array $data = [];
public function mount(QuickLinks $quickLinks): void
{
$this->form->fill(['links' => $quickLinks->all()]);
}
public function form(Schema $schema): Schema
{
return $schema
->components([
Section::make('Schnellzugriffe')
->description('Anwendungen und Seiten, die viele täglich brauchen – z. B. Dienstplan, Dokumentation oder Archiv. Angeheftete stehen auf der Startseite, alle zusammen unter „Anwendungen“ in der Kopfzeile. Die Reihenfolge lässt sich per Ziehen ändern.')
->schema([
Repeater::make('links')
->hiddenLabel()
->columns(4)
->reorderable()
->collapsible()
->collapsed(fn (array $state) => count($state) > 6)
->itemLabel(fn (array $state) => trim(($state['label'] ?? '').(($state['pinned'] ?? false) ? ' · angeheftet' : '').(filled($state['roles'] ?? null) ? ' · eingeschränkt' : '')) ?: null)
->addActionLabel('Schnellzugriff hinzufügen')
->maxItems(60)
->schema([
TextInput::make('label')
->label('Bezeichnung')
->required()
->maxLength(40),
TextInput::make('subtitle')
->label('Untertitel')
->placeholder('z. B. Dienstplan')
->helperText('Hilft, wenn der Name allein nicht sagt, wofür es ist.')
->maxLength(60),
TextInput::make('url')
->label('Adresse')
->placeholder('https://… oder /personen')
->required()
->maxLength(500)
->regex('#^(https?://|/)#i')
->validationMessages(['regex' => 'Bitte eine Adresse angeben, die mit https://, http:// oder / beginnt.'])
->columnSpan(2),
Select::make('icon')
->label('Symbol')
->options(Icons::options())
->allowHtml()
->searchable()
->getSearchResultsUsing(fn (string $search) => Icons::search($search))
->getOptionLabelUsing(fn (?string $value) => $value ? Icons::option($value) : null)
->helperText('Wird gezeigt, wenn kein Logo hochgeladen ist.')
->default('link')
->required(),
SafeUpload::apply(FileUpload::make('logo'), [...SafeUpload::IMAGES, 'image/svg+xml'])
->label('Logo')
->helperText('Optional, quadratisch am besten (PNG, SVG, WebP).')
->disk('uploads')->directory('quick-links')->visibility('public')
->image()->maxSize(1024),
TextInput::make('category')
->label('Kategorie')
->placeholder('z. B. Pflege, Verwaltung')
->helperText('Ordnet die Liste unter „Anwendungen“.')
->datalist(fn () => collect(app(QuickLinks::class)->all())->pluck('category')->filter()->unique()->values()->all())
->maxLength(40),
Select::make('roles')
->label('Sichtbar für')
->multiple()
->options(fn () => Role::query()->orderBy('name')->pluck('name', 'id')->all())
->placeholder('Alle')
->helperText('Leer = alle. Sonst nur Personen mit einer dieser Rollen.'),
Toggle::make('pinned')
->label('Auf der Startseite anheften')
->helperText('Ohne angeheftete Einträge stehen alle auf der Startseite.')
->columnSpan(2),
Toggle::make('new_tab')
->label('In neuem Tab öffnen')
->columnSpan(2),
]),
]),
])
->statePath('data');
}
public function save(Settings $settings): void
{
$links = array_values(array_map(fn (array $link) => [
...$link,
'roles' => array_values(array_map('intval', (array) ($link['roles'] ?? []))),
], $this->form->getState()['links'] ?? []));
$settings->set('portal.quick_links', $links);
Notification::make()
->success()
->title('Schnellzugriffe gespeichert')
->send();
}
}