eql.theme 6.7 KB

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