| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 | 
							- <?php
 
- /*
 
- 	* @files
 
- 	* Theme Template Funtions
 
- */
 
- // use Drupal\Core\Template\Attribute;
 
- // use Drupal\Core\Link;
 
- // use Drupal\Core\Url;
 
- use Drupal\Component\Utility\Html;
 
- use Drupal\Component\Transliteration\TransliterationInterface;
 
- use Drupal\taxonomy\Entity\Term;
 
- use Drupal\Core\Template\Attribute;
 
- use Drupal\node\NodeInterface;
 
- function eql_preprocess_html(&$variables) {
 
-   $node = \Drupal::routeMatch()->getParameter('node');
 
-   if ($node instanceof \Drupal\node\NodeInterface) {
 
-     $variables['attributes']['class'][] = 'node-type-' . $node->bundle();
 
-     $variables['attributes']['class'][] = 'node-id-' . $node->id();
 
-     // Liste des champs à traiter pour générer des classes dynamiques
 
-     $fields_to_classify = [
 
-       'field_type_de_ressource' => 'type-',
 
-       'field_type_de_media'     => 'type-media-',
 
-     ];
 
-     foreach ($fields_to_classify as $field_name => $prefix) {
 
-       if ($node->hasField($field_name) && !$node->get($field_name)->isEmpty()) {
 
-         foreach ($node->get($field_name)->referencedEntities() as $term) {
 
-           $label = $term->label();
 
-           $css_class = $prefix . Html::cleanCssIdentifier(strtolower($label));
 
-           $variables['attributes']['class'][] = $css_class;
 
-         }
 
-       }
 
-     }
 
-   }
 
- }
 
- function eql_preprocess_node(&$variables){
 
-   $node = &$variables['node'];
 
-   $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
 
-   if($node->gettype() == "actualite") {
 
-     $actu_type = $node->get('field_actu_type')->getString();
 
-     $variables['attributes']['class'][] = 'actu-type-' . $actu_type;
 
-   }
 
-   if($node->gettype() == "offre_de_service") {
 
-     $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
 
-     $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
 
-   }
 
-   if ($node->getType() === 'ressource' && $node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
 
-     foreach ($node->get('field_type_de_ressource')->referencedEntities() as $term) {
 
-       $label = $term->label(); // ex: "Presse"
 
-       $class = 'type-' . Html::cleanCssIdentifier(strtolower($label));
 
-       $variables['attributes']['class'][] = $class;
 
-     }
 
-   }
 
- }
 
- function eql_preprocess_page(array &$variables) {
 
-   $node = \Drupal::routeMatch()->getParameter('node');
 
-   if ($node instanceof \Drupal\node\NodeInterface && $node->bundle() === 'ressource') {
 
-     if ($node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
 
-       foreach ($node->get('field_type_de_ressource')->referencedEntities() as $term) {
 
-         $label = $term->label();
 
-         $css_class = 'type-' . \Drupal\Component\Utility\Html::getClass($label);
 
-         // S'assurer que les attributs existent
 
-         if (!isset($variables['page']['top']['#attributes'])) {
 
-           $variables['page']['top']['#attributes'] = ['class' => []];
 
-         }
 
-         $variables['page']['top']['#attributes']['class'][] = $css_class;
 
-       }
 
-     }
 
-   }
 
- }
 
- function eql_preprocess_block(array &$variables) {
 
-   // Vérifie si on est sur une page node de type 'ressource'
 
-   $route_match = \Drupal::routeMatch();
 
-   $node = $route_match->getParameter('node');
 
-   if ($node instanceof \Drupal\node\NodeInterface && $node->bundle() === 'ressource') {
 
-     $variables['is_ressource_page'] = TRUE;
 
-   }
 
-   else {
 
-     $variables['is_ressource_page'] = FALSE;
 
-   }
 
- }
 
- function eql_preprocess_field(&$variables) {
 
-   $node = \Drupal::routeMatch()->getParameter('node');
 
-   $field_name = &$variables['field_name'];
 
-   if($node) {
 
-     if ($field_name == 'field_type_de_protagoniste'){
 
-     $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
 
-     $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
 
-     }
 
-   }
 
-   $field_name = &$variables['field_name'];
 
-   if($node) {
 
-     if ($field_name == 'field-type-de-ressource'){
 
-       $type_ressource = $node->get('field-type-de-ressource')->getString();
 
-       $variables['attributes']['class'][] = 'type-de-ressource-' . $type_ressource;
 
-       }
 
-   }
 
- }
 
