eql.theme 3.9 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 = $node->get('field_type_de_ressource')->entity->getName();
  32. // Ajoute la classe CSS basée sur la valeur du type de ressource
  33. $variables['attributes']['class'][] = 'type-de-ressource-' . Html::cleanCssIdentifier($type_de_ressource);
  34. }
  35. }
  36. function eql_preprocess_field(&$variables) {
  37. $node = \Drupal::routeMatch()->getParameter('node');
  38. $field_name = &$variables['field_name'];
  39. if($node) {
  40. if ($field_name == 'field_type_de_protagoniste'){
  41. $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
  42. $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
  43. }
  44. }
  45. $field_name = &$variables['field_name'];
  46. if($node) {
  47. if ($field_name == 'field-type-de-ressource'){
  48. $type_ressource = $node->get('field-type-de-ressource')->getString();
  49. $variables['attributes']['class'][] = 'type-de-ressource-' . $type_ressource;
  50. }
  51. }
  52. }
  53. ////////////
  54. function eql_preprocess_layout__threecol_25_50_25(&$variables) {
  55. $node = \Drupal::routeMatch()->getParameter('node');
  56. if($node->gettype() == "projet"){
  57. $variables['content']['top_bottom'] = []; /////// déclare les nvx array
  58. $variables['content']['top_right'] = [];
  59. $variables['content']['top_left'] = [];
  60. $variables['content']['top_bottom_left'] = [];
  61. foreach ($variables['content']['top'] as $key => $value) {
  62. 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
  63. if($value['#derivative_plugin_id']=="node:field_region" || $value['#derivative_plugin_id']=="node:field_adresse") {
  64. $variables['content']['top_bottom_left'][] = $variables['content']['top'][$key];
  65. unset($variables["content"]["top"][$key]);
  66. }
  67. 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") {
  68. $variables['content']['top_bottom'][] = $variables['content']['top'][$key];
  69. unset($variables["content"]["top"][$key]);
  70. }
  71. if($value['#derivative_plugin_id']=="node:title" || $value['#derivative_plugin_id']=="node:field_equipe" || $value['#derivative_plugin_id']=="node:field_incube"){
  72. $variables['content']['top_right'][] = $variables['content']['top'][$key];
  73. unset($variables["content"]["top"][$key]);
  74. }
  75. if($value['#derivative_plugin_id']=="node:field_photo"){
  76. $variables['content']['top_left'][] = $variables['content']['top'][$key];
  77. unset($variables["content"]["top"][$key]);
  78. }
  79. }
  80. }
  81. }
  82. }