====== Menu-Icons ====== ===== Modul "menu_link_attributes" ===== Modul [[https://www.drupal.org/project/menu_link_attributes|menu_link_attributes]] installieren und wie folgt konfigurieren: attributes: class: label: '' description: '' data-icon: label: Menu-Icon description: 'Set an Icon for this menu-entry.' options: icon-academic-cap: Academic-Cap icon-newspaper: Newspaper icon-pencil: Pencil icon-at-symbol: at-Symbol default_value: '' target: label: '' description: '' options: _blank: 'New window (_blank)' _self: 'Same window (_self)' default_value: '' rel: label: Rel-Attribute description: 'Rel(ation) Attribute festlegen' options: nofollow: nofollow default_value: '' ===== Theme Hook ===== Theme Hook für Menu-Entries in der Datei TemplateName.theme bereitstellen und das "FormattableMarkup" nach eigenen Wünschen gestalten. /** fuer menu_link_attributes: * svg icons als svg sprite bereitstellen * passendes sprite auswaehlen * svg in page.html.twig */ use Drupal\Component\Render\FormattableMarkup; /** * Implements theme_preprocess_menu(). */ function swiftly_preprocess_menu(&$variables, $hook) { foreach ($variables['items'] as &$item) { $attributes = $item['url']->getOption('attributes'); if (isset($attributes['data-icon'])) { $title = new FormattableMarkup('
', [ '@title' => $item['title'], '@icon' => $attributes['data-icon'], ]); $item['title'] = $title; } } }
===== SVG Sprites ===== Die SVG-Icons als SVG Sprites in der Datei page.html.twig (immer verfügbar) bereitstellen, einfach unten anfügen. Die Icons selbst sind in diesem Fall von heroicons.com. ===== CSS Style ===== Die SVG Sprites lassen sich beliebig mit CSS stylen, z.B.: (Tailwind CSS) /* menu-icons (menu_link_attributes) */ .icon { @apply w-6 fill-transparent stroke-onyx hover:stroke-lava; }