Files
laraundfelix/app/Filament/Resources/ContentElements/Pages/ListContentElements.php
T
LarsandClaude Opus 5.5 f846c0b2ee
CI Feature / test (push) Successful in 1m0s
Deploy Test / test (push) Successful in 54s
Deploy Test / deploy (push) Successful in 23s
Zeige den Dialog „Medium anlegen“ in der Medienliste wieder an.
Filament gibt den Dialogbereich einer Listenseite über die Tabelle aus. Die
Medienliste ersetzt die Tabelle durch die eigene Kachel-/Listenansicht; damit
fehlte der Bereich, „Medium anlegen“ wurde zwar geöffnet, aber nie
angezeigt. Die Ansicht gibt den Dialogbereich jetzt selbst aus. Der Knopf im
Dialog heißt „Medium anlegen“ statt „Absenden“.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 07:58:48 +01:00

199 lines
5.8 KiB
PHP

<?php
namespace App\Filament\Resources\ContentElements\Pages;
use App\Domain\Catalog\EditorialContentKind;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\MediaLibrary;
use App\Filament\Support\MediumForm;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Resources\Pages\ListRecords;
use Filament\Schemas\Components\RenderHook;
use Filament\Schemas\Components\View;
use Filament\Schemas\Schema;
use Filament\Support\Enums\Width;
use Filament\View\PanelsRenderHook;
use Illuminate\Contracts\Support\Htmlable;
use Livewire\Attributes\Url;
class ListContentElements extends ListRecords
{
use ReportsDomainRules;
protected static string $resource = ContentElementResource::class;
#[Url(as: 'suche', except: '')]
public string $suche = '';
#[Url(as: 'ansicht', except: 'kacheln')]
public string $ansicht = 'kacheln';
#[Url(as: 'art', except: '')]
public string $art = '';
#[Url(as: 'freigabe', except: '')]
public string $freigabe = '';
#[Url(as: 'entwurf', except: '')]
public string $entwurf = '';
#[Url(as: 'fassung', except: '')]
public string $fassung = '';
#[Url(as: 'nutzung', except: '')]
public string $nutzung = '';
#[Url(as: 'saeule', except: '')]
public string $saeule = '';
#[Url(as: 'inhaltsart', except: '')]
public string $inhaltsart = '';
#[Url(as: 'einordnung', except: '')]
public string $einordnung = '';
#[Url(as: 'verarbeitung', except: '')]
public string $verarbeitung = '';
#[Url(as: 'archiv', except: 'aktiv')]
public string $archiv = 'aktiv';
public function getSubheading(): string|Htmlable|null
{
return 'Die Dateien und Texte. Ein Modul oder ein Programm verweist auf eine Fassung; die Datei wird nicht für jede Verwendung neu hochgeladen.';
}
public function getMaxContentWidth(): Width|string|null
{
return Width::Full;
}
public function content(Schema $schema): Schema
{
return $schema->components([
$this->getTabsContentComponent(),
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_BEFORE),
View::make('filament.media.library'),
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_AFTER),
]);
}
public function showingList(): bool
{
return $this->ansicht === 'liste';
}
/**
* @return list<array<string, mixed>>
*/
public function cards(): array
{
return app(MediaLibrary::class)->cards($this->libraryFilters(), ContentElementResource::editor());
}
/**
* @return list<array{value: string, label: string}>
*/
public function typeOptions(): array
{
return app(MediaLibrary::class)->types();
}
/**
* @return list<array{id: int, name: string}>
*/
public function pillarOptions(): array
{
return app(MediaLibrary::class)->pillars();
}
/**
* @return list<array{id: int, label: string}>
*/
public function classificationOptions(): array
{
return app(MediaLibrary::class)->classifications();
}
/**
* @return array<int, string>
*/
public function contentKindOptions(): array
{
return EditorialContentKind::selectOptions();
}
public function filtersActive(): bool
{
return trim($this->suche) !== ''
|| $this->art !== ''
|| $this->freigabe !== ''
|| $this->entwurf !== ''
|| $this->fassung !== ''
|| $this->nutzung !== ''
|| $this->saeule !== ''
|| $this->einordnung !== ''
|| $this->inhaltsart !== ''
|| $this->verarbeitung !== ''
|| $this->archiv !== 'aktiv';
}
public function resetFilters(): void
{
$this->suche = '';
$this->art = '';
$this->freigabe = '';
$this->entwurf = '';
$this->fassung = '';
$this->nutzung = '';
$this->saeule = '';
$this->einordnung = '';
$this->inhaltsart = '';
$this->verarbeitung = '';
$this->archiv = 'aktiv';
}
/**
* @return array<string, string>
*/
private function libraryFilters(): array
{
return [
'suche' => $this->suche,
'art' => $this->art,
'freigabe' => $this->freigabe,
'entwurf' => $this->entwurf,
'fassung' => $this->fassung,
'nutzung' => $this->nutzung,
'saeule' => $this->saeule,
'einordnung' => $this->einordnung,
'inhaltsart' => $this->inhaltsart,
'verarbeitung' => $this->verarbeitung,
'archiv' => $this->archiv,
];
}
protected function getHeaderActions(): array
{
return [
Action::make('create')
->label('Medium anlegen')
->modalSubmitActionLabel('Medium anlegen')
->visible(fn (): bool => ContentElementResource::editor())
->modalDescription('Dieselbe Maske gilt im Medienbestand, im Modul und im Programm. Der Upload zeigt seinen Fortschritt. Beschreibung, Hinweise und Vorschaubild gehören dazu.')
->schema(fn (): array => MediumForm::fields(creating: true))
->action(function (array $data): void {
$element = null;
$this->report(function () use ($data, &$element): void {
$element = MediumForm::create($data, hold: false);
}, 'Das Medium ist angelegt.');
if ($element !== null) {
$this->redirect(ContentElementResource::getUrl('view', ['record' => $element]));
}
}),
];
}
}