eql.theme 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }
  24. ///////////////////////////////////////////////////
  25. // counter pour id
  26. // function eql_preprocess_field(&$variables) {
  27. // // static $counter = 0;
  28. // // $variables['counter'] = $counter++;
  29. // $variables['elements']['#paragraph']->item_id;
  30. // }
  31. // la fonction suivante ne fonctionne pas
  32. // function eql_preprocess_field(&$variables) {
  33. // $paragraph = &$variables['paragraph'];
  34. // $variables['attributes']['class'][] = 'paragraph-type-' . $paragraph->id();
  35. // $hook_id = $paragraph->get('paragraph-id--')->getString();
  36. // $variables['attributes']['class'][] = 'hook-id-' . $hook_id;
  37. // }
  38. //might be useful for if-clause: $variables['field_name'] and $variables['field_type']
  39. // if ($paragraph && $paragraph->getEntityTypeId() == 'paragraph' . $paragraph->id() ) {
  40. //whatever logic you need goes here, e.g. something like
  41. //$variables['attributes']['data-from-parent-paragraph'] = $parentEntity->getYourStuff();
  42. // }
  43. // function yourtheme_preprocess_field(&$variables, $hook) {
  44. // $element = $variables['element'];
  45. // $parentEntity = $element['#object'];
  46. // //might be useful for if-clause: $variables['field_name'] and $variables['field_type']
  47. // if ($parentEntity && $parentEntity->getEntityTypeId() == 'paragraph' ) {
  48. // //whatever logic you need goes here, e.g. something like
  49. // //$variables['attributes']['data-from-parent-paragraph'] = $parentEntity->getYourStuff();
  50. // }
  51. // }
  52. // $variables['elements']['#entity']->item_id;
  53. // function MYTHEME_preprocess_views_view_fields__view_machine_name(&$vars) {
  54. // static $counter = 0;
  55. // $vars['counter'] = $counter++;
  56. // }