eql.theme 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. function eql_preprocess_html(&$variables) {
  10. $node = \Drupal::routeMatch()->getParameter('node');
  11. if ($node){
  12. $variables['attributes']['class'][] = 'node-type-' . $node->bundle();
  13. $variables['attributes']['class'][] = 'node-id-' . $node->id();
  14. }
  15. }
  16. function eql_preprocess_node(&$variables){
  17. $node = &$variables['node'];
  18. $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
  19. // $variables['elements']['content_bottom'] = []; /////////////////////////////
  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. // foreach ($variables['elements'] as $key => $value){ //////////////////////////////////
  29. // if(isset($value['#view_mode']) && $value['#view_mode']== 'teaser'){
  30. // if($value['elements']=="field_region" || $value['#derivative_plugin_id']=="node:field_adresse"){
  31. // $variables['elements']['content_bottom'][] = $variables["elements"]["field_incube"]["#field_name"];
  32. // }
  33. // }
  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. }
  46. ////////////
  47. function eql_preprocess_layout__threecol_25_50_25(&$variables) {
  48. $node = \Drupal::routeMatch()->getParameter('node');
  49. // $node = &$variables['node'];
  50. // $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
  51. if($node->gettype() == "projet"){
  52. $variables['content']['top_bottom'] = []; /////// déclare les nvx array
  53. $variables['content']['top_right'] = [];
  54. $variables['content']['top_left'] = [];
  55. $variables['content']['top_bottom_left'] = [];
  56. foreach ($variables['content']['top'] as $key => $value) {
  57. 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
  58. if($value['#derivative_plugin_id']=="node:field_region" || $value['#derivative_plugin_id']=="node:field_adresse") {
  59. $variables['content']['top_bottom_left'][] = $variables['content']['top'][$key];
  60. unset($variables["content"]["top"][$key]);
  61. }
  62. 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") {
  63. $variables['content']['top_bottom'][] = $variables['content']['top'][$key];
  64. unset($variables["content"]["top"][$key]);
  65. }
  66. // foreach ($variables['content']['top_bottom'] as $key => $value) {
  67. // }
  68. if($value['#derivative_plugin_id']=="node:title" || $value['#derivative_plugin_id']=="node:field_equipe" || $value['#derivative_plugin_id']=="node:field_incube"){
  69. $variables['content']['top_right'][] = $variables['content']['top'][$key];
  70. unset($variables["content"]["top"][$key]);
  71. }
  72. if($value['#derivative_plugin_id']=="node:field_photo"){
  73. $variables['content']['top_left'][] = $variables['content']['top'][$key];
  74. unset($variables["content"]["top"][$key]);
  75. }
  76. }
  77. }
  78. }
  79. }
  80. // function eql_preprocess_views_row_plugins(&$variables){
  81. // $t = 't';
  82. // }
  83. //////////////////////////////////////////////////
  84. // function eql_preprocess_input(&$variables) {
  85. // $form = \Drupal::routeMatch()->getParameter('form');
  86. // $form['keys']['#attributes']['placeholder'] = t('The new placeholder');
  87. // }
  88. // function eql_preprocess_field(&$variables){
  89. // $node = &$variables['node'];
  90. // $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
  91. // if($node->gettype() == "offre_de_service") {
  92. // $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
  93. // $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
  94. // }
  95. // }
  96. // function MYTHEME_preprocess_field__MYFIELD(&$variables) {
  97. // if ($variables['element']['#entity_type'] === 'node') {
  98. // $node = $variables['element']['#object'];
  99. // $nid = $node->id();
  100. // $variables['myurl'] = \Drupal::service('path.alias_manager')->getAliasByPath('/node/' . $nid);
  101. // }
  102. // }
  103. // function template_preprocess_block(&$variables) {
  104. // $node = &$variables['node'];
  105. // $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
  106. // if($node->gettype() == "offre_de_service") {
  107. // $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
  108. // $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
  109. // }
  110. // }
  111. ///////////////////////////////////////////////////
  112. ///////////////////////////////////////////////////
  113. // counter pour id
  114. // function eql_preprocess_field(&$variables) {
  115. // // static $counter = 0;
  116. // // $variables['counter'] = $counter++;
  117. // $variables['elements']['#paragraph']->item_id;
  118. // }
  119. // la fonction suivante ne fonctionne pas
  120. // function eql_preprocess_field(&$variables) {
  121. // $paragraph = &$variables['paragraph'];
  122. // $variables['attributes']['class'][] = 'paragraph-type-' . $paragraph->id();
  123. // $hook_id = $paragraph->get('paragraph-id--')->getString();
  124. // $variables['attributes']['class'][] = 'hook-id-' . $hook_id;
  125. // }
  126. //might be useful for if-clause: $variables['field_name'] and $variables['field_type']
  127. // if ($paragraph && $paragraph->getEntityTypeId() == 'paragraph' . $paragraph->id() ) {
  128. //whatever logic you need goes here, e.g. something like
  129. //$variables['attributes']['data-from-parent-paragraph'] = $parentEntity->getYourStuff();
  130. // }
  131. // function yourtheme_preprocess_field(&$variables, $hook) {
  132. // $element = $variables['element'];
  133. // $parentEntity = $element['#object'];
  134. // //might be useful for if-clause: $variables['field_name'] and $variables['field_type']
  135. // if ($parentEntity && $parentEntity->getEntityTypeId() == 'paragraph' ) {
  136. // //whatever logic you need goes here, e.g. something like
  137. // //$variables['attributes']['data-from-parent-paragraph'] = $parentEntity->getYourStuff();
  138. // }
  139. // }
  140. // $variables['elements']['#entity']->item_id;
  141. // function MYTHEME_preprocess_views_view_fields__view_machine_name(&$vars) {
  142. // static $counter = 0;
  143. // $vars['counter'] = $counter++;
  144. // }