Anliegen, Feldkatalog, Feldgruppen, Anfragevorlagen mit Fassungen, Anfrage-Einstiege, Posteingang mit Status und Notizen, Einstellungen mit Empfängern. Das Widget speichert nur die Kennung eines veröffentlichten Einstiegs; Formular, Bedingungen und Annahme kommen zur Laufzeit vom Server (Kompaktformular und mehrstufiger Dialog aus derselben Beschreibung). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
67 lines
2.2 KiB
PHP
67 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Support;
|
|
|
|
use Filament\Actions\Action;
|
|
use Filament\Notifications\Notification;
|
|
|
|
/**
|
|
* Archivieren und Wiederherstellen statt Löschen für die Konfigurationsbereiche der Kommunikationsverwaltung. Die
|
|
* Seite liefert archiveNote() (Wirkung), archiveBlocked() (Hinderungsgrund oder null) und indexUrl().
|
|
*/
|
|
trait ArchivesCommunicationRecords
|
|
{
|
|
abstract protected function archiveNote(): string;
|
|
|
|
abstract protected function indexUrl(): string;
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function archiveAttributes(): array
|
|
{
|
|
return ['archived_at' => now(), 'active' => false];
|
|
}
|
|
|
|
/** Grund, warum das Archivieren gerade nicht möglich ist; null: möglich. */
|
|
protected function archiveBlocked(): ?string
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return list<Action>
|
|
*/
|
|
protected function archiveActions(): array
|
|
{
|
|
return [
|
|
Action::make('archive')
|
|
->label('Archivieren')
|
|
->color('gray')
|
|
->visible(fn (): bool => $this->getRecord()->archived_at === null)
|
|
->requiresConfirmation()
|
|
->modalDescription(fn (): string => $this->archiveNote())
|
|
->action(function (): void {
|
|
if (($reason = $this->archiveBlocked()) !== null) {
|
|
Notification::make()->title($reason)->danger()->send();
|
|
|
|
return;
|
|
}
|
|
|
|
$this->getRecord()->forceFill($this->archiveAttributes())->save();
|
|
Notification::make()->title('Archiviert.')->success()->send();
|
|
$this->redirect($this->indexUrl());
|
|
}),
|
|
Action::make('restore')
|
|
->label('Wiederherstellen')
|
|
->color('gray')
|
|
->visible(fn (): bool => $this->getRecord()->archived_at !== null)
|
|
->action(function (): void {
|
|
$this->getRecord()->forceFill(['archived_at' => null])->save();
|
|
Notification::make()->title('Wiederhergestellt.')->success()->send();
|
|
$this->redirect($this->indexUrl());
|
|
}),
|
|
];
|
|
}
|
|
}
|