label('Medium anlegen') ->visible(fn (): bool => ContentElementResource::editor()) ->schema([ TextInput::make('working_title')->label('Titel')->required(), Select::make('shape')->label('Was ist das?')->options([ 'film' => 'Film', 'audio' => 'Hörstück', 'bild' => 'Bild', 'document' => 'Dokument', 'text' => 'Text', ])->required()->live(), Textarea::make('body')->label('Text')->visible(fn ($get): bool => $get('shape') === 'text'), EditContentElement::uploadField()->visible(fn ($get): bool => $get('shape') !== 'text'), TextInput::make('change_note')->label('Notiz zur ersten Fassung'), ]) ->action(function (array $data): void { $element = null; $this->report(function () use ($data, &$element): void { $service = app(ContentService::class); [$kind, $output] = match ($data['shape']) { 'audio' => ['audio', 'audio'], 'bild' => ['bild', 'bild'], 'document' => ['dokument', 'document'], 'text' => ['text', 'text'], default => ['film', 'film'], }; $element = $service->createElement($kind, $output, $data['working_title']); $metadata = []; $incoming = IncomingFile::store($data['incoming'] ?? null); if (is_string($incoming) && $incoming !== '') { $metadata['incoming'] = $incoming; } if (is_numeric($data['decision_seconds'] ?? null)) { $metadata['decision_seconds'] = (int) $data['decision_seconds']; } $body = $data['body'] ?? null; if ((is_string($body) && $body !== '') || $metadata !== []) { $service->publishElementVersion($element, is_string($body) ? $body : null, $metadata, $data['change_note'] ?? null); } }, 'Das Medium ist angelegt.'); if ($element !== null) { $this->redirect(ContentElementResource::getUrl('view', ['record' => $element])); } }), ]; } }