eql.theme 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. function eql_preprocess_html(&$variables) {
  11. $node = \Drupal::routeMatch()->getParameter('node');
  12. if ($node){
  13. $variables['attributes']['class'][] = 'node-type-' . $node->bundle();
  14. $variables['attributes']['class'][] = 'node-id-' . $node->id();
  15. }
  16. }
  17. function eql_preprocess_node(&$variables){
  18. $node = &$variables['node'];
  19. $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
  20. if($node->gettype() == "actualite") {
  21. $actu_type = $node->get('field_actu_type')->getString();
  22. $variables['attributes']['class'][] = 'actu-type-' . $actu_type;
  23. }
  24. if($node->gettype() == "offre_de_service") {
  25. $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
  26. $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
  27. }
  28. // Vérifie si le champ field_type_de_ressource existe et ajoute une classe basée sur sa valeur
  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. }
  39. function eql_preprocess_field(&$variables) {
  40. $node = \Drupal::routeMatch()->getParameter('node');
  41. $field_name = &$variables['field_name'];
  42. if($node) {
  43. if ($field_name == 'field_type_de_protagoniste'){
  44. $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
  45. $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
  46. }
  47. }
  48. $field_name = &$variables['field_name'];
  49. if($node) {
  50. if ($field_name == 'field-type-de-ressource'){
  51. $type_ressource = $node->get('field-type-de-ressource')->getString();
  52. $variables['attributes']['class'][] = 'type-de-ressource-' . $type_ressource;
  53. }
  54. }
  55. }
  56. ////////////
  57. function eql_preprocess_layout__threecol_25_50_25(&$variables) {
  58. $node = \Drupal::routeMatch()->getParameter('node');
  59. if($node->gettype() == "projet"){
  60. $variables['content']['top_bottom'] = []; /////// déclare les nvx array
  61. $variables['content']['top_right'] = [];
  62. $variables['content']['top_left'] = [];
  63. $variables['content']['top_bottom_left'] = [];
  64. foreach ($variables['content']['top'] as $key => $value) {
  65. 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
  66. if($value['#derivative_plugin_id']=="node:field_region" || $value['#derivative_plugin_id']=="node:field_adresse") {
  67. $variables['content']['top_bottom_left'][] = $variables['content']['top'][$key];
  68. unset($variables["content"]["top"][$key]);
  69. }
  70. 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") {
  71. $variables['content']['top_bottom'][] = $variables['content']['top'][$key];
  72. unset($variables["content"]["top"][$key]);
  73. }
  74. if($value['#derivative_plugin_id']=="node:title" || $value['#derivative_plugin_id']=="node:field_equipe" || $value['#derivative_plugin_id']=="node:field_incube"){
  75. $variables['content']['top_right'][] = $variables['content']['top'][$key];
  76. unset($variables["content"]["top"][$key]);
  77. }
  78. if($value['#derivative_plugin_id']=="node:field_photo"){
  79. $variables['content']['top_left'][] = $variables['content']['top'][$key];
  80. unset($variables["content"]["top"][$key]);
  81. }
  82. }
  83. }
  84. }
  85. }