Neues Werkzeug neben dem freien Link in Fließtext, Überschrift-Einleitung und Bild-Text. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
78 lines
3.2 KiB
PHP
78 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Support;
|
|
|
|
use App\Domain\Catalog\FormattedText;
|
|
use Filament\Forms\Components\RichEditor;
|
|
use Filament\Forms\Components\RichEditor\RichEditorTool;
|
|
use Filament\Forms\Components\RichEditor\TextColor;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Js;
|
|
|
|
/**
|
|
* 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
|
|
{
|
|
/** Farbwerte der Schriftfarben im Editor (Weiß/Cremefläche); auf der Seite bestimmt `widgets.css` je Fläche. */
|
|
private const SITE_COLOR_VALUES = ['marine' => '#032551', 'gruen' => '#3b7b09', 'rot' => '#a8212b', 'grau' => '#3e4c5c'];
|
|
|
|
/**
|
|
* @param ?string $label Bezeichnung des Felds; sie ist auch der Name für Hilfstechnik
|
|
* @param bool $live Arbeitsplätze gleichen beim Verlassen des Felds ab ({@see ManagesRichFields}); Dialoge nicht
|
|
* @param bool $hideLabel Die Bezeichnung zeigt der Arbeitsplatz selbst
|
|
* @param bool $images Bilder aus dem Medienbestand einfügen; nur auf Seiten mit dem gemeinsamen Picker
|
|
* ({@see ManagesEditorialSurface::openTextImagePicker()})
|
|
* @param bool $website Texte der Website (Fließtext): zusätzlich Schriftgröße, Schriftfarbe und Ausrichtung aus festen
|
|
* Werten ({@see FormattedText::SITE_SIZES}, {@see FormattedText::SITE_COLORS}); gespeichert wird
|
|
* mit dem Webprofil von {@see FormattedText}
|
|
*/
|
|
public static function make(string $name, ?string $label = null, bool $live = true, bool $hideLabel = false, bool $images = false, bool $website = false): RichEditor
|
|
{
|
|
$toolbar = FormattedText::TOOLBAR;
|
|
|
|
if ($website) {
|
|
// Interne Seite oder Sprungmarke verlinken, gleich neben dem freien Link.
|
|
$toolbar[0] = [...$toolbar[0], 'interneSeite'];
|
|
array_splice($toolbar, 1, 0, [['fontSize', 'textColor'], ['alignStart', 'alignCenter', 'alignEnd']]);
|
|
}
|
|
|
|
if ($images) {
|
|
array_splice($toolbar, count($toolbar) - 1, 0, [['bild']]);
|
|
}
|
|
|
|
$field = RichEditor::make($name)->toolbarButtons($toolbar);
|
|
|
|
if ($website) {
|
|
$field
|
|
->plugins([new FontSizePlugin, new InternalLinkPlugin])
|
|
->textColors(Arr::mapWithKeys(
|
|
FormattedText::SITE_COLORS,
|
|
fn (string $label, string $key): array => [$key => TextColor::make($label, self::SITE_COLOR_VALUES[$key])],
|
|
))
|
|
->customTextColors(false);
|
|
}
|
|
|
|
if ($images) {
|
|
$field->tools([
|
|
RichEditorTool::make('bild')
|
|
->label('Bild aus dem Medienbestand einfügen')
|
|
->icon(Heroicon::Photo)
|
|
->jsHandler('$wire.openTextImagePicker('.Js::from($name).', editorSelection)'),
|
|
]);
|
|
}
|
|
|
|
if ($live) {
|
|
$field->live(onBlur: true);
|
|
}
|
|
|
|
if ($label !== null) {
|
|
$field->label($label);
|
|
}
|
|
|
|
return $label === null || $hideLabel ? $field->hiddenLabel() : $field;
|
|
}
|
|
}
|