|
@@ -7,6 +7,8 @@ use Symfony\Component\HttpFoundation\Request;
|
|
use Drupal\Core\Url;
|
|
use Drupal\Core\Url;
|
|
use Drupal\Core\Language\LanguageInterface;
|
|
use Drupal\Core\Language\LanguageInterface;
|
|
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
|
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
|
|
|
+use Drupal\Core\Datetime\DrupalDateTime;
|
|
|
|
+
|
|
// use Symfony\Component\HttpFoundation\JsonResponse;
|
|
// use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use \Drupal\block\Entity\Block;
|
|
use \Drupal\block\Entity\Block;
|
|
use Drupal\Core\Cache\CacheableJsonResponse;
|
|
use Drupal\Core\Cache\CacheableJsonResponse;
|
|
@@ -18,6 +20,104 @@ class EdlpAjaxController extends ControllerBase {
|
|
|
|
|
|
private function query() {
|
|
private function query() {
|
|
$this->entity = entity_load($this->entity_type, $this->id);
|
|
$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"=>"<h3>" . t("Future events") . "</h3>",
|
|
|
|
+ "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"=>"<h3>" . t("Past events") . "</h3>",
|
|
|
|
+ "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(){
|
|
private function toRenderable(){
|
|
@@ -29,6 +129,7 @@ class EdlpAjaxController extends ControllerBase {
|
|
"#entity_type" => $this->entity_type,
|
|
"#entity_type" => $this->entity_type,
|
|
'#entity' => $this->entity,
|
|
'#entity' => $this->entity,
|
|
'#view_mode' => $this->viewmode,
|
|
'#view_mode' => $this->viewmode,
|
|
|
|
+ '#aside' => $this->getAside(),
|
|
);
|
|
);
|
|
}else{
|
|
}else{
|
|
return array(
|
|
return array(
|
|
@@ -55,28 +156,18 @@ class EdlpAjaxController extends ControllerBase {
|
|
return render($renderable);
|
|
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 = [
|
|
$data = [
|
|
'date' => time(),
|
|
'date' => time(),
|
|
'id' => $this->id,
|
|
'id' => $this->id,
|
|
'view_mode' => $this->viewmode,
|
|
'view_mode' => $this->viewmode,
|
|
- 'bundle' => $bundle,
|
|
|
|
|
|
+ 'bundle' => $this->bundle,
|
|
'entity_type' => $this->entity_type,
|
|
'entity_type' => $this->entity_type,
|
|
'rendered'=> $rendered,
|
|
'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');
|
|
$menuLinkManager = \Drupal::service('plugin.manager.menu.link');
|
|
$links = $menuLinkManager->loadLinksByRoute('entity.node.canonical', array('node' => $this->id), 'productions');
|
|
$links = $menuLinkManager->loadLinksByRoute('entity.node.canonical', array('node' => $this->id), 'productions');
|
|
// dpm($links, 'links');
|
|
// dpm($links, 'links');
|