eql.theme 6.3 KB

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