rorschach.theme 4.8 KB

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