edlp_home.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. );
  86. foreach($vars['lastdocs_items'] as $node){
  87. $lastdocs['list']['#items'][] = $node_view_builder->view($node, 'search_index');
  88. }
  89. $vars['lastdocs'] = render($lastdocs);
  90. }
  91. // render the next events of agenda as list
  92. if(isset($vars['agenda_items'])){
  93. $agenda_url = Url::fromRoute('edlp_agenda.agenda');
  94. $agenda = array(
  95. '#type'=>"container",
  96. 'title'=>array(
  97. '#prefix'=> '<h3>',
  98. '#title' => t("Agenda"),
  99. '#suffix' => '</h3>',
  100. '#type' => 'link',
  101. '#url' => $agenda_url,
  102. '#options'=>array(
  103. 'attributes' => array(
  104. 'data-drupal-link-system-path' => $agenda_url->getInternalPath(),
  105. 'class' => array('ajax-link'),
  106. )
  107. )
  108. ),
  109. 'list'=> array(
  110. '#theme' => 'item_list',
  111. '#items' => [],
  112. ),
  113. 'seeall'=>array(
  114. '#type' => 'link',
  115. '#prefix'=> '<nav>',
  116. '#title' => t("See all"),
  117. '#suffix'=> '</nav>',
  118. '#url' => $agenda_url,
  119. '#options'=>array(
  120. 'attributes' => array(
  121. 'data-drupal-link-system-path' => $agenda_url->getInternalPath(),
  122. 'class' => array('ajax-link'),
  123. )
  124. )
  125. ),
  126. );
  127. foreach($vars['agenda_items'] as $node){
  128. $agenda['list']['#items'][] = $node_view_builder->view($node, 'teaser');
  129. }
  130. $vars['agenda'] = render($agenda);
  131. }
  132. if(isset($vars['collection_link'])){
  133. $collection = array(
  134. '#type'=>"container",
  135. 'title'=>array(
  136. '#prefix'=> '<h3>',
  137. '#title' => t("Collection"),
  138. '#suffix' => '</h3>',
  139. '#type' => 'link',
  140. '#url' => $vars['collection_link']['url'],
  141. '#options'=>array(
  142. 'attributes' => array(
  143. 'data-drupal-link-system-path' => $vars['collection_link']['internal_path'],
  144. 'class' => array('ajax-link'),
  145. )
  146. )
  147. )
  148. );
  149. $vars['collection'] = render($collection);
  150. }
  151. }