edlp_home.inc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. use Drupal\Core\Url;
  3. function template_preprocess_edlp_home(&$vars){
  4. $node_view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
  5. $term_view_builder = \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term');
  6. // dpm($vars);
  7. // render the promoted_nodes
  8. $vars['nodes'] = array();
  9. if(isset($vars['promoted_nodes'])){
  10. foreach($vars['promoted_nodes'] as $node){
  11. if($node->hasField('field_view_mode')){
  12. switch($node->get('field_view_mode')->value){
  13. case "1":
  14. $vm = "image_2_columns";
  15. break;
  16. case "2":
  17. $vm = "image_1_columns";
  18. break;
  19. case "3":
  20. $vm = "text_1_column";
  21. break;
  22. };
  23. }else{
  24. $vm = 'default';
  25. }
  26. $vars['nodes'][] = array(
  27. 'vm'=>$vm,
  28. 'build'=>$node_view_builder->view($node, $vm)
  29. );
  30. }
  31. }
  32. // render the presentation column
  33. // $vars["presentation"] = array(
  34. // "#type"=>"container",
  35. // "pres"=>$node_view_builder->view($vars["presentation_node"], 'default'),
  36. // "link"=> array(
  37. // '#title' => t('Visiter la collection sonore.'),
  38. // '#type' => 'link',
  39. // '#url' => Url::fromRoute('<front>', [], array(
  40. // 'attributes' => array(
  41. // 'class' => ['corpus-link', 'ajax-link']
  42. // )
  43. // ))
  44. // )
  45. // );
  46. // render the last fil column
  47. // $vars["last_fil"] = array(
  48. // "#type" => "container",
  49. // // 'fil' => $node_view_builder->view($vars['last_fil_node'], 'teaser'),
  50. // 'title'=> array("#markup" => "<h2 class='title'>Dernier Fil</h2>"),
  51. // 'fil' => $vars['last_fil_node'],
  52. // // 'links' => array(
  53. // // '#theme' => 'item_list',
  54. // // '#items' => array(
  55. // // 'link_all' => array(
  56. // // '#title' => t("Voir tous les fils de l'EP."),
  57. // // '#type' => 'link',
  58. // // '#url' => Url::fromRoute('edlp_fils.fils', [], array(
  59. // // 'attributes' => array(
  60. // // 'class' => ['fils-link', 'ajax-link']
  61. // // )
  62. // // ))
  63. // // ),
  64. // // // TODO: link posdcast fils
  65. // // 'link_podcast' => array(
  66. // // '#title' => t("S'abonner au podcast des fils."),
  67. // // '#type' => 'link',
  68. // // '#url' => Url::fromRoute('<front>', [], array(
  69. // // 'attributes' => array(
  70. // // 'class' => ['fils-link']
  71. // // )
  72. // // ))
  73. // // )
  74. // // )
  75. // // )
  76. // );
  77. // render the last production column
  78. // $vars["last_production"] = array(
  79. // '#type' => 'container',
  80. // 'prod' => $node_view_builder->view($vars['last_production_node'], 'teaser'),
  81. // 'link'=> array(
  82. // '#title' => t('Voir toutes les productions.'),
  83. // '#type' => 'link',
  84. // '#url' => Url::fromRoute('edlp_productions.productions', [], array(
  85. // 'attributes' => array(
  86. // 'class' => ['productions-link', 'ajax-link']
  87. // )
  88. // ))
  89. // )
  90. // );
  91. // render the lasts documents of collection as list
  92. if(isset($vars['lastdocs_items'])){
  93. $lastdocs_url = Url::fromRoute('edlp_corpus.lastdocs');
  94. $lastdocs = array(
  95. '#type'=>"container",
  96. 'title'=>array(
  97. '#prefix'=> '<h3>',
  98. '#title' => t("Recently uploaded"),
  99. '#suffix' => '</h3>',
  100. '#type' => 'link',
  101. '#url' => $lastdocs_url,
  102. '#options'=>array(
  103. 'attributes' => array(
  104. 'data-drupal-link-system-path' => $lastdocs_url->getInternalPath(),
  105. 'class' => array('ajax-link'),
  106. )
  107. )
  108. ),
  109. 'list'=> array(
  110. '#theme' => 'item_list',
  111. '#items' => [],
  112. ),
  113. );
  114. foreach($vars['lastdocs_items'] as $node){
  115. $lastdocs['list']['#items'][] = $node_view_builder->view($node, 'search_index');
  116. }
  117. $vars['lastdocs'] = render($lastdocs);
  118. }
  119. // render the next events of agenda as list
  120. if(isset($vars['agenda_items'])){
  121. $agenda_url = Url::fromRoute('edlp_agenda.agenda');
  122. $agenda = array(
  123. '#type'=>"container",
  124. 'title'=>array(
  125. '#prefix'=> '<h3>',
  126. '#title' => t("Agenda"),
  127. '#suffix' => '</h3>',
  128. '#type' => 'link',
  129. '#url' => $agenda_url,
  130. '#options'=>array(
  131. 'attributes' => array(
  132. 'data-drupal-link-system-path' => $agenda_url->getInternalPath(),
  133. 'class' => array('ajax-link'),
  134. )
  135. )
  136. ),
  137. 'list'=> array(
  138. '#theme' => 'item_list',
  139. '#items' => [],
  140. ),
  141. );
  142. foreach($vars['agenda_items'] as $node){
  143. $agenda['list']['#items'][] = $node_view_builder->view($node, 'teaser');
  144. }
  145. $vars['agenda'] = render($agenda);
  146. }
  147. if(isset($vars['entrees_items'])){
  148. $entrees = array(
  149. '#type'=>"container",
  150. // '#attributes' => array(
  151. // 'id' => array('collection'),
  152. // ),
  153. '#prefix' => '<div id="collection"></div>',
  154. 'title'=>array(
  155. '#markup'=>"<h3>".t("Collection")."</h3>",
  156. ),
  157. 'list'=> array(
  158. '#theme' => 'item_list',
  159. '#items' => [],
  160. ),
  161. );
  162. foreach($vars['entrees_items'] as $term){
  163. $entrees['list']['#items'][] = $term_view_builder->view($term, 'home_mobile');
  164. }
  165. $vars['entrees'] = render($entrees);
  166. }
  167. }