Files
laraundfelix/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php
T
LarsandCursor d6ff881e4e
Deploy Test / test (push) Successful in 18s
Deploy Test / deploy (push) Successful in 22s
Mache die Inhaltsverwaltung fuer die Redaktion bedienbar
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 08:59:30 +01:00

62 lines
2.4 KiB
PHP

<?php
namespace App\Filament\Resources\Compositions\Pages;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\EditorialContentKind;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Support\Htmlable;
abstract class ListCompositionKind extends ListRecords
{
use ReportsDomainRules;
abstract protected function kind(): CompositionKind;
public function getSubheading(): string|Htmlable|null
{
return $this->kind()->explanation();
}
protected function getHeaderActions(): array
{
return [
Action::make('create')
->label(match ($this->kind()) {
CompositionKind::Kurs => 'Programm anlegen',
CompositionKind::Uebung => 'Modul anlegen',
default => $this->kind()->createLabel(),
})
->visible(fn (): bool => ContentElementResource::editor())
->schema([
TextInput::make('designation')->label('Bezeichnung')->required(),
])
->action(function (array $data): void {
$composition = null;
$this->report(function () use ($data, &$composition): void {
$composition = app(ContentService::class)->createComposition($data['designation'], $this->kind());
$slug = match ($this->kind()) {
CompositionKind::Kurs => 'programm',
CompositionKind::Uebung => 'modul',
default => null,
};
$editorial = $slug === null ? null : EditorialContentKind::query()->where('slug', $slug)->first();
if ($editorial !== null) {
$composition->editorial_content_kind_id = $editorial->id;
$composition->save();
}
}, $this->kind()->label().' ist angelegt.');
if ($composition !== null) {
$this->redirect(static::getResource()::getUrl('edit', ['record' => $composition]));
}
}),
];
}
}