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