rorschach.theme 4.5 KB

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