eql.theme 4.5 KB

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