eql.theme 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /*
  3. * @files
  4. * Theme Template Funtions
  5. */
  6. // use Drupal\Core\Template\Attribute;
  7. // use Drupal\Core\Link;
  8. // use Drupal\Core\Url;
  9. use Drupal\Component\Utility\Html;
  10. use Drupal\Component\Transliteration\TransliterationInterface;
  11. function eql_preprocess_html(&$variables) {
  12. $node = \Drupal::routeMatch()->getParameter('node');
  13. if ($node){
  14. $variables['attributes']['class'][] = 'node-type-' . $node->bundle();
  15. $variables['attributes']['class'][] = 'node-id-' . $node->id();
  16. }
  17. }
  18. function eql_preprocess_node(&$variables){
  19. $node = &$variables['node'];
  20. $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
  21. if($node->gettype() == "actualite") {
  22. $actu_type = $node->get('field_actu_type')->getString();
  23. $variables['attributes']['class'][] = 'actu-type-' . $actu_type;
  24. }
  25. if($node->gettype() == "offre_de_service") {
  26. $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
  27. $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
  28. }
  29. // if ($node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
  30. // // Récupère la valeur de field_type_de_ressource
  31. // $type_de_ressource_entity = $node->get('field_type_de_ressource')->entity;
  32. // if ($type_de_ressource_entity) {
  33. // $type_de_ressource_name = $type_de_ressource_entity->getName();
  34. // // Ajoute la classe CSS basée sur la valeur du type de ressource
  35. // $variables['attributes']['class'][] = 'type-de-ressource-' . Html::cleanCssIdentifier($type_de_ressource_name);
  36. // }
  37. // }
  38. if ($node->getType() === 'ressource' && $node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
  39. foreach ($node->get('field_type_de_ressource')->referencedEntities() as $term) {
  40. $label = $term->label(); // ex: "Presse"
  41. $class = 'type-' . Html::cleanCssIdentifier(strtolower($label));
  42. $variables['attributes']['class'][] = $class;
  43. }
  44. }
  45. }
  46. function eql_preprocess_field(&$variables) {
  47. $node = \Drupal::routeMatch()->getParameter('node');
  48. $field_name = &$variables['field_name'];
  49. if($node) {
  50. if ($field_name == 'field_type_de_protagoniste'){
  51. $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
  52. $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
  53. }
  54. }
  55. $field_name = &$variables['field_name'];
  56. if($node) {
  57. if ($field_name == 'field-type-de-ressource'){
  58. $type_ressource = $node->get('field-type-de-ressource')->getString();
  59. $variables['attributes']['class'][] = 'type-de-ressource-' . $type_ressource;
  60. }
  61. }
  62. }
  63. ////////////
  64. function eql_preprocess_layout__threecol_25_50_25(&$variables) {
  65. $node = \Drupal::routeMatch()->getParameter('node');
  66. if($node->gettype() == "projet"){
  67. $variables['content']['top_bottom'] = []; /////// déclare les nvx array
  68. $variables['content']['top_right'] = [];
  69. $variables['content']['top_left'] = [];
  70. $variables['content']['top_bottom_left'] = [];
  71. foreach ($variables['content']['top'] as $key => $value) {
  72. 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
  73. if($value['#derivative_plugin_id']=="node:field_region" || $value['#derivative_plugin_id']=="node:field_adresse") {
  74. $variables['content']['top_bottom_left'][] = $variables['content']['top'][$key];
  75. unset($variables["content"]["top"][$key]);
  76. }
  77. 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") {
  78. $variables['content']['top_bottom'][] = $variables['content']['top'][$key];
  79. unset($variables["content"]["top"][$key]);
  80. }
  81. if($value['#derivative_plugin_id']=="node:title" || $value['#derivative_plugin_id']=="node:field_equipe" || $value['#derivative_plugin_id']=="node:field_incube"){
  82. $variables['content']['top_right'][] = $variables['content']['top'][$key];
  83. unset($variables["content"]["top"][$key]);
  84. }
  85. if($value['#derivative_plugin_id']=="node:field_photo"){
  86. $variables['content']['top_left'][] = $variables['content']['top'][$key];
  87. unset($variables["content"]["top"][$key]);
  88. }
  89. }
  90. }
  91. }
  92. }
  93. function eql_preprocess_views_view_unformatted(&$variables) {
  94. // On utilise le service de translittération de Drupal
  95. $transliterator = \Drupal::service('transliteration');
  96. foreach ($variables['rows'] as &$row) {
  97. if (isset($row['content']['#node'])) {
  98. $node = $row['content']['#node'];
  99. if ($node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
  100. foreach ($node->get('field_type_de_ressource')->referencedEntities() as $term) {
  101. $label = $term->label();
  102. // Supprimer les accents
  103. $label_ascii = $transliterator->transliterate($label);
  104. // Nettoyer pour que ce soit une classe CSS valide
  105. $class = 'type-' . Html::cleanCssIdentifier(strtolower($label_ascii));
  106. $row['attributes']->addClass($class);
  107. }
  108. }
  109. }
  110. }
  111. }