Speichere formatierte Texte als bereinigtes HTML mit einem Editor (ADR-50)
Ein Baustein (FormattedText) bereinigt, bringt Werte in die kanonische Form und wandelt Klartext des Altbestands; RichField ist der eine Editor, ManagesRichFields verbindet ihn mit den Arbeitsplätzen. Formatiert sind Texte der Übungen und Textbausteine, Kurzbeschreibung und Beschreibung, Lernziel und Ausstattung. Mitgliederansicht und PDF zeigen fett, kursiv, Listen, Überschrift, Zitat und Link (PDF: schräge Schnitte, nur wenn gebraucht). Das Livewire-Limit für verschachtelte Pfade steigt auf 30, weil Aufzählungen sonst abgelehnt werden. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
be24f3bf64
commit
9fbd933e1e
50 files changed
+1461
-181
No files matched your search
@@ -16,6 +16,7 @@
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\EditorialWorkingDraft;
|
||||
use App\Domain\Catalog\ForeignCompositions;
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
@@ -26,6 +27,7 @@
|
||||
use App\Filament\Support\AssignsPillars;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Filament\Support\ManagesEditorialSurface;
|
||||
use App\Filament\Support\ManagesRichFields;
|
||||
use App\Filament\Support\MediumForm;
|
||||
use App\Filament\Support\WidgetEditor;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
@@ -48,6 +50,7 @@ abstract class EditComposition extends EditRecord
|
||||
{
|
||||
use AssignsPillars;
|
||||
use ManagesEditorialSurface;
|
||||
use ManagesRichFields;
|
||||
use WithFileUploads;
|
||||
|
||||
protected string $view = 'filament.editorial.edit';
|
||||
@@ -382,6 +385,14 @@ public function redaktionTitel(): string
|
||||
return $title !== '' ? $title : $this->hostLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
protected function richFelder(): array
|
||||
{
|
||||
return ['summary', 'description', 'learningGoal', 'materialNote', 'partBody', 'newTextBody'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
@@ -395,8 +406,8 @@ public function redaktionFelder(): array
|
||||
['id' => 'name', 'label' => 'Name in der Verwaltung', 'model' => 'designation', 'kind' => 'text', 'stored' => $stored('designation'), 'required' => true, 'hilfe' => 'Pflichtangabe. Erscheint in Listen der Verwaltung.'],
|
||||
['id' => 'titel', 'label' => 'Titel', 'model' => 'displayTitle', 'kind' => 'text', 'stored' => $stored('display_title'), 'hilfe' => 'Erscheint auf Karten und in der Bibliothek. Leer zeigt den Namen.'],
|
||||
['id' => 'teaser', 'label' => 'Teaser', 'model' => 'teaser', 'kind' => 'textarea', 'rows' => 2, 'stored' => $stored('teaser')],
|
||||
['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'textarea', 'rows' => 3, 'stored' => $stored('summary')],
|
||||
['id' => 'beschreibung', 'label' => 'Ausführliche Beschreibung', 'model' => 'description', 'kind' => 'textarea', 'rows' => 8, 'stored' => $stored('description'), 'hilfe' => 'Beschreibt das Angebot. Kein Lehrtext und kein Lernziel.'],
|
||||
['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'rich', 'stored' => $stored('summary')],
|
||||
['id' => 'beschreibung', 'label' => 'Ausführliche Beschreibung', 'model' => 'description', 'kind' => 'rich', 'stored' => $stored('description'), 'hilfe' => 'Beschreibt das Angebot. Kein Lehrtext und kein Lernziel.'],
|
||||
['id' => 'suche', 'label' => 'Suchbegriffe', 'model' => 'searchTerms', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('search_terms'), 'placeholder' => 'Begriffe, durch Komma getrennt'],
|
||||
];
|
||||
}
|
||||
@@ -1248,7 +1259,7 @@ public function loadTemplate(int $versionId): void
|
||||
public function addText(): void
|
||||
{
|
||||
$title = trim($this->newTextTitle);
|
||||
$body = trim($this->newTextBody);
|
||||
$body = FormattedText::canonical($this->newTextBody);
|
||||
|
||||
if ($title === '' || $body === '') {
|
||||
$this->feedback = 'Der Text braucht einen Titel und einen Inhalt.';
|
||||
@@ -1578,7 +1589,7 @@ private function writePartText(): string|false
|
||||
}
|
||||
|
||||
$title = trim($this->partTitle);
|
||||
$body = trim($this->partBody);
|
||||
$body = FormattedText::canonical($this->partBody);
|
||||
|
||||
if ($title === '' || $body === '') {
|
||||
$this->feedback = 'Der Text braucht einen Titel und einen Inhalt.';
|
||||
@@ -1598,7 +1609,7 @@ private function writePartText(): string|false
|
||||
return false;
|
||||
}
|
||||
|
||||
$changed = $title !== (string) ($member['title'] ?? '') || $body !== trim((string) $version->body);
|
||||
$changed = $title !== (string) ($member['title'] ?? '') || ! FormattedText::same($body, $version->body);
|
||||
|
||||
if (! $changed) {
|
||||
return '';
|
||||
@@ -1755,10 +1766,10 @@ public function publishRevision(): bool
|
||||
$this->actor(),
|
||||
$note !== '' ? $note : null,
|
||||
[
|
||||
'learning_goal' => $this->blank($this->learningGoal),
|
||||
'learning_goal' => $this->richBlank('learningGoal'),
|
||||
'duration_minutes' => $minutes,
|
||||
'duration_max' => $this->blank($this->durationMax),
|
||||
'material_note' => $this->blank($this->materialNote),
|
||||
'material_note' => $this->richBlank('materialNote'),
|
||||
'prerequisites' => $this->blank($this->prerequisites),
|
||||
],
|
||||
$this->releaseConsent,
|
||||
@@ -2079,8 +2090,8 @@ protected function didacticChanged(CompositionVersion $version): bool
|
||||
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description, 'origin' => $variant->origin,
|
||||
])->all());
|
||||
|
||||
return $version->learning_goal !== $this->blank($this->learningGoal)
|
||||
|| $version->material_note !== $this->blank($this->materialNote)
|
||||
return ! FormattedText::same($version->learning_goal, $this->learningGoal)
|
||||
|| ! FormattedText::same($version->material_note, $this->materialNote)
|
||||
|| $version->prerequisites !== $this->blank($this->prerequisites)
|
||||
|| ($version->duration_max === null ? null : (string) $version->duration_max) !== $this->blank($this->durationMax)
|
||||
|| $storedVariants !== $this->normalizeVariants($this->variants)
|
||||
@@ -2104,6 +2115,14 @@ protected function minutes(string $value): int|false|null
|
||||
return $minutes > 0 ? $minutes : false;
|
||||
}
|
||||
|
||||
/** Formatierte Eigenschaft in kanonischer Form für das Speichern; leer wird null. */
|
||||
protected function richBlank(string $name): ?string
|
||||
{
|
||||
$value = $this->richWert($name);
|
||||
|
||||
return $value === '' ? null : $value;
|
||||
}
|
||||
|
||||
protected function blank(string $value): ?string
|
||||
{
|
||||
$value = trim($value);
|
||||
@@ -2138,9 +2157,9 @@ protected function persistRedaktion(): bool
|
||||
app(IdentityProfile::class)->fill($record, [
|
||||
'display_title' => $this->displayTitle,
|
||||
'teaser' => $this->teaser,
|
||||
'summary' => $this->summary,
|
||||
'summary' => $this->richStore('summary', $record->summary),
|
||||
'search_terms' => $this->searchTerms,
|
||||
'description' => $this->description,
|
||||
'description' => $this->richStore('description', $record->description),
|
||||
], $this->actor());
|
||||
$this->syncDimensions($record, array_map(intval(...), $this->dimensionIds));
|
||||
$this->persistPillarIds($record);
|
||||
@@ -2291,9 +2310,9 @@ protected function payload(): array
|
||||
$minutes = $this->minutes($this->durationMinutes);
|
||||
|
||||
return [
|
||||
'learning_goal' => $this->blank($this->learningGoal),
|
||||
'learning_goal' => $this->richBlank('learningGoal'),
|
||||
'duration_minutes' => $minutes === false ? $this->durationMinutes : $minutes,
|
||||
'material_note' => $this->blank($this->materialNote),
|
||||
'material_note' => $this->richBlank('materialNote'),
|
||||
'duration_max' => $this->blank($this->durationMax),
|
||||
'prerequisites' => $this->blank($this->prerequisites),
|
||||
'variants' => $this->normalizeVariants($this->variants),
|
||||
@@ -2392,9 +2411,10 @@ protected function normalizePayload(array $payload): array
|
||||
}
|
||||
|
||||
return [
|
||||
'learning_goal' => $payload['learning_goal'] ?? null,
|
||||
// Formatierte Angaben nur in kanonischer Form vergleichen: Klartext des Altbestands und dasselbe als HTML sind gleich.
|
||||
'learning_goal' => FormattedText::canonical($payload['learning_goal'] ?? null) ?: null,
|
||||
'duration_minutes' => $payload['duration_minutes'] ?? null,
|
||||
'material_note' => $payload['material_note'] ?? null,
|
||||
'material_note' => FormattedText::canonical($payload['material_note'] ?? null) ?: null,
|
||||
'duration_max' => isset($payload['duration_max']) && $payload['duration_max'] !== '' ? (string) $payload['duration_max'] : null,
|
||||
'prerequisites' => $payload['prerequisites'] ?? null,
|
||||
'variants' => $this->normalizeVariants($payload['variants'] ?? []),
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
@@ -19,13 +20,13 @@
|
||||
use App\Filament\Support\ElementRevision;
|
||||
use App\Filament\Support\MediumForm;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use App\Filament\Support\RichField;
|
||||
use App\Jobs\DeriveThumbnail;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
@@ -71,7 +72,7 @@ public function form(Schema $schema): Schema
|
||||
...MediumForm::fields(creating: false, element: $element),
|
||||
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),
|
||||
RichField::make('summary', 'Kurzbeschreibung', live: false),
|
||||
Select::make('editorial_content_kind_id')
|
||||
->label('Fachliche Materialart')
|
||||
->options(fn (): array => app(EditorialVocabulary::class)->kindOptions('medium', $this->getRecord()->editorial_content_kind_id !== null ? (int) $this->getRecord()->editorial_content_kind_id : null))
|
||||
@@ -194,12 +195,12 @@ protected function mutateFormDataBeforeFill(array $data): array
|
||||
return [
|
||||
'working_title' => $this->getRecord()->working_title,
|
||||
'thumbnail_alt' => $this->getRecord()->thumbnail_alt,
|
||||
'body' => $this->getRecord()->versions()->orderByDesc('number')->first()?->body,
|
||||
'body' => FormattedText::html($this->getRecord()->versions()->orderByDesc('number')->first()?->body),
|
||||
'display_title' => $this->getRecord()->display_title,
|
||||
'description' => $this->getRecord()->description,
|
||||
'description' => FormattedText::html($this->getRecord()->description),
|
||||
'usage_note' => $this->getRecord()->usage_note,
|
||||
'license_note' => $this->getRecord()->license_note,
|
||||
'summary' => $this->getRecord()->summary,
|
||||
'summary' => FormattedText::html($this->getRecord()->summary),
|
||||
'editorial_content_kind_id' => $this->getRecord()->editorial_content_kind_id,
|
||||
'dimension_ids' => IdentityDimensionValue::query()
|
||||
->where('subject_type', $this->getRecord()->getMorphClass())
|
||||
@@ -218,10 +219,15 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
{
|
||||
/** @var ContentElement $record */
|
||||
try {
|
||||
app(ContentService::class)->describe($record, (string) $data['working_title'], $data['description'] ?? null);
|
||||
$description = FormattedText::same((string) ($data['description'] ?? ''), $record->description)
|
||||
? $record->description
|
||||
: (FormattedText::canonical((string) ($data['description'] ?? '')) ?: null);
|
||||
app(ContentService::class)->describe($record, (string) $data['working_title'], $description);
|
||||
app(IdentityProfile::class)->fill($record, [
|
||||
'display_title' => $data['display_title'] ?? null,
|
||||
'summary' => $data['summary'] ?? null,
|
||||
'summary' => FormattedText::same((string) ($data['summary'] ?? ''), $record->summary)
|
||||
? $record->summary
|
||||
: (FormattedText::canonical((string) ($data['summary'] ?? '')) ?: null),
|
||||
'usage_note' => $data['usage_note'] ?? null,
|
||||
'license_note' => $data['license_note'] ?? null,
|
||||
'thumbnail_alt' => $data['thumbnail_alt'] ?? null,
|
||||
@@ -229,8 +235,8 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
if ($record->output_class === 'text' && is_string($data['body'] ?? null)) {
|
||||
$latest = $record->versions()->orderByDesc('number')->first();
|
||||
|
||||
if ($latest instanceof ContentElementVersion) {
|
||||
app(ContentService::class)->reviseElementContent($latest, $data['body']);
|
||||
if ($latest instanceof ContentElementVersion && ! FormattedText::same($data['body'], $latest->body)) {
|
||||
app(ContentService::class)->reviseElementContent($latest, FormattedText::canonical($data['body']));
|
||||
}
|
||||
}
|
||||
if (array_key_exists('editorial_content_kind_id', $data)) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use App\Domain\Catalog\IdentityChange;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
@@ -26,6 +27,7 @@
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Filament\Support\ElementRevision;
|
||||
use App\Filament\Support\ManagesEditorialSurface;
|
||||
use App\Filament\Support\ManagesRichFields;
|
||||
use App\Filament\Support\MediaLibrary;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
@@ -45,6 +47,7 @@
|
||||
class ViewContentElement extends ViewRecord
|
||||
{
|
||||
use ManagesEditorialSurface;
|
||||
use ManagesRichFields;
|
||||
use ReportsDomainRules;
|
||||
use WithFileUploads;
|
||||
|
||||
@@ -211,7 +214,7 @@ public function textUnsaved(): bool
|
||||
return $shown instanceof ContentElementVersion
|
||||
&& $this->getRecord()->output_class === 'text'
|
||||
&& $shown->status !== ContentVersionStatus::Gesperrt
|
||||
&& trim($this->bodyDraft) !== trim((string) $shown->body);
|
||||
&& ! FormattedText::same($this->bodyDraft, $shown->body);
|
||||
}
|
||||
|
||||
public function discardShownText(): void
|
||||
@@ -243,7 +246,7 @@ public function saveShownText(): void
|
||||
}
|
||||
|
||||
try {
|
||||
$saved = app(ContentService::class)->reviseElementContent($shown, $this->bodyDraft);
|
||||
$saved = app(ContentService::class)->reviseElementContent($shown, FormattedText::canonical($this->bodyDraft));
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->fassungFeedback = $exception->getMessage();
|
||||
$this->fassungFeedbackError = true;
|
||||
@@ -687,9 +690,9 @@ protected function saveRedaktionTexte(): bool
|
||||
'working_title' => $title,
|
||||
'display_title' => $this->displayTitle,
|
||||
'teaser' => $this->teaser,
|
||||
'summary' => $this->summary,
|
||||
'summary' => $this->richStore('summary', $element->summary),
|
||||
'search_terms' => $this->searchTerms,
|
||||
'description' => $this->descriptionText,
|
||||
'description' => $this->richStore('descriptionText', $element->description),
|
||||
'usage_note' => $this->usageNote,
|
||||
'license_note' => $this->licenseNote,
|
||||
'website_credit' => $this->websiteCredit,
|
||||
@@ -780,6 +783,14 @@ public function redaktionTitel(): string
|
||||
return $title !== '' ? $title : (string) $this->getRecord()->working_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
protected function richFelder(): array
|
||||
{
|
||||
return ['summary', 'descriptionText', 'bodyDraft'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
@@ -793,8 +804,8 @@ public function redaktionFelder(): array
|
||||
['id' => 'arbeitstitel', 'label' => 'Arbeitstitel', 'model' => 'workingTitle', 'kind' => 'text', 'stored' => $stored('working_title'), 'required' => true, 'hilfe' => 'Bezeichnung in der Verwaltung. Pflichtangabe.'],
|
||||
['id' => 'anzeigename', 'label' => 'Anzeigename', 'model' => 'displayTitle', 'kind' => 'text', 'stored' => $stored('display_title'), 'hilfe' => 'Erscheint auf Karten und in der Bibliothek. Leer zeigt den Arbeitstitel.'],
|
||||
['id' => 'teaser', 'label' => 'Teaser', 'model' => 'teaser', 'kind' => 'textarea', 'rows' => 2, 'stored' => $stored('teaser')],
|
||||
['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'textarea', 'rows' => 3, 'stored' => $stored('summary'), 'hilfe' => 'Erscheint auf Website- und Bibliothekskarten.'],
|
||||
['id' => 'beschreibung', 'label' => 'Ausführliche Beschreibung', 'model' => 'descriptionText', 'kind' => 'textarea', 'rows' => 8, 'stored' => $stored('description'), 'hilfe' => 'Bleibt in der Verwaltung und in Detailansichten. Kein Lehrtext.'],
|
||||
['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'rich', 'stored' => $stored('summary'), 'hilfe' => 'Erscheint auf Website- und Bibliothekskarten.'],
|
||||
['id' => 'beschreibung', 'label' => 'Ausführliche Beschreibung', 'model' => 'descriptionText', 'kind' => 'rich', 'stored' => $stored('description'), 'hilfe' => 'Bleibt in der Verwaltung und in Detailansichten. Kein Lehrtext.'],
|
||||
['id' => 'suche', 'label' => 'Suchbegriffe', 'model' => 'searchTerms', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('search_terms'), 'placeholder' => 'Begriffe, durch Komma getrennt'],
|
||||
['id' => 'einsatz', 'label' => 'Hinweise für den Einsatz', 'model' => 'usageNote', 'kind' => 'textarea', 'rows' => 3, 'gruppe' => 'weitere', 'stored' => $stored('usage_note')],
|
||||
['id' => 'lizenz', 'label' => 'Interner Lizenzvermerk', 'model' => 'licenseNote', 'kind' => 'textarea', 'rows' => 3, 'gruppe' => 'weitere', 'stored' => $stored('license_note'), 'hilfe' => 'Nur intern sichtbar.'],
|
||||
@@ -1040,7 +1051,7 @@ public function previewHtml(): string
|
||||
$draft = [
|
||||
'working_title' => $this->workingTitle,
|
||||
'display_title' => $this->displayTitle,
|
||||
'summary' => $this->summary,
|
||||
'summary' => FormattedText::plain($this->summary),
|
||||
'thumbnail_alt' => $this->thumbnailAlt,
|
||||
];
|
||||
|
||||
@@ -1053,7 +1064,7 @@ public function previewHtml(): string
|
||||
'type' => $element->output_class === 'film' ? 'film' : 'material',
|
||||
'url' => '#vorschau',
|
||||
'title' => $title !== '' ? $title : $element->working_title,
|
||||
'summary' => trim($this->summary) !== '' ? trim($this->summary) : null,
|
||||
'summary' => FormattedText::plain($this->summary) !== '' ? FormattedText::plain($this->summary) : null,
|
||||
'kind' => PublicMaterialReader::outputLabel((string) $element->output_class),
|
||||
'hide_status' => true,
|
||||
'image' => trim($this->thumbnailAlt) !== '' ? trim($this->thumbnailAlt) : $title,
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
use App\Filament\Support\CatalogOptions;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Filament\Support\ManagesEditorialSurface;
|
||||
use App\Filament\Support\ManagesRichFields;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
@@ -33,6 +34,7 @@ class ViewLicenseArticle extends ViewRecord
|
||||
{
|
||||
use AssignsPillars;
|
||||
use ManagesEditorialSurface;
|
||||
use ManagesRichFields;
|
||||
use ReportsDomainRules;
|
||||
|
||||
protected static string $resource = LicenseArticleResource::class;
|
||||
@@ -110,8 +112,8 @@ protected function saveRedaktionTexte(): bool
|
||||
'working_title' => $this->workingTitle,
|
||||
'display_title' => $this->displayTitle,
|
||||
'teaser' => $this->teaser,
|
||||
'summary' => $this->summary,
|
||||
'description' => $this->descriptionText,
|
||||
'summary' => $this->richStore('summary', $article->summary),
|
||||
'description' => $this->richStore('descriptionText', $article->description),
|
||||
'search_terms' => $this->searchTerms,
|
||||
'editorial_content_kind_id' => filled($this->kindId) ? (int) $this->kindId : null,
|
||||
], auth()->user());
|
||||
@@ -199,6 +201,14 @@ public function redaktionTitel(): string
|
||||
return $source !== null ? $this->sourceTitle($source) : (string) $this->getRecord()->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
protected function richFelder(): array
|
||||
{
|
||||
return ['summary', 'descriptionText'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
@@ -218,8 +228,8 @@ public function redaktionFelder(): array
|
||||
['id' => 'arbeitstitel', 'label' => 'Interner Arbeitstitel', 'model' => 'workingTitle', 'kind' => 'text', 'stored' => $stored('working_title'), 'hilfe' => 'Nur in der Verwaltung sichtbar.'],
|
||||
['id' => 'anzeigename', 'label' => 'Name', 'model' => 'displayTitle', 'kind' => 'text', 'stored' => $stored('display_title'), 'quelle' => $quelle('display_title')],
|
||||
['id' => 'teaser', 'label' => 'Teaser', 'model' => 'teaser', 'kind' => 'textarea', 'rows' => 2, 'stored' => $stored('teaser'), 'quelle' => $quelle('teaser')],
|
||||
['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'textarea', 'rows' => 4, 'stored' => $stored('summary'), 'quelle' => $quelle('summary')],
|
||||
['id' => 'beschreibung', 'label' => 'Beschreibung', 'model' => 'descriptionText', 'kind' => 'textarea', 'rows' => 6, 'stored' => $stored('description'), 'quelle' => $quelle('description')],
|
||||
['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'rich', 'stored' => $stored('summary'), 'quelle' => $quelle('summary')],
|
||||
['id' => 'beschreibung', 'label' => 'Beschreibung', 'model' => 'descriptionText', 'kind' => 'rich', 'stored' => $stored('description'), 'quelle' => $quelle('description')],
|
||||
['id' => 'suche', 'label' => 'Suchbegriffe', 'model' => 'searchTerms', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('search_terms'), 'quelle' => $quelle('search_terms')],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
@@ -108,8 +109,8 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
'kind' => $kind,
|
||||
'output' => (string) $element->output_class,
|
||||
'body' => (string) ($version->body ?? ''),
|
||||
'summary' => (string) ($element->summary ?: $element->description ?: ''),
|
||||
'medium_description' => (string) ($element->description ?? ''),
|
||||
'summary' => FormattedText::plain((string) ($element->summary ?: $element->description ?: '')),
|
||||
'medium_description' => FormattedText::plain((string) ($element->description ?? '')),
|
||||
'usage_note' => (string) ($element->usage_note ?? ''),
|
||||
'license_note' => (string) ($element->license_note ?? ''),
|
||||
'tone' => $this->tone((string) $element->output_class, $kind),
|
||||
@@ -159,7 +160,7 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
'target' => 'composition:'.$version->id,
|
||||
'title' => $this->compositionTitle($composition),
|
||||
'kind' => $kind,
|
||||
'summary' => (string) ($composition->summary ?? ''),
|
||||
'summary' => FormattedText::plain((string) ($composition->summary ?? '')),
|
||||
'tone' => $this->tone('', $kind),
|
||||
'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path),
|
||||
'version_label' => $version->status === ContentVersionStatus::Gesperrt
|
||||
@@ -194,7 +195,7 @@ private function draftCompositionRow(int $compositionId, int $exceptCompositionI
|
||||
'target' => 'composition-draft:'.$composition->id,
|
||||
'title' => $this->compositionTitle($composition),
|
||||
'kind' => $kind,
|
||||
'summary' => (string) ($composition->summary ?? ''),
|
||||
'summary' => FormattedText::plain((string) ($composition->summary ?? '')),
|
||||
'tone' => $this->tone('', $kind),
|
||||
'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path),
|
||||
'version_label' => 'Entwurf',
|
||||
@@ -510,8 +511,8 @@ private function rowForPresentationMedium(int $id): ?array
|
||||
'kind' => $kind,
|
||||
'output' => (string) $element->output_class,
|
||||
'body' => '',
|
||||
'summary' => (string) ($element->summary ?: $element->description ?: ''),
|
||||
'medium_description' => (string) ($element->description ?? ''),
|
||||
'summary' => FormattedText::plain((string) ($element->summary ?: $element->description ?: '')),
|
||||
'medium_description' => FormattedText::plain((string) ($element->description ?? '')),
|
||||
'usage_note' => (string) ($element->usage_note ?? ''),
|
||||
'license_note' => (string) ($element->license_note ?? ''),
|
||||
'tone' => $this->tone((string) $element->output_class, $kind),
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
||||
use Filament\Forms\Components\Component;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
|
||||
@@ -37,14 +37,14 @@ public static function publish(ContentElement $record, array $data): string
|
||||
$metadata['decision_seconds'] = $decision;
|
||||
}
|
||||
|
||||
$body = is_string($data['body'] ?? null) ? $data['body'] : null;
|
||||
$body = is_string($data['body'] ?? null) ? (FormattedText::canonical($data['body']) ?: null) : null;
|
||||
$note = is_string($data['change_note'] ?? null) ? $data['change_note'] : null;
|
||||
$previousDecision = is_array($latest?->metadata) && is_numeric($latest->metadata['decision_seconds'] ?? null)
|
||||
? (int) $latest->metadata['decision_seconds']
|
||||
: null;
|
||||
$changed = $incoming !== null
|
||||
|| $dropFile
|
||||
|| trim((string) $body) !== trim((string) $latest?->body)
|
||||
|| ! FormattedText::same($body, $latest?->body)
|
||||
|| $decision !== $previousDecision
|
||||
|| (is_string($note) && trim($note) !== '');
|
||||
|
||||
@@ -71,7 +71,7 @@ public static function fields(ContentElement $element): array
|
||||
$latest = $element->versions()->orderByDesc('number')->first();
|
||||
|
||||
return [
|
||||
Textarea::make('body')->label('Text')->rows(8)->default($latest?->body),
|
||||
RichField::make('body', 'Text', live: false)->default(FormattedText::html($latest?->body)),
|
||||
EditContentElement::uploadField(),
|
||||
Toggle::make('drop_file')
|
||||
->label('Datei in der neuen Fassung nicht mehr verwenden')
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\ExerciseSource;
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\PillarFilterCompat;
|
||||
@@ -183,8 +184,8 @@ public function entries(): array
|
||||
}
|
||||
|
||||
$title = $catalog->compositionTitle($composition);
|
||||
$summary = trim((string) ($composition->summary ?? ''));
|
||||
$haystack = mb_strtolower($title.' '.$composition->designation.' '.$summary.' '.(string) $composition->description);
|
||||
$summary = FormattedText::plain((string) ($composition->summary ?? ''));
|
||||
$haystack = mb_strtolower($title.' '.$composition->designation.' '.$summary.' '.FormattedText::plain((string) $composition->description));
|
||||
|
||||
if ($needle !== '' && ! str_contains($haystack, $needle)) {
|
||||
continue;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
use App\Domain\Catalog\EditorialProfile;
|
||||
use App\Domain\Catalog\EditorialProfileReader;
|
||||
use App\Domain\Catalog\EditorialTextVariant;
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use App\Domain\Catalog\PresentationMedia;
|
||||
use App\Domain\Catalog\PresentationRole;
|
||||
use App\Domain\Media\WebsiteRelease;
|
||||
@@ -310,6 +311,10 @@ public function feldGeaendert(array $feld): bool
|
||||
{
|
||||
$model = (string) $feld['model'];
|
||||
|
||||
if (($feld['kind'] ?? null) === 'rich') {
|
||||
return ! FormattedText::same((string) $this->{$model}, (string) ($feld['stored'] ?? ''));
|
||||
}
|
||||
|
||||
return trim((string) $this->{$model}) !== trim((string) ($feld['stored'] ?? ''));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
/**
|
||||
* Formatierte Textfelder in den Arbeitsplätzen der Verwaltung (ADR-50).
|
||||
*
|
||||
* Die Arbeitsplätze halten ihre Texte als einfache Zeichenketten in öffentlichen Eigenschaften. Der Editor von Filament
|
||||
* hält dagegen ein Dokument in seinem eigenen Zustand (`rich.<feld>`). Diese Eigenschaft ist der einzige Ort, an dem beide
|
||||
* zusammenkommen:
|
||||
*
|
||||
* - Die Zeichenkette bleibt maßgeblich. Eine Eingabe im Editor wird beim Verlassen des Felds in kanonisches HTML gewandelt
|
||||
* und in die Eigenschaft geschrieben ({@see self::updatedRich()}).
|
||||
* - Setzt der Server eine Eigenschaft selbst (Laden, Zurücknehmen, Wechsel des Abschnitts), gleicht der Editor sich vor
|
||||
* dem nächsten Rendern an ({@see self::renderingManagesRichFields()}). Klartext des Altbestands erscheint dabei
|
||||
* formatiert, ohne dass etwas gespeichert wird.
|
||||
*
|
||||
* Verglichen wird nur in kanonischer Form ({@see FormattedText::canonical()}): Das Öffnen eines Felds im Editor ändert
|
||||
* nichts am Arbeitsstand.
|
||||
*/
|
||||
trait ManagesRichFields
|
||||
{
|
||||
/** @var array<string, mixed> Zustand der Editoren (Dokumente) je Eigenschaft */
|
||||
public array $rich = [];
|
||||
|
||||
/** @var array<string, string> Zuletzt abgeglichener kanonischer Wert je Eigenschaft */
|
||||
public array $richSeen = [];
|
||||
|
||||
/**
|
||||
* Eigenschaften dieser Seite, die mit dem Editor bearbeitet werden.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
protected function richFelder(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function richTextSchema(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->statePath('rich')
|
||||
->components(array_map(fn (string $name): RichEditor => RichField::make($name), $this->richFelder()));
|
||||
}
|
||||
|
||||
public function richKomponente(string $name): ?Component
|
||||
{
|
||||
return $this->getSchema('richTextSchema')?->getFlatComponents()[$name] ?? null;
|
||||
}
|
||||
|
||||
/** Eingabe im Editor übernehmen. */
|
||||
public function updatedRich(mixed $value = null, ?string $key = null): void
|
||||
{
|
||||
$name = explode('.', (string) $key)[0];
|
||||
|
||||
if ($name !== '' && in_array($name, $this->richFelder(), true)) {
|
||||
$this->richPull($name);
|
||||
}
|
||||
}
|
||||
|
||||
/** Wert aus dem Editor in die Eigenschaft schreiben. */
|
||||
protected function richPull(string $name): void
|
||||
{
|
||||
$component = $this->richKomponente($name);
|
||||
|
||||
if ($component === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$html = FormattedText::canonicalHtml((string) $component->getState());
|
||||
$this->{$name} = $html;
|
||||
$this->richSeen[$name] = $html;
|
||||
}
|
||||
|
||||
/** Wert der Eigenschaft in den Editor schreiben. */
|
||||
protected function richPush(string $name): void
|
||||
{
|
||||
$component = $this->richKomponente($name);
|
||||
|
||||
if ($component === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$canonical = FormattedText::canonical((string) $this->{$name});
|
||||
$component->state($canonical === '' ? null : $canonical);
|
||||
$this->richSeen[$name] = $canonical;
|
||||
}
|
||||
|
||||
/** Vor dem Rendern: Eigenschaften, die der Server geändert hat, in den Editor übernehmen. */
|
||||
public function renderingManagesRichFields(): void
|
||||
{
|
||||
foreach ($this->richFelder() as $name) {
|
||||
$canonical = FormattedText::canonical((string) $this->{$name});
|
||||
|
||||
if (! array_key_exists($name, $this->richSeen) || $this->richSeen[$name] !== $canonical) {
|
||||
$this->richPush($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wert zum Schreiben in eine Spalte. Ist der Text inhaltlich der gespeicherte, bleibt der gespeicherte Wert, wie er
|
||||
* ist: Klartext des Altbestands wird nicht allein durch das Öffnen im Editor zu HTML und erzeugt keine Änderung.
|
||||
*/
|
||||
protected function richStore(string $name, ?string $stored): ?string
|
||||
{
|
||||
if (FormattedText::same((string) $this->{$name}, $stored)) {
|
||||
return ($stored === null || trim($stored) === '') ? null : $stored;
|
||||
}
|
||||
|
||||
$value = $this->richWert($name);
|
||||
|
||||
return $value === '' ? null : $value;
|
||||
}
|
||||
|
||||
/** Kanonischer Wert einer Eigenschaft für Speichern und Vergleichen. */
|
||||
protected function richWert(string $name): string
|
||||
{
|
||||
return FormattedText::canonical((string) $this->{$name});
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
use App\Domain\Media\PresentationFile;
|
||||
use App\Jobs\DeriveThumbnail;
|
||||
@@ -35,7 +36,7 @@ public static function fields(bool $creating, ?ContentElement $element = null):
|
||||
'document' => 'Dokument',
|
||||
'text' => 'Text',
|
||||
])->required()->live();
|
||||
$fields[] = Textarea::make('body')->label('Text')->rows(8)
|
||||
$fields[] = RichField::make('body', 'Text', live: false)
|
||||
->visible(fn ($get): bool => $get('shape') === 'text')
|
||||
->required(fn ($get): bool => $get('shape') === 'text');
|
||||
$fields[] = self::fileField()
|
||||
@@ -46,12 +47,12 @@ public static function fields(bool $creating, ?ContentElement $element = null):
|
||||
->helperText('Bild, Film oder Hörstück ohne fachliche Inhaltsfassung, zum Beispiel ein Trailer, der ungeschützt auf der Website laufen soll. Der Film muss dafür MP4 (H.264) oder WebM sein. Er wird nicht lizenziert und erst nach „Für die Website freigeben“ öffentlich.')
|
||||
->visible(fn ($get): bool => in_array($get('shape'), ['film', 'audio', 'bild'], true));
|
||||
} elseif ($element?->output_class === 'text') {
|
||||
$fields[] = Textarea::make('body')->label('Text')->rows(8)->required();
|
||||
$fields[] = RichField::make('body', 'Text', live: false)->required();
|
||||
}
|
||||
|
||||
return [
|
||||
...$fields,
|
||||
Textarea::make('description')->label('Beschreibung')->rows(4)
|
||||
RichField::make('description', 'Beschreibung', live: false)
|
||||
->helperText('Gilt für das Medium, nicht nur für diese eine Stelle.'),
|
||||
Textarea::make('usage_note')->label('Hinweise für den Einsatz')->rows(3),
|
||||
Textarea::make('license_note')->label('Interner Lizenzvermerk')->rows(3)
|
||||
@@ -125,7 +126,7 @@ public static function create(array $data, bool $hold): ContentElement
|
||||
self::remember($element, $data);
|
||||
|
||||
if ($output === 'text') {
|
||||
$body = trim((string) ($data['body'] ?? ''));
|
||||
$body = FormattedText::canonical((string) ($data['body'] ?? ''));
|
||||
|
||||
if ($body === '') {
|
||||
throw new DomainRuleException('Der Text braucht einen Inhalt.');
|
||||
@@ -164,7 +165,7 @@ public static function update(ContentElement $element, array $data): ?ContentEle
|
||||
|
||||
if ($element->output_class === 'text') {
|
||||
$latest = $element->versions()->orderByDesc('number')->first();
|
||||
$body = trim((string) ($data['body'] ?? ''));
|
||||
$body = FormattedText::canonical((string) ($data['body'] ?? ''));
|
||||
|
||||
if ($latest instanceof ContentElementVersion && $body !== '') {
|
||||
$revised = app(ContentService::class)->reviseElementContent($latest, $body);
|
||||
@@ -185,11 +186,11 @@ public static function fill(ContentElement $element): array
|
||||
|
||||
return [
|
||||
'working_title' => $element->working_title,
|
||||
'description' => $element->description,
|
||||
'description' => FormattedText::html($element->description),
|
||||
'usage_note' => $element->usage_note,
|
||||
'license_note' => $element->license_note,
|
||||
'thumbnail_alt' => $element->thumbnail_alt,
|
||||
'body' => $latest?->body,
|
||||
'body' => FormattedText::html($latest?->body),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -198,7 +199,10 @@ public static function fill(ContentElement $element): array
|
||||
*/
|
||||
public static function remember(ContentElement $element, array $data): void
|
||||
{
|
||||
app(ContentService::class)->describe($element, (string) $data['working_title'], $data['description'] ?? null);
|
||||
$description = FormattedText::same((string) ($data['description'] ?? ''), $element->description)
|
||||
? $element->description
|
||||
: (FormattedText::canonical((string) ($data['description'] ?? '')) ?: null);
|
||||
app(ContentService::class)->describe($element, (string) $data['working_title'], $description);
|
||||
app(IdentityProfile::class)->fill($element, [
|
||||
'usage_note' => $data['usage_note'] ?? null,
|
||||
'license_note' => $data['license_note'] ?? null,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
|
||||
/**
|
||||
* Der eine Editor für formatierte Texte (ADR-50): immer dieselbe Symbolleiste, dasselbe Ergebnis (bereinigtes HTML).
|
||||
* Neue formatierte Felder nutzen diesen Baustein und keinen eigenen Editor.
|
||||
*/
|
||||
final class RichField
|
||||
{
|
||||
/**
|
||||
* @param ?string $label Mit Bezeichnung für Formulare und Dialoge; ohne bleibt sie dem Arbeitsplatz überlassen
|
||||
* @param bool $live Arbeitsplätze gleichen beim Verlassen des Felds ab ({@see ManagesRichFields}); Dialoge nicht
|
||||
*/
|
||||
public static function make(string $name, ?string $label = null, bool $live = true): RichEditor
|
||||
{
|
||||
$field = RichEditor::make($name)->toolbarButtons(FormattedText::TOOLBAR);
|
||||
|
||||
if ($live) {
|
||||
$field->live(onBlur: true);
|
||||
}
|
||||
|
||||
return $label === null ? $field->hiddenLabel() : $field->label($label);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user