edlp_home.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 last fil column
  33. // $vars["last_fil"] = array(
  34. // "#type" => "container",
  35. // // 'fil' => $node_view_builder->view($vars['last_fil_node'], 'teaser'),
  36. // 'title'=> array("#markup" => "<h2 class='title'>Dernier Fil</h2>"),
  37. // 'fil' => $vars['last_fil_node'],
  38. // // 'links' => array(
  39. // // '#theme' => 'item_list',
  40. // // '#items' => array(
  41. // // 'link_all' => array(
  42. // // '#title' => t("Voir tous les fils de l'EP."),
  43. // // '#type' => 'link',
  44. // // '#url' => Url::fromRoute('edlp_fils.fils', [], array(
  45. // // 'attributes' => array(
  46. // // 'class' => ['fils-link', 'ajax-link']
  47. // // )
  48. // // ))
  49. // // ),
  50. // // // TODO: link posdcast fils
  51. // // 'link_podcast' => array(
  52. // // '#title' => t("S'abonner au podcast des fils."),
  53. // // '#type' => 'link',
  54. // // '#url' => Url::fromRoute('<front>', [], array(
  55. // // 'attributes' => array(
  56. // // 'class' => ['fils-link']
  57. // // )
  58. // // ))
  59. // // )
  60. // // )
  61. // // )
  62. // );
  63. // render the lasts documents of collection as list
  64. if(isset($vars['lastdocs_items'])){
  65. $lastdocs_url = Url::fromRoute('edlp_corpus.lastdocs');
  66. $lastdocs = array(
  67. '#type'=>"container",
  68. 'title'=>array(
  69. '#prefix'=> '<h3>',
  70. '#title' => t("Recently uploaded"),
  71. '#suffix' => '</h3>',
  72. '#type' => 'link',
  73. '#url' => $lastdocs_url,
  74. '#options'=>array(
  75. 'attributes' => array(
  76. 'data-drupal-link-system-path' => $lastdocs_url->getInternalPath(),
  77. 'class' => array('ajax-link'),
  78. )
  79. )
  80. ),
  81. 'list'=> array(
  82. '#theme' => 'item_list',
  83. '#items' => [],
  84. ),
  85. 'seeall'=>array(
  86. '#type' => 'link',
  87. '#prefix'=> '<nav>',
  88. '#title' => t("See all"),
  89. '#suffix'=> '</nav>',
  90. '#url' => $lastdocs_url,
  91. '#options'=>array(
  92. 'attributes' => array(
  93. 'data-drupal-link-system-path' => $lastdocs_url->getInternalPath(),
  94. 'class' => array('ajax-link'),
  95. )
  96. )
  97. ),
  98. );
  99. foreach($vars['lastdocs_items'] as $node){
  100. $lastdocs['list']['#items'][] = $node_view_builder->view($node, 'search_index');
  101. }
  102. $vars['lastdocs'] = render($lastdocs);
  103. }
  104. // render the next events of agenda as list
  105. if(isset($vars['agenda_items'])){
  106. $agenda_url = Url::fromRoute('edlp_agenda.agenda');
  107. $agenda = array(
  108. '#type'=>"container",
  109. 'title'=>array(
  110. '#prefix'=> '<h3>',
  111. '#title' => t("Agenda"),
  112. '#suffix' => '</h3>',
  113. '#type' => 'link',
  114. '#url' => $agenda_url,
  115. '#options'=>array(
  116. 'attributes' => array(
  117. 'data-drupal-link-system-path' => $agenda_url->getInternalPath(),
  118. 'class' => array('ajax-link'),
  119. )
  120. )
  121. ),
  122. 'list'=> array(
  123. '#theme' => 'item_list',
  124. '#items' => [],
  125. ),
  126. 'seeall'=>array(
  127. '#type' => 'link',
  128. '#prefix'=> '<nav>',
  129. '#title' => t("See all"),
  130. '#suffix'=> '</nav>',
  131. '#url' => $agenda_url,
  132. '#options'=>array(
  133. 'attributes' => array(
  134. 'data-drupal-link-system-path' => $agenda_url->getInternalPath(),
  135. 'class' => array('ajax-link'),
  136. )
  137. )
  138. ),
  139. );
  140. foreach($vars['agenda_items'] as $node){
  141. $agenda['list']['#items'][] = $node_view_builder->view($node, 'teaser');
  142. }
  143. $vars['agenda'] = render($agenda);
  144. }
  145. if(isset($vars['collection_link'])){
  146. $collection = array(
  147. '#type'=>"container",
  148. 'title'=>array(
  149. '#prefix'=> '<h3>',
  150. '#title' => t("Collection"),
  151. '#suffix' => '</h3>',
  152. '#type' => 'link',
  153. '#url' => $vars['collection_link']['url'],
  154. '#options'=>array(
  155. 'attributes' => array(
  156. 'data-drupal-link-system-path' => $vars['collection_link']['internal_path'],
  157. 'class' => array('ajax-link'),
  158. )
  159. )
  160. )
  161. );
  162. $vars['collection'] = render($collection);
  163. }
  164. }