diff --git a/app/Domain/Catalog/MaterialTag.php b/app/Domain/Catalog/MaterialTag.php new file mode 100644 index 0000000..9609940 --- /dev/null +++ b/app/Domain/Catalog/MaterialTag.php @@ -0,0 +1,61 @@ + '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, + }; + } +} diff --git a/app/Domain/Cms/Catalog/CardSubject.php b/app/Domain/Cms/Catalog/CardSubject.php index d75a52f..9d16cbc 100644 --- a/app/Domain/Cms/Catalog/CardSubject.php +++ b/app/Domain/Cms/Catalog/CardSubject.php @@ -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 diff --git a/app/Domain/Cms/Catalog/PublicMaterialReader.php b/app/Domain/Cms/Catalog/PublicMaterialReader.php index 49780f9..78557d7 100644 --- a/app/Domain/Cms/Catalog/PublicMaterialReader.php +++ b/app/Domain/Cms/Catalog/PublicMaterialReader.php @@ -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, ); } diff --git a/app/Support/Brand/Symbols.php b/app/Support/Brand/Symbols.php new file mode 100644 index 0000000..af63267 --- /dev/null +++ b/app/Support/Brand/Symbols.php @@ -0,0 +1,84 @@ +/ 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 */ + private static array $cache = []; + + /** + * @return list + */ + 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('/^