- ////////////
 
- function eql_preprocess_layout__threecol_25_50_25(&$variables) {
 
-   $node = \Drupal::routeMatch()->getParameter('node');
 
-   if($node->gettype() == "projet"){
 
-     $variables['content']['top_bottom'] = [];     /////// déclare les nvx array 
 
-     $variables['content']['top_right'] = [];
 
-     $variables['content']['top_left'] = [];
 
-     $variables['content']['top_bottom_left'] = [];
 
-     foreach ($variables['content']['top'] as $key => $value) {
 
-       if(isset($value['#base_plugin_id']) && $value['#base_plugin_id']== 'entity_field'){      ////// isset pour voir si existe && si oui fait ce que tu as à faire. $Value c'est l'attribut  
 
-         if($value['#derivative_plugin_id']=="node:field_region" || $value['#derivative_plugin_id']=="node:field_adresse") {
 
-           $variables['content']['top_bottom_left'][] = $variables['content']['top'][$key];
 
-           unset($variables["content"]["top"][$key]); 
 
-         }
 
-         if($value['#derivative_plugin_id']=="node:field_type_de_moa" || $value['#derivative_plugin_id']=="node:field_type_de_projet" || $value['#derivative_plugin_id']=="node:field_etape_du_projet") {
 
-           $variables['content']['top_bottom'][] = $variables['content']['top'][$key];
 
-           unset($variables["content"]["top"][$key]); 
 
-         } 
 
-         if($value['#derivative_plugin_id']=="node:title" || $value['#derivative_plugin_id']=="node:field_equipe" || $value['#derivative_plugin_id']=="node:field_incube"){
 
-           $variables['content']['top_right'][] = $variables['content']['top'][$key];
 
-           unset($variables["content"]["top"][$key]);
 
-         }
 
-         if($value['#derivative_plugin_id']=="node:field_photo"){
 
-           $variables['content']['top_left'][] = $variables['content']['top'][$key];
 
-           unset($variables["content"]["top"][$key]);
 
-         }
 
-       }
 
-     }
 
-   }
 
-   if ($node && $node->getType() === 'ressource') {
 
-     if ($node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
 
-       $terms = $node->get('field_type_de_ressource')->referencedEntities();
 
-       if (!empty($terms)) {
 
-         foreach ($terms as $term) {
 
-           if ($term instanceof \Drupal\taxonomy\Entity\Term) {
 
-             $label = $term->label();
 
-             $css_class = 'type-' . \Drupal\Component\Utility\Html::cleanCssIdentifier(strtolower($label));
 
-       
 
-             if (!isset($variables['region_attributes']['top'])) {
 
-               $variables['region_attributes']['top'] = new \Drupal\Core\Template\Attribute();
 
-             }
 
-       
 
-             $variables['region_attributes']['top']->addClass($css_class);
 
-           }
 
-         }
 
-       }
 
-     }
 
-        // Champ : field_type_de_media
 
-   if ($node->hasField('field_type_de_media') && !$node->get('field_type_de_media')->isEmpty()) {
 
-     $terms = $node->get('field_type_de_media')->referencedEntities();
 
-     foreach ($terms as $term) {
 
-       if ($term instanceof \Drupal\taxonomy\Entity\Term) {
 
-         $media_label = $term->label();
 
-         $css_class = 'type-media-' . \Drupal\Component\Utility\Html::cleanCssIdentifier(strtolower($media_label));
 
-         if (!isset($variables['region_attributes']['top'])) {
 
-           $variables['region_attributes']['top'] = new \Drupal\Core\Template\Attribute();
 
-         }
 
-         $variables['region_attributes']['top']->addClass($css_class);
 
-       }
 
-     }
 
-   }
 
- }
 
- }
 
