Merge remote-tracking branch 'origin/feature/kleingrafiken-symbole-tags' into HEAD
This commit is contained in:
commit
ad03eee41f
124 files changed
+839
-2
No files matched your search
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
/**
|
||||
* Material-Tags des Brand-Kits (Film, Übung, PDF, Paket, Film + Übungen, Film + Merkblatt).
|
||||
*
|
||||
* Die Zuordnung hängt an Schlüsseln (Ausgabeklasse des Mediums, Kennung der redaktionellen Art), nie an Beschriftungen.
|
||||
* Was nicht eindeutig zuzuordnen ist, bekommt kein Tag und bleibt Text:
|
||||
* - „Paket“ und die beiden Kombinationen werden nicht automatisch vergeben (offen: Paket als Angebot oder als Programm;
|
||||
* Kombinationen aus dem Modulaufbau berechnen oder redaktionell wählen). Die Komponente kann sie darstellen.
|
||||
* - „Dokument“ ist nicht automatisch PDF; das Tag PDF gibt es nur für die Ausgabeklasse „pdf“.
|
||||
*/
|
||||
enum MaterialTag: string
|
||||
{
|
||||
case Film = 'film';
|
||||
case Uebung = 'uebung';
|
||||
case Pdf = 'pdf';
|
||||
case Paket = 'paket';
|
||||
case FilmUebungen = 'film-uebungen';
|
||||
case FilmMerkblatt = 'film-merkblatt';
|
||||
|
||||
private const FILM_KINDS = ['unterrichtsfilm', 'kurzfilm', 'trailer', 'interview'];
|
||||
|
||||
private const EXERCISE_KINDS = ['arbeitsblatt', 'uebungsbeschreibung'];
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Film => 'Film',
|
||||
self::Uebung => 'Übung',
|
||||
self::Pdf => 'PDF',
|
||||
self::Paket => 'Paket',
|
||||
self::FilmUebungen => 'Film + Übungen',
|
||||
self::FilmMerkblatt => 'Film + Merkblatt',
|
||||
};
|
||||
}
|
||||
|
||||
/** Name des Zeichens im Satz „glyphen“ (resources/svg/brand/glyphen). */
|
||||
public function glyph(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Film => 'film',
|
||||
self::Uebung => 'uebung',
|
||||
self::Pdf, self::FilmMerkblatt => 'dokument',
|
||||
self::Paket => 'paket',
|
||||
self::FilmUebungen => 'filmstreifen',
|
||||
};
|
||||
}
|
||||
|
||||
public static function fromContent(?string $outputClass, ?string $editorialKindSlug = null): ?self
|
||||
{
|
||||
return match (true) {
|
||||
$outputClass === 'film' => self::Film,
|
||||
$outputClass === 'pdf' => self::Pdf,
|
||||
in_array($editorialKindSlug, self::FILM_KINDS, true) => self::Film,
|
||||
in_array($editorialKindSlug, self::EXERCISE_KINDS, true) => self::Uebung,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
* Redaktionsvorschau (Route editorial.card, nur für angemeldete Redaktion); öffentlich nie ausgegeben, weil es
|
||||
* keine Freigabe für die Website hat.
|
||||
* - missing: was für eine vollständige Karte fehlt, als Hinweis nur in der Redaktionsvorschau.
|
||||
* - tag: Schlüssel eines Material-Tags (App\Domain\Catalog\MaterialTag), nur wenn die Art eindeutig zuzuordnen ist;
|
||||
* sonst null, und die Karte zeigt die Art als Text wie bisher.
|
||||
* - texts: die zentralen Texte des Fachobjekts, aus denen die Karte einen wählen kann (teaser, summary, description).
|
||||
* summary bleibt der Text der Vorgabe („Automatisch“); texts wird nur gelesen, wenn die Redaktion einen wählt.
|
||||
*/
|
||||
@@ -39,6 +41,7 @@ public function __construct(
|
||||
public array $missing = [],
|
||||
public ?string $style = null,
|
||||
public array $texts = [],
|
||||
public ?string $tag = null,
|
||||
) {}
|
||||
|
||||
public function withText(?string $title, ?string $summary): self
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialProfileReader;
|
||||
use App\Domain\Catalog\MaterialTag;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Domain\Media\ThumbnailRef;
|
||||
use App\Domain\Media\WebsiteMedia;
|
||||
@@ -235,6 +236,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
|
||||
missing: $missing,
|
||||
style: $film ? 'media' : 'material',
|
||||
texts: $texts,
|
||||
tag: MaterialTag::fromContent((string) $shown->output_class, $element->editorialContentKind?->slug)?->value,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,12 @@ public function panel(Panel $panel): Panel
|
||||
->authMiddleware([
|
||||
Authenticate::class,
|
||||
])
|
||||
// Favicon zur Anfragezeit: ->favicon(asset(...)) würde beim Start der Anwendung berechnet, vor der
|
||||
// Auswertung von Proxy-Kopfzeilen und geöffneter Adresse, und könnte auf einen falschen Host zeigen.
|
||||
->renderHook(
|
||||
PanelsRenderHook::HEAD_END,
|
||||
fn (): string => view('components.site.favicon')->render(),
|
||||
)
|
||||
->renderHook(
|
||||
PanelsRenderHook::STYLES_AFTER,
|
||||
fn (): string => view('filament.cms.styles')->render().view('filament.verwaltung.styles')->render(),
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Brand;
|
||||
|
||||
use Illuminate\Support\HtmlString;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Kleingrafiken des Brand-Kits (docs/Brand-UI-Kit/16_Lara-Felix-Kleingrafiken) als Inline-SVG.
|
||||
*
|
||||
* - Nur Dateien aus resources/svg/brand/<Satz>/ sind zulässig; ein unbekannter Name ist ein Fehler, kein stiller Leerplatz.
|
||||
* - Die Kit-Dateien tragen alle dieselbe ID (motif-title) und einen Titel. Beim Einbetten werden ID, Titel, Rolle und feste
|
||||
* Größe entfernt, damit mehrere Symbole auf einer Seite keine doppelten IDs erzeugen. Symbole sind Beiwerk
|
||||
* (aria-hidden); die Aussage trägt immer der danebenstehende Text.
|
||||
* - Sätze: „symbole“ (Symbole und Akzente aus dem Kit, feste Markenfarben) und „glyphen“ (kleine Zeichen für Tags, Farbe
|
||||
* über currentColor, Geometrie aus den Tag-Dateien des Kits).
|
||||
* - Nicht enthalten: die Motive mit Text als Pfad (Pinsel, Pillen, Tags, Kompositionen). Text bleibt HTML.
|
||||
*/
|
||||
final class Symbols
|
||||
{
|
||||
public const SET_SYMBOLS = 'symbole';
|
||||
|
||||
public const SET_GLYPHS = 'glyphen';
|
||||
|
||||
/** @var array<string, string> */
|
||||
private static array $cache = [];
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function names(string $set = self::SET_SYMBOLS): array
|
||||
{
|
||||
$files = glob(self::directory($set).'/*.svg') ?: [];
|
||||
$names = array_map(fn (string $file): string => basename($file, '.svg'), $files);
|
||||
sort($names);
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
public static function symbol(string $name, string $attributes = ''): HtmlString
|
||||
{
|
||||
return self::render(self::SET_SYMBOLS, $name, $attributes);
|
||||
}
|
||||
|
||||
public static function glyph(string $name, string $attributes = ''): HtmlString
|
||||
{
|
||||
return self::render(self::SET_GLYPHS, $name, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $attributes bereits maskierte Attribute (aus der Attributtasche der Komponente)
|
||||
*/
|
||||
private static function render(string $set, string $name, string $attributes): HtmlString
|
||||
{
|
||||
if (! preg_match('/^[a-z0-9-]+$/', $name) || ! in_array($name, self::names($set), true)) {
|
||||
throw new InvalidArgumentException("Unbekanntes Markensymbol „{$name}“ im Satz „{$set}“.");
|
||||
}
|
||||
|
||||
$svg = self::$cache["$set/$name"] ??= self::clean((string) file_get_contents(self::directory($set)."/$name.svg"));
|
||||
$extra = trim($attributes) === '' ? '' : ' '.trim($attributes);
|
||||
|
||||
return new HtmlString(preg_replace('/^<svg\b/', '<svg aria-hidden="true" focusable="false"'.$extra, $svg, 1) ?? $svg);
|
||||
}
|
||||
|
||||
private static function clean(string $svg): string
|
||||
{
|
||||
$svg = trim($svg);
|
||||
$svg = preg_replace('#<title\b[^>]*>.*?</title>#s', '', $svg) ?? $svg;
|
||||
$svg = preg_replace('/\r?\n\s*/', '', $svg) ?? $svg;
|
||||
|
||||
return (string) preg_replace_callback('/^<svg\b[^>]*>/', function (array $root): string {
|
||||
return (string) preg_replace('/\s(?:id|role|aria-labelledby|width|height)="[^"]*"/', '', $root[0]);
|
||||
}, $svg);
|
||||
}
|
||||
|
||||
private static function directory(string $set): string
|
||||
{
|
||||
if (! in_array($set, [self::SET_SYMBOLS, self::SET_GLYPHS], true)) {
|
||||
throw new InvalidArgumentException("Unbekannter Symbolsatz „{$set}“.");
|
||||
}
|
||||
|
||||
return resource_path("svg/brand/$set");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user