eql.theme 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. // /**
  29. // * Implements hook_preprocess_field().
  30. // */
  31. // function eql_preprocess_field(&$variables) {
  32. // $node = \Drupal::routeMatch()->getParameter('node');
  33. // if($node) {
  34. // $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
  35. // $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
  36. // }
  37. // }
  38. // function eql_preprocess_field(&$variables){
  39. // $node = &$variables['node'];
  40. // $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
  41. // if($node->gettype() == "offre_de_service") {
  42. // $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
  43. // $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
  44. // }
  45. // }
  46. // function MYTHEME_preprocess_field__MYFIELD(&$variables) {
  47. // if ($variables['element']['#entity_type'] === 'node') {
  48. // $node = $variables['element']['#object'];
  49. // $nid = $node->id();
  50. // $variables['myurl'] = \Drupal::service('path.alias_manager')->getAliasByPath('/node/' . $nid);
  51. // }
  52. // }
  53. // function template_preprocess_block(&$variables) {
  54. // $node = &$variables['node'];
  55. // $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
  56. // if($node->gettype() == "offre_de_service") {
  57. // $type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
  58. // $variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
  59. // }
  60. // }
  61. ///////////////////////////////////////////////////
  62. ///////////////////////////////////////////////////
  63. // counter pour id
  64. // function eql_preprocess_field(&$variables) {
  65. // // static $counter = 0;
  66. // // $variables['counter'] = $counter++;
  67. // $variables['elements']['#paragraph']->item_id;
  68. // }
  69. // la fonction suivante ne fonctionne pas
  70. // function eql_preprocess_field(&$variables) {
  71. // $paragraph = &$variables['paragraph'];
  72. // $variables['attributes']['class'][] = 'paragraph-type-' . $paragraph->id();
  73. // $hook_id = $paragraph->get('paragraph-id--')->getString();
  74. // $variables['attributes']['class'][] = 'hook-id-' . $hook_id;
  75. // }
  76. //might be useful for if-clause: $variables['field_name'] and $variables['field_type']
  77. // if ($paragraph && $paragraph->getEntityTypeId() == 'paragraph' . $paragraph->id() ) {
  78. //whatever logic you need goes here, e.g. something like
  79. //$variables['attributes']['data-from-parent-paragraph'] = $parentEntity->getYourStuff();
  80. // }
  81. // function yourtheme_preprocess_field(&$variables, $hook) {
  82. // $element = $variables['element'];
  83. // $parentEntity = $element['#object'];
  84. // //might be useful for if-clause: $variables['field_name'] and $variables['field_type']
  85. // if ($parentEntity && $parentEntity->getEntityTypeId() == 'paragraph' ) {
  86. // //whatever logic you need goes here, e.g. something like
  87. // //$variables['attributes']['data-from-parent-paragraph'] = $parentEntity->getYourStuff();
  88. // }
  89. // }
  90. // $variables['elements']['#entity']->item_id;
  91. // function MYTHEME_preprocess_views_view_fields__view_machine_name(&$vars) {
  92. // static $counter = 0;
  93. // $vars['counter'] = $counter++;
  94. // }