122 lines
3.6 KiB
PHP
122 lines
3.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Functions to support theming in the mathallo theme.
|
|
*/
|
|
|
|
function mathallo_page_attachments_alter(&$page) {
|
|
if (getenv('APP_ENV') === 'development') {
|
|
// Port réel du dev server Vite, écrit par le plugin devPortFilePlugin
|
|
// (vite.config.js) dans .vite-dev-port
|
|
// (premier port libre à partir de 5173, strictPort: false) : permet de
|
|
// lancer plusieurs sites sur le même modèle de thème en même temps.
|
|
$port = (int) trim((string) @file_get_contents(__DIR__ . '/.vite-dev-port'));
|
|
if ($port <= 0) {
|
|
$port = 5173;
|
|
}
|
|
$page['#attached']['html_head'][] = [
|
|
[
|
|
'#type' => 'html_tag',
|
|
'#tag' => 'script',
|
|
'#attributes' => ['type' => 'module', 'src' => "https://localhost:{$port}/@vite/client"],
|
|
],
|
|
'vite-client',
|
|
];
|
|
$page['#attached']['html_head'][] = [
|
|
[
|
|
'#type' => 'html_tag',
|
|
'#tag' => 'script',
|
|
'#attributes' => ['type' => 'module', 'src' => "https://localhost:{$port}/assets/js/main.js"],
|
|
],
|
|
'vite-main',
|
|
];
|
|
}else{
|
|
$page['#attached']['library'][] = 'mathallo/global';
|
|
}
|
|
}
|
|
/**
|
|
* Implements hook_preprocess_HOOK() for html.html.twig.
|
|
*/
|
|
function mathallo_preprocess_html(&$variables) {
|
|
}
|
|
|
|
/**
|
|
* Implements hook_preprocess_HOOK() for page.html.twig.
|
|
*/
|
|
function mathallo_preprocess_page(&$variables) {
|
|
|
|
}
|
|
|
|
function mathallo_preprocess_region(&$variables) {
|
|
if (!isset($variables["attributes"]['class'])) {
|
|
$variables["attributes"]['class'] = [];
|
|
}
|
|
$variables["attributes"]['class'][] = "wrapper";
|
|
}
|
|
|
|
|
|
// function mathallo_preprocess_block__mathallo_contenu(&$variables) {
|
|
function mathallo_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 mathallo_preprocess_node(&$variables) {
|
|
$node_type = $variables['node']->getType();
|
|
if (!isset($variables["attributes"]['class'])) {
|
|
$variables["attributes"]['class'] = [];
|
|
}
|
|
$variables["attributes"]['class'][] = "node-type-{$node_type}";
|
|
}
|
|
|
|
|
|
function mathallo_preprocess_contanier(&$variables) {
|
|
|
|
}
|
|
|
|
/**
|
|
* Implements hook_preprocess_HOOK() for node.html.twig.
|
|
*/
|
|
function mathallo_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'];
|
|
}
|