Dieselbe Liste trägt die öffentliche Seite. Medien bleiben privat, Seiten können mehreren Säulen zugeordnet sein. Co-authored-by: Cursor <cursoragent@cursor.com>
73 lines
2.2 KiB
PHP
73 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Pillars\Pages;
|
|
|
|
use App\Domain\Catalog\DomainRuleException;
|
|
use App\Domain\Catalog\Pillar;
|
|
use App\Domain\Catalog\PillarService;
|
|
use App\Filament\Resources\Pillars\PillarResource;
|
|
use App\Filament\Support\ReportsDomainRules;
|
|
use Filament\Actions\Action;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
use Filament\Support\Exceptions\Halt;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class EditPillar extends EditRecord
|
|
{
|
|
use ReportsDomainRules;
|
|
|
|
protected static string $resource = PillarResource::class;
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('delete')
|
|
->label('Löschen')
|
|
->color('danger')
|
|
->requiresConfirmation()
|
|
->action(function (): void {
|
|
/** @var Pillar $pillar */
|
|
$pillar = $this->getRecord();
|
|
$deleted = false;
|
|
$this->report(function () use ($pillar, &$deleted): void {
|
|
app(PillarService::class)->delete($pillar);
|
|
$deleted = true;
|
|
}, 'Die Säule ist gelöscht.');
|
|
|
|
if ($deleted) {
|
|
$this->redirect(PillarResource::getUrl('index'));
|
|
}
|
|
}),
|
|
];
|
|
}
|
|
|
|
protected function mutateFormDataBeforeFill(array $data): array
|
|
{
|
|
$data['published'] = $this->getRecord()->published_at !== null;
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function handleRecordUpdate(Model $record, array $data): Model
|
|
{
|
|
/** @var Pillar $record */
|
|
try {
|
|
app(PillarService::class)->present(
|
|
$record,
|
|
(string) $data['name'],
|
|
(string) ($data['slug'] ?? ''),
|
|
$data['public_summary'] ?? null,
|
|
(bool) ($data['published'] ?? false),
|
|
(int) ($data['sort_order'] ?? 0),
|
|
);
|
|
} catch (DomainRuleException $exception) {
|
|
Notification::make()->title($exception->getMessage())->danger()->send();
|
|
|
|
throw new Halt;
|
|
}
|
|
|
|
return $record;
|
|
}
|
|
}
|