diff --git a/sites/all/modules/figli/edlp_ajax/edlp_ajax.module b/sites/all/modules/figli/edlp_ajax/edlp_ajax.module index 40ed0e254..8c375bc9a 100644 --- a/sites/all/modules/figli/edlp_ajax/edlp_ajax.module +++ b/sites/all/modules/figli/edlp_ajax/edlp_ajax.module @@ -95,7 +95,8 @@ function edlp_ajax_theme($existing, $type, $theme, $path) { 'variables' => array( 'entity_type' => 'node', 'entity' => NULL, - 'view_mode' => 'default' + 'view_mode' => 'default', + 'aside' => array(), ), ), ); diff --git a/sites/all/modules/figli/edlp_ajax/includes/edlp_ajax.inc b/sites/all/modules/figli/edlp_ajax/includes/edlp_ajax.inc index acd6601ac..d9b9773b3 100644 --- a/sites/all/modules/figli/edlp_ajax/includes/edlp_ajax.inc +++ b/sites/all/modules/figli/edlp_ajax/includes/edlp_ajax.inc @@ -9,4 +9,5 @@ function template_preprocess_edlp_ajax(&$vars){ */ $view_builder = \Drupal::entityTypeManager()->getViewBuilder($vars['entity_type']); $vars['content'] = $view_builder->view($vars['entity'], $vars['view_mode']); + } diff --git a/sites/all/modules/figli/edlp_ajax/src/Controller/EdlpAjaxController.php b/sites/all/modules/figli/edlp_ajax/src/Controller/EdlpAjaxController.php index 2dc36d63e..b41a326fe 100644 --- a/sites/all/modules/figli/edlp_ajax/src/Controller/EdlpAjaxController.php +++ b/sites/all/modules/figli/edlp_ajax/src/Controller/EdlpAjaxController.php @@ -7,6 +7,8 @@ use Symfony\Component\HttpFoundation\Request; use Drupal\Core\Url; use Drupal\Core\Language\LanguageInterface; use Drupal\menu_link_content\Entity\MenuLinkContent; +use Drupal\Core\Datetime\DrupalDateTime; + // use Symfony\Component\HttpFoundation\JsonResponse; use \Drupal\block\Entity\Block; use Drupal\Core\Cache\CacheableJsonResponse; @@ -18,6 +20,104 @@ class EdlpAjaxController extends ControllerBase { private function query() { $this->entity = entity_load($this->entity_type, $this->id); + + if($this->entity){ + switch($this->entity_type){ + case 'node': + $this->bundle = $this->entity->getType(); + break; + case 'taxonomy_term': + $this->bundle = $this->entity->bundle(); + break; + default: + $this->bundle = NULL; + } + } + } + + private function getProductionDatesAside(){ + + $now = new DrupalDateTime('now'); + $now->setTimezone(new \DateTimeZone(DATETIME_STORAGE_TIMEZONE)); + + $future_dates_query = \Drupal::entityQuery('node') + ->condition('status', 1) + ->condition('type', 'evenement') + ->condition('field_page_liee.target_id', $this->entity->id(), 'IN') + ->condition('field_date', $now->format(DATETIME_DATETIME_STORAGE_FORMAT), '>=') + ->sort('field_date'); + $future_nids = $future_dates_query->execute(); + + $past_dates_query = \Drupal::entityQuery('node') + ->condition('status', 1) + ->condition('type', 'evenement') + ->condition('field_page_liee.target_id', $this->entity->id(), 'IN') + ->condition('field_date', $now->format(DATETIME_DATETIME_STORAGE_FORMAT), '<') + ->sort('field_date', 'DESC'); + $past_nids = $past_dates_query->execute(); + + if(count($future_nids) || count($past_nids)){ + + $aside = array( + '#type'=>'container' + ); + + $node_view_builder = \Drupal::entityTypeManager()->getViewBuilder('node'); + + if(count($future_nids)){ + $future_nodes = entity_load_multiple('node', $future_nids); + $future_list = array ( + '#theme' => 'item_list', + '#items' => [], + ); + foreach($future_nodes as $node){ + $future_list['#items'][] = $node_view_builder->view($node, 'teaser'); + } + $aside['future_events'] = array( + "#type"=>"container", + "#attributes"=>array( + "class"=>['future-events'] + ), + "#markup"=>"

" . t("Future events") . "

", + "future_events"=>$future_list + ); + } + + if(count($past_nids)){ + $past_nodes = entity_load_multiple('node', $past_nids); + $past_list = array ( + '#theme' => 'item_list', + '#items' => [], + ); + foreach($past_nodes as $node){ + $past_list['#items'][] = $node_view_builder->view($node, 'teaser'); + } + $aside['past_events'] = array( + "#type"=>"container", + "#attributes"=>array( + "class"=>['future-events'] + ), + "#markup"=>"

" . t("Past events") . "

", + "past_events"=>$past_list + ); + } + }else{ + $aside = null; + } + return $aside; + } + + /** + * + * return a renderable array + */ + private function getAside() { + if($this->bundle == 'page'){ + $aside = $this->getProductionDatesAside(); + }else{ + $aside = null; + } + return $aside; } private function toRenderable(){ @@ -29,6 +129,7 @@ class EdlpAjaxController extends ControllerBase { "#entity_type" => $this->entity_type, '#entity' => $this->entity, '#view_mode' => $this->viewmode, + '#aside' => $this->getAside(), ); }else{ return array( @@ -55,28 +156,18 @@ class EdlpAjaxController extends ControllerBase { return render($renderable); }); - switch($this->entity_type){ - case 'node': - $bundle = $this->entity->getType(); - break; - case 'taxonomy_term': - $bundle = $this->entity->bundle(); - break; - default: - $bundle = NULL; - } $data = [ 'date' => time(), 'id' => $this->id, 'view_mode' => $this->viewmode, - 'bundle' => $bundle, + 'bundle' => $this->bundle, 'entity_type' => $this->entity_type, 'rendered'=> $rendered, ]; - // if content type page (productions) get the menu items - if($bundle == "page"){ + // if content type page (productions) get the menu items and linked dates + if($this->bundle == "page"){ $menuLinkManager = \Drupal::service('plugin.manager.menu.link'); $links = $menuLinkManager->loadLinksByRoute('entity.node.canonical', array('node' => $this->id), 'productions'); // dpm($links, 'links'); diff --git a/sites/all/modules/figli/edlp_ajax/templates/edlp-ajax.html.twig b/sites/all/modules/figli/edlp_ajax/templates/edlp-ajax.html.twig index cddd07099..7b1f9ea8b 100644 --- a/sites/all/modules/figli/edlp_ajax/templates/edlp-ajax.html.twig +++ b/sites/all/modules/figli/edlp_ajax/templates/edlp-ajax.html.twig @@ -1 +1,2 @@ {{ content }} +{{ aside }} diff --git a/sites/all/themes/custom/edlptheme/templates/content/edlp-ajax--node--default.html.twig b/sites/all/themes/custom/edlptheme/templates/content/edlp-ajax--node--default.html.twig index 69cd182a6..df2105b69 100644 --- a/sites/all/themes/custom/edlptheme/templates/content/edlp-ajax--node--default.html.twig +++ b/sites/all/themes/custom/edlptheme/templates/content/edlp-ajax--node--default.html.twig @@ -5,3 +5,12 @@ {##} +{% if aside %} +
+
+ {#
#} + {{ aside }} + {#
#} +
+
+{% endif %}