123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?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;
- function eql_preprocess_html(&$variables) {
- $node = \Drupal::routeMatch()->getParameter('node');
- if ($node){
- $variables['attributes']['class'][] = 'node-type-' . $node->bundle();
- $variables['attributes']['class'][] = 'node-id-' . $node->id();
- }
- }
- 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->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
- // // Récupère la valeur de field_type_de_ressource
- // $type_de_ressource_entity = $node->get('field_type_de_ressource')->entity;
- // if ($type_de_ressource_entity) {
- // $type_de_ressource_name = $type_de_ressource_entity->getName();
- // // Ajoute la classe CSS basée sur la valeur du type de ressource
- // $variables['attributes']['class'][] = 'type-de-ressource-' . Html::cleanCssIdentifier($type_de_ressource_name);
- // }
- // }
- 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_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]);
- }
- }
- }
- }
- }
- function eql_preprocess_views_view_unformatted(&$variables) {
- // On utilise le service de translittération de Drupal
- $transliterator = \Drupal::service('transliteration');
- foreach ($variables['rows'] as &$row) {
- if (isset($row['content']['#node'])) {
- $node = $row['content']['#node'];
- 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();
- // Supprimer les accents
- $label_ascii = $transliterator->transliterate($label);
- // Nettoyer pour que ce soit une classe CSS valide
- $class = 'type-' . Html::cleanCssIdentifier(strtolower($label_ascii));
- $row['attributes']->addClass($class);
- }
- }
- }
- }
- }
|