edlptheme.theme 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * @file
  4. * Functions to support theming in the edlp theme.
  5. */
  6. use Drupal\Core\Url;
  7. use Drupal\Core\Form\FormStateInterface;
  8. use Drupal\Core\Template\Attribute;
  9. // function edlptheme_preprocess_input(&$vars){
  10. // dsm($vars, 'vars');
  11. // $vars['attributes']['placeholder'] = "salut";
  12. // }
  13. function edlptheme_preprocess_node(&$vars){
  14. $node = $vars['elements']['#node'];
  15. $options = ['absolute' => TRUE];
  16. $url = Url::fromRoute('entity.node.canonical', ['node' => $node->id()], $options);
  17. $system_path = $url->getInternalPath();
  18. $vars['link_attributes'] = new Attribute(array(
  19. 'data-drupal-link-system-path' => $system_path=='' ? '<front>' : $system_path
  20. ));
  21. }
  22. /**
  23. * Implements hook_form_alter
  24. */
  25. function edlptheme_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  26. // dpm($form_id, 'form_id');
  27. // dpm($form, 'form');
  28. $form['name']['#attributes']['placeholder'] = (string) $form['name']['#title'];
  29. unset($form['name']['#title']);
  30. $form['pass']['#attributes']['placeholder'] = (string) $form['pass']['#title'];
  31. unset($form['pass']['#title']);
  32. }
  33. function edlptheme_preprocess_edlp_productions(&$vars){
  34. foreach($vars['nodes'] as &$node){
  35. switch($node['vm']){
  36. case "image_2_columns":
  37. $cols = 4;
  38. break;
  39. case "image_1_columns":
  40. $cols = 2;
  41. break;
  42. case "text_1_column":
  43. $cols = 2;
  44. break;
  45. };
  46. $node['cols'] = $cols;
  47. }
  48. // dpm($vars);
  49. }
  50. function edlptheme_preprocess_node__enregistrement__index(&$vars){
  51. $node = $vars['elements']['#node'];
  52. $options = ['absolute' => TRUE];
  53. $url = Url::fromRoute('entity.node.canonical', ['node' => $node->id()], $options);
  54. $system_path = $url->getInternalPath();
  55. // get the audio file url
  56. $field_son_values = $node->get('field_son')->getValue();
  57. $son_fid = count($field_son_values) ? $field_son_values[0]['target_id'] : "";
  58. $son_file = \Drupal\file\Entity\File::load($son_fid);
  59. $son_url = null;
  60. if($son_file){
  61. $son_uri = $son_file->getFileUri();
  62. $son_url = file_create_url($son_uri);
  63. }
  64. $vars['link_attributes'] = new Attribute(array(
  65. 'data-drupal-link-system-path' => $system_path=='' ? '<front>' : $system_path,
  66. 'audio_url' => $son_url,
  67. 'nid' => $node->id(),
  68. 'class' => array('audio-link', 'ajax-link')
  69. ));
  70. // dpm($vars['link_attributes']);
  71. }
  72. function edlptheme_preprocess_node__enregistrement__player_cartel(&$vars){
  73. // dpm($vars);
  74. // if transcript not empty
  75. $url = Url::fromRoute('entity.node.canonical', ['node'=>$vars['node']->id()], array(
  76. 'attributes' => array(
  77. 'class' => ['link-transcript', 'ajax-link'],
  78. 'viewmode'=>'transcript'
  79. )
  80. ));
  81. $vars['link_transcript'] = array(
  82. '#title' => t("Lire le text."),
  83. '#type' => 'link',
  84. '#url' => $url,
  85. '#options'=>array(
  86. 'attributes' => array(
  87. 'data-drupal-link-system-path' => $url->getInternalPath()
  88. )
  89. )
  90. );
  91. // TODO: refacorize the link generator as following :
  92. // $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term'=>$tid]);
  93. // $url->setOptions(array(
  94. // 'attributes' => array(
  95. // 'class' => ['index-link', 'ajax-link'],
  96. // 'viewmode'=>'index',
  97. // 'tid'=>$tid,
  98. // 'data-drupal-link-system-path' => $url->getInternalPath()
  99. // )
  100. // ));
  101. // $entree['index_link'] = Link::fromTextAndUrl('index', $url);
  102. // if article not empty
  103. $url = Url::fromRoute('entity.node.canonical', ['node'=>$vars['node']->id()], array(
  104. 'attributes' => array(
  105. 'class' => ['link-article', 'ajax-link'],
  106. 'viewmode'=>'article'
  107. )
  108. ));
  109. $vars['link_article'] = array(
  110. '#title' => t("Lire l'article."),
  111. '#type' => 'link',
  112. '#url' => $url,
  113. '#options' => array(
  114. 'attributes'=>array(
  115. 'data-drupal-link-system-path' => $url->getInternalPath()
  116. )
  117. )
  118. );
  119. // if article or transcript
  120. $vars['col_left'] = true;
  121. // if
  122. $vars['col_right'] = true;
  123. }