eql.theme 4.8 KB

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