'http://localhost:5173/@vite/client', 'type' => 'module'],'vite-client']; // $page['#attached']['library'][] = 'http://localhost:5173/@vite/client'; // $attachments['#attached']['html_head'][] = [['src' => 'http://localhost:5173/assets/js/main.js', 'type' => 'module'],'vite-main']; // $page['#attached']['library'][] = 'http://localhost:5173/assets/js/main.js'; $page['#attached']['library'][] = 'leshed/vitehmr'; $page['#attached']['library'][] = 'leshed/titles_hmr'; }else{ $page['#attached']['library'][] = 'leshed/global'; $page['#attached']['library'][] = 'leshed/titles'; // Must match exactly the url() resolved from assets/dist/main.css, or the // font is downloaded twice. $fonts_path = base_path() . \Drupal::service('extension.list.theme')->getPath('leshed') . '/assets/dist/fonts/'; foreach (['Epilogue-VariableFont_wght.ttf', 'Epilogue-Italic-VariableFont_wght.ttf'] as $font) { $page['#attached']['html_head'][] = [ [ '#tag' => 'link', '#attributes' => [ 'rel' => 'preload', 'href' => $fonts_path . $font, 'as' => 'font', 'type' => 'font/ttf', 'crossorigin' => 'anonymous', ], ], 'leshed_preload_' . $font, ]; } } } /** * Implements hook_preprocess_HOOK() for html.html.twig. */ function leshed_preprocess_html(&$variables) { } /** * Implements hook_preprocess_HOOK() for page.html.twig. */ function leshed_preprocess_page(&$variables) { } function leshed_preprocess_region(&$variables) { if (!isset($variables["attributes"]['class'])) { $variables["attributes"]['class'] = []; } $variables["attributes"]['class'][] = "wrapper"; } // function leshed_preprocess_block__leshed_contenu(&$variables) { function leshed_preprocess_block__menu_block__contenu(&$variables) { foreach ($variables['content']['#items'] as $key => $item) { parse_menu_item($variables['content']['#items'], $key); } } function parse_menu_item(&$items, $key){ if ($items[$key]['url']->getRouteName() === "entity.node.canonical") { $nid = $items[$key]['url']->getRouteParameters()['node']; $node = \Drupal\node\Entity\Node::load($nid); // create prefix (label) for chapitres if ($node->getType() === "chapitre") { $chapitre = $node->get('field_chapitre_num')->getValue()[0]['value']; $items[$key]['prefix'] = "Chapitre {$chapitre}"; } // create prefix (label) for parties if ($node->getType() === "partie") { $partie = $node->get('field_partie')->getValue()[0]['value']; $items[$key]['prefix'] = "Partie {$partie}"; } // add active attribute if ($items[$key]['in_active_trail']){ $items[$key]['attributes']->offsetSet('class', 'in-active-trail'); } } if (count($items[$key]['below']) > 0) { foreach ($items[$key]['below'] as $key_b => $item_b) { parse_menu_item($items[$key]['below'], $key_b); } } } /** * Implements hook_preprocess_HOOK() for node.html.twig. */ function leshed_preprocess_node(&$variables) { /** @var \Drupal\node\Entity\Node $node */ $node = $variables['node']; $node_type = $node->getType(); if (!isset($variables["attributes"]['class'])) { $variables["attributes"]['class'] = []; } $variables["attributes"]['class'][] = "node-type-{$node_type}"; $variables["attributes"]['class'][] = "view-mode-{$variables['view_mode']}"; if ($node->hasField('field_images')) { /** @var \Drupal\file\Plugin\\Field\FieldType\FileFieldItemList $field_images */ $field_images = $node->get('field_images'); if ($field_images && !$field_images->isEmpty()) { $variables["attributes"]['class'][] = "has-image"; } } } function leshed_preprocess_container(&$variables) { } /** * Implements hook_preprocess_HOOK() for node.html.twig. */ function leshed_preprocess_field(&$variables) { if (!isset($variables["title_attributes"]['class'])) { $variables["title_attributes"]['class'] = []; } $variables['title_attributes']['class'][] = 'field-label'; if (!isset($variables["attributes"]['class'])) { $variables["attributes"]['class'] = []; } $variables['attributes']['class'][] = $variables['field_name']; if ($variables['field_name'] === 'field_dates') { $field_items = $variables['element']['#items']; foreach ($variables['items'] as $delta => &$item) { $field_item = $field_items[$delta]; foreach (['start_date', 'end_date'] as $key) { /** @var \Drupal\Core\Datetime\DrupalDateTime|null $date */ $date = $field_item->{$key}; if ($date instanceof \Drupal\Core\Datetime\DrupalDateTime) { $item[$key] = [ 'year' => $date->format('y'), 'month' => $date->format('m'), 'month_name' => $date->format('F'), 'day' => $date->format('d'), 'iso' => $date->format('Y-m-d\TH:i:s') . 'Z', ]; } } } } } function leshed_preprocess_links__language_block(&$variables){ foreach ($variables['links'] as $langcode => $link) { $variables['links'][$langcode]['text'] = $langcode; $variables['links'][$langcode]['link']['#title'] = $langcode; } } function leshed_preprocess_time(&$variables){ }