edlp_home.inc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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_statics and promoted_prods
  8. $promoteds = ['statics', 'prods'];
  9. foreach ($promoteds as $index => $p) {
  10. $vars['nodes_' . $p] = array();
  11. if(isset($vars['promoted_' . $p])){
  12. foreach($vars['promoted_' . $p] as $node){
  13. if($node->hasField('field_view_mode')){
  14. switch($node->get('field_view_mode')->value){
  15. case "1":
  16. $vm = "image_2_columns";
  17. break;
  18. case "2":
  19. $vm = "image_1_columns";
  20. break;
  21. case "3":
  22. $vm = "text_1_column";
  23. break;
  24. };
  25. }else{
  26. $vm = 'default';
  27. }
  28. $vars['nodes_' . $p][] = array(
  29. 'vm'=>$vm,
  30. 'build'=>$node_view_builder->view($node, $vm)
  31. );
  32. }
  33. }
  34. }
  35. // render the last fil column
  36. // $vars["last_fil"] = array(
  37. // "#type" => "container",
  38. // // 'fil' => $node_view_builder->view($vars['last_fil_node'], 'teaser'),
  39. // 'title'=> array("#markup" => "<h2 class='title'>Dernier Fil</h2>"),
  40. // 'fil' => $vars['last_fil_node'],
  41. // // 'links' => array(
  42. // // '#theme' => 'item_list',
  43. // // '#items' => array(
  44. // // 'link_all' => array(
  45. // // '#title' => t("Voir tous les fils de l'EP."),
  46. // // '#type' => 'link',
  47. // // '#url' => Url::fromRoute('edlp_fils.fils', [], array(
  48. // // 'attributes' => array(
  49. // // 'class' => ['fils-link', 'ajax-link']
  50. // // )
  51. // // ))
  52. // // ),
  53. // // // TODO: link posdcast fils
  54. // // 'link_podcast' => array(
  55. // // '#title' => t("S'abonner au podcast des fils."),
  56. // // '#type' => 'link',
  57. // // '#url' => Url::fromRoute('<front>', [], array(
  58. // // 'attributes' => array(
  59. // // 'class' => ['fils-link']
  60. // // )
  61. // // ))
  62. // // )
  63. // // )
  64. // // )
  65. // );
  66. // render the lasts documents of collection as list
  67. if(isset($vars['lastdocs_items'])){
  68. $lastdocs_url = Url::fromRoute('edlp_corpus.lastdocs');
  69. $lastdocs = array(
  70. '#type'=>"container",
  71. 'title'=>array(
  72. '#prefix'=> '<h3>',
  73. '#title' => t("Recently uploaded"),
  74. '#suffix' => '</h3>',
  75. '#type' => 'link',
  76. '#url' => $lastdocs_url,
  77. '#options'=>array(
  78. 'attributes' => array(
  79. 'data-drupal-link-system-path' => $lastdocs_url->getInternalPath(),
  80. 'class' => array('ajax-link'),
  81. )
  82. )
  83. ),
  84. 'list'=> array(
  85. '#theme' => 'item_list',
  86. '#items' => [],
  87. ),
  88. 'seeall'=>array(
  89. '#type' => 'link',
  90. '#prefix'=> '<nav>',
  91. '#title' => t("See all"),
  92. '#suffix'=> '</nav>',
  93. '#url' => $lastdocs_url,
  94. '#options'=>array(
  95. 'attributes' => array(
  96. 'data-drupal-link-system-path' => $lastdocs_url->getInternalPath(),
  97. 'class' => array('ajax-link'),
  98. )
  99. )
  100. ),
  101. );
  102. foreach($vars['lastdocs_items'] as $node){
  103. $lastdocs['list']['#items'][] = $node_view_builder->view($node, 'search_index');
  104. }
  105. $vars['lastdocs'] = render($lastdocs);
  106. }
  107. // render the next events of agenda as list
  108. if(isset($vars['agenda_items'])){
  109. $agenda_url = Url::fromRoute('edlp_agenda.agenda');
  110. $agenda = array(
  111. '#type'=>"container",
  112. 'title'=>array(
  113. '#prefix'=> '<h3>',
  114. '#title' => t("Agenda"),
  115. '#suffix' => '</h3>',
  116. '#type' => 'link',
  117. '#url' => $agenda_url,
  118. '#options'=>array(
  119. 'attributes' => array(
  120. 'data-drupal-link-system-path' => $agenda_url->getInternalPath(),
  121. 'class' => array('ajax-link'),
  122. )
  123. )
  124. ),
  125. 'list'=> array(
  126. '#theme' => 'item_list',
  127. '#items' => [],
  128. ),
  129. 'seeall'=>array(
  130. '#type' => 'link',
  131. '#prefix'=> '<nav>',
  132. '#title' => t("See all"),
  133. '#suffix'=> '</nav>',
  134. '#url' => $agenda_url,
  135. '#options'=>array(
  136. 'attributes' => array(
  137. 'data-drupal-link-system-path' => $agenda_url->getInternalPath(),
  138. 'class' => array('ajax-link'),
  139. )
  140. )
  141. ),
  142. );
  143. foreach($vars['agenda_items'] as $node){
  144. $agenda['list']['#items'][] = $node_view_builder->view($node, 'teaser');
  145. }
  146. $vars['agenda'] = render($agenda);
  147. }
  148. if(isset($vars['collection_link'])){
  149. $collection = array(
  150. '#type'=>"container",
  151. 'title'=>array(
  152. '#prefix'=> '<h3>',
  153. '#title' => t("Collection"),
  154. '#suffix' => '</h3>',
  155. '#type' => 'link',
  156. '#url' => $vars['collection_link']['url'],
  157. '#options'=>array(
  158. 'attributes' => array(
  159. 'data-drupal-link-system-path' => $vars['collection_link']['internal_path'],
  160. 'class' => array('ajax-link'),
  161. )
  162. )
  163. )
  164. );
  165. $vars['collection_link_rendered'] = render($collection);
  166. }
  167. if(isset($vars['production_link'])){
  168. $production = array(
  169. '#type'=>"container",
  170. 'title'=>array(
  171. '#prefix'=> '<h3>',
  172. '#title' => t("Productions"),
  173. '#suffix' => '</h3>',
  174. '#type' => 'link',
  175. '#url' => $vars['production_link']['url'],
  176. '#options'=>array(
  177. 'attributes' => array(
  178. 'data-drupal-link-system-path' => $vars['production_link']['internal_path'],
  179. 'class' => array('ajax-link'),
  180. )
  181. )
  182. )
  183. );
  184. $vars['production_link_rendered'] = render($production);
  185. }
  186. if(isset($vars['agenda_link'])){
  187. $agenda = array(
  188. '#type'=>"container",
  189. 'title'=>array(
  190. '#prefix'=> '<h3>',
  191. '#title' => t("Agenda"),
  192. '#suffix' => '</h3>',
  193. '#type' => 'link',
  194. '#url' => $vars['agenda_link']['url'],
  195. '#options'=>array(
  196. 'attributes' => array(
  197. 'data-drupal-link-system-path' => $vars['agenda_link']['internal_path'],
  198. 'class' => array('ajax-link'),
  199. )
  200. )
  201. )
  202. );
  203. $vars['agenda_link_rendered'] = render($agenda);
  204. }
  205. }