Browse Source

fixed next envent not apearing in agenda and empty comming events bug

Bachir Soussi Chiadmi 6 years ago
parent
commit
a9a219f2ed

+ 23 - 19
sites/all/modules/figli/edlp_agenda/includes/edlp_agenda.inc

@@ -9,27 +9,31 @@ function template_preprocess_edlp_agenda(&$vars){
   */
   $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
 
-  $vars['next_event'] = array(
-    "#markup"=>"<h3>Prochaine Date</h3>",
-    "event"=>$view_builder->view($vars['next_event_node'], 'default')
-  );
-
-  $future_list = array (
-    '#theme' => 'item_list',
-    '#items' => [],
-  );
-  foreach($vars['coming_events_nodes'] as $node){
-    $future_list['#items'][] = $view_builder->view($node, 'teaser');
+  if(isset($vars['next_event_node'])){
+    $vars['next_event'] = array(
+      "#markup"=>"<h3>Prochaine Date</h3>",
+      "event"=>$view_builder->view($vars['next_event_node'], 'default')
+    );
   }
 
-  $vars['coming_events'] = array(
-    "#type"=>"container",
-    "#attributes"=>array(
-      "class"=>['future-events']
-    ),
-    "#markup"=>"<h3>".t("Upcoming Events")."</h3>",
-    "future_events"=>$future_list
-  );
+  if(count($vars['coming_events_nodes'])){
+    $future_list = array (
+      '#theme' => 'item_list',
+      '#items' => [],
+    );
+    foreach($vars['coming_events_nodes'] as $node){
+      $future_list['#items'][] = $view_builder->view($node, 'teaser');
+    }
+
+    $vars['coming_events'] = array(
+      "#type"=>"container",
+      "#attributes"=>array(
+        "class"=>['future-events']
+      ),
+      "#markup"=>"<h3>".t("Upcoming Events")."</h3>",
+      "future_events"=>$future_list
+    );
+  }
 
 
   $past_list = array (

+ 3 - 3
sites/all/modules/figli/edlp_agenda/src/Controller/AgendaController.php

@@ -29,7 +29,7 @@ class AgendaController extends ControllerBase {
     $this->future_nids = $query->execute();
     $this->future_nodes = entity_load_multiple('node', $this->future_nids);
 
-    $this->next_event = array_shift($this->future_nodes);
+    $this->next_event_node = array_shift($this->future_nodes);
 
     $query = \Drupal::entityQuery('node')
       ->condition('status', 1)
@@ -43,11 +43,11 @@ class AgendaController extends ControllerBase {
 
   private function toRenderable(){
     $this->query();
-    // dpm($this->future_nodes);
+    // dpm($this->next_event_node);
 
     return array(
       "#theme"=>'edlp_agenda',
-      '#next_event_node' => $this->next_event,
+      '#next_event_node' => $this->next_event_node,
       "#coming_events_nodes" => $this->future_nodes,
       "#past_events_nodes" => $this->past_nodes,
     );

+ 1 - 0
sites/all/themes/custom/edlptheme/templates/content/edlp-agenda.html.twig

@@ -1,6 +1,7 @@
 <div class="col small-col-12 med-col-5 large-col-4 float-right">
   <div class="wrapper">
     <div class="agenda">
+      {{ next_event }}
       {{ coming_events }}
       {{ past_events }}
     </div>