columns(1)->components([
Placeholder::make('open')->label('Medium')->content(function (): HtmlString {
$url = ContentElementResource::getUrl('view', ['record' => $this->getRecord()]);
return new HtmlString('Medium und Fassungen ansehen');
}),
TextInput::make('working_title')->label('Arbeitstitel')->required(),
TextInput::make('display_title')->label('Anzeigetitel')
->helperText('Erscheint in der Bibliothek. Leer lässt den Arbeitstitel stehen. Speichern legt keine Fassung an.'),
Textarea::make('summary')->label('Kurzbeschreibung')->rows(3),
Textarea::make('description')->label('Beschreibung')->rows(4)
->helperText('Gilt für das Medium, nicht für eine einzelne Fassung.'),
Select::make('editorial_content_kind_id')
->label('Inhaltsart')
->options(fn (): array => EditorialContentKind::selectOptions())
->nullable()
->helperText('Optional für Bibliothek und Website. Ändert weder die Ausgabeart noch eine Fassung.'),
CheckboxList::make('pillars')
->label('Fachliche Säulen')
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all())
->helperText('Ein Medium kann mehreren Säulen zugeordnet sein. Weitere Säulen legst du unter Fachliche Säulen an.')
->columns(1),
]);
}
public static function uploadField(): FileUpload
{
return FileUpload::make('incoming')
->label('Datei')
->disk('cms_incoming')
->directory('inhalte')
->visibility('private')
->maxSize(MediaUploadLimit::KILOBYTES)
->helperText('Film, Audio, Bild oder PDF bis 2 GB.');
}
protected function getHeaderActions(): array
{
return [
Action::make('view')
->label('Ansehen')
->url(fn (): string => ContentElementResource::getUrl('view', ['record' => $this->getRecord()])),
Action::make('revise')
->label('Neue Fassung anlegen')
->schema(fn (): array => ElementRevision::fields($this->getRecord()))
->action(function (array $data): void {
$this->report(function () use ($data): string {
/** @var ContentElement $element */
$element = $this->getRecord();
return ElementRevision::publish($element, $data);
}, 'Die neue Fassung ist angelegt.');
$this->getRecord()->unsetRelation('versions');
}),
Action::make('delete')
->label('Löschen')
->color('danger')
->requiresConfirmation()
->visible(fn (): bool => $this->getRecord()->versions()->doesntExist())
->action(function (): void {
$this->getRecord()->delete();
$this->redirect(ContentElementResource::getUrl('index'));
}),
];
}
protected function getSaveFormAction(): Action
{
return parent::getSaveFormAction()->label('Speichern');
}
protected function getSavedNotificationTitle(): ?string
{
return 'Gespeichert. Es gibt keine neue Fassung.';
}
/**
* @param array $data
* @return array
*/
protected function mutateFormDataBeforeFill(array $data): array
{
return [
'working_title' => $this->getRecord()->working_title,
'display_title' => $this->getRecord()->display_title,
'description' => $this->getRecord()->description,
'summary' => $this->getRecord()->summary,
'pillars' => $this->getRecord()->pillars()->pluck('pillars.id')->all(),
];
}
/**
* @param array $data
*/
protected function handleRecordUpdate(Model $record, array $data): Model
{
/** @var ContentElement $record */
try {
app(ContentService::class)->describe($record, (string) $data['working_title'], $data['description'] ?? null);
app(IdentityProfile::class)->fill($record, [
'display_title' => $data['display_title'] ?? null,
'summary' => $data['summary'] ?? null,
], auth()->user());
app(PillarService::class)->assign($record, array_map(intval(...), $data['pillars'] ?? []));
} catch (DomainRuleException $exception) {
Notification::make()->title($exception->getMessage())->danger()->send();
throw new Halt;
}
return $record;
}
}