- function eql_preprocess_views_view_unformatted(array &$variables) {
 
-   $view = $variables['view'];
 
-   if ($view->id() !== 'base_de_donnees') {
 
-     return;
 
-   }
 
-   $transliterator = \Drupal::service('transliteration');
 
-   $current_path = \Drupal::service('path.current')->getPath();
 
-   $request = \Drupal::request();
 
-   $query_params = $request->query->all();
 
-   // Active uniquement si on est sur la page /ressources sans filtres actifs
 
-   $is_ressource_main = $current_path === '/ressources';
 
-   $has_filters = !empty(array_filter($query_params, fn($v) => $v !== '' && $v !== 'All'));
 
-   $filter_slides = $is_ressource_main && !$has_filters;
 
-   // Liste des types à restreindre uniquement sur /ressources sans filtres
 
-   $allowed_types = [
 
-     'type-paroles-de-laureats',
 
-     'type-publications-issues-du-programme',
 
-     'type-presse',
 
-     'type-les-projets-en-images',
 
-     // 'type-autres',
 
-     // 'type-evenements',
 
-     'type-publications-des-partenaires-et-laureats',
 
-   ];
 
-   $slides = [];
 
-   $unclassified_rows = [];
 
-   foreach ($variables['rows'] as $row) {
 
-     if (!isset($row['content']['#node'])) {
 
-       $unclassified_rows[] = $row;
 
-       continue;
 
-     }
 
-     $node = $row['content']['#node'];
 
-     $matched = false;
 
-     if ($node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
 
-       foreach ($node->get('field_type_de_ressource')->referencedEntities() as $term) {
 
-         $label = $term->label();
 
-         $tid = $term->id(); // <-- on récupère l'ID
 
-         $label_ascii = $transliterator->transliterate($label);
 
-         $type_class = 'type-' . Html::cleanCssIdentifier(strtolower($label_ascii));
 
-         // Init slide si non encore créé
 
-         if (!isset($slides[$type_class])) {
 
-           $slides[$type_class] = [
 
-             'label' => $label,
 
-             'tid' => $term->id(),
 
-             'rows' => [],
 
-           ];
 
-         }
 
-         // Ajouter la row dans le slide
 
-         $slides[$type_class]['rows'][] = $row;
 
-         $matched = true;
 
-         // Ajouter la classe CSS à la row
 
-         $row['attributes']->addClass($type_class);
 
-         // Ajouter aussi à l'article si possible
 
-         if (!isset($row['content']['#attributes']) || !($row['content']['#attributes'] instanceof Attribute)) {
 
-           $row['content']['#attributes'] = new Attribute();
 
-         }
 
-         $row['content']['#attributes']->addClass($type_class);
 
-       }
 
-     }
 
-     if (!$matched) {
 
-       $unclassified_rows[] = $row;
 
-     }
 
-   }
 
-   // Appliquer le filtrage final si sur la page principale
 
-   $variables['grouped_rows'] = $filter_slides
 
-     ? array_filter($slides, fn($key) => in_array($key, $allowed_types), ARRAY_FILTER_USE_KEY)
 
-     : $slides;
 
-   $variables['unclassified_rows'] = $unclassified_rows;
 
-   $variables['rows'] = []; // désactive affichage par défaut
 
-   $variables['is_filtered'] = !$filter_slides;
 
- }
 
- function eql_preprocess_form(&$variables) {
 
-   $terms = \Drupal::entityTypeManager()
 
-     ->getStorage('taxonomy_term')
 
-     ->loadTree('type_de_media');
 
-   $transliterator = \Drupal::service('transliteration');
 
-   $media_links = [];
 
-   // Récupère la valeur actuelle du filtre dans l’URL
 
-   $request = \Drupal::request();
 
-   $active_tid = $request->query->get('field_type_de_media_target_id');
 
-   foreach ($terms as $term) {
 
-     $slug = Html::cleanCssIdentifier(strtolower($transliterator->transliterate($term->name)));
 
-     $slug = Html::cleanCssIdentifier($slug); // Nettoie pour CSS
 
-     $media_links[] = [
 
-       'tid' => $term->tid,
 
-       'label' => $term->name,
 
-       'slug' => $slug,
 
-       'active' => (string)$term->tid === $active_tid, // <-- True si c'est celui sélectionné
 
-     ];
 
-   }
 
-   $variables['media_links'] = $media_links;
 
- }
 
 
  |