created edlp_home, edlp_agenda, edlp_production custom modules

This commit is contained in:
Bachir Soussi Chiadmi
2018-01-06 11:27:29 +01:00
parent ee2f631ed7
commit 5017966908
18 changed files with 478 additions and 8 deletions
@@ -0,0 +1,26 @@
<?php
function template_preprocess_edlp_home(&$vars){
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
// dpm($vars);
// render the presentation node
$vars["presentation"] = $view_builder->view($vars["presentation_node"], 'default');
// TODO: last fil
// render the last production node
$vars["last_production"] = $view_builder->view($vars['last_production_node'], 'teaser');
// render the next events of agenda as list
$agenda = array (
'#theme' => 'item_list',
'#items' => [],
);
foreach($vars['agenda_items'] as $node){
$agenda['#items'][] = $view_builder->view($node, 'teaser');
}
$vars['agenda'] = render($agenda);
}
@@ -0,0 +1,18 @@
# @Author: Bachir Soussi Chiadmi <bach>
# @Date: 13-12-2017
# @Email: bachir@figureslibres.io
# @Filename: edlp_home.info.yml
# @Last modified by: bach
# @Last modified time: 20-12-2017
# @License: GPL-V3
name: Edlp Home
type: module
description: Manage home for edlp d8.
core: 8.x
package: Edlp
# dependencies:
# - migrate_drupal
# - migrate_plus
# - migrate_tools
@@ -0,0 +1,29 @@
<?php
# @Author: Bachir Soussi Chiadmi <bach>
# @Date: 13-12-2017
# @Email: bachir@figureslibres.io
# @Filename: edlp_home.module
# @Last modified by: bach
# @Last modified time: 20-12-2017
# @License: GPL-V3
/**
* Implements hook_theme().
*/
function edlp_home_theme($existing, $type, $theme, $path) {
// @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
return array(
'edlp_home' => array(
// 'render element' => '',
'file' => 'edlp_home.inc',
'variables' => array(
'presentation_node' => NULL,
'last_fil_node' => NULL,
'last_production_node' => NULL,
'agenda_items' => NULL
),
),
);
}
@@ -0,0 +1,15 @@
# @Author: Bachir Soussi Chiadmi <bach>
# @Date: 13-12-2017
# @Email: bachir@figureslibres.io
# @Filename: edlp_home.routing.yml
# @Last modified by: bach
# @Last modified time: 20-12-2017
# @License: GPL-V3
edlp_home.home:
path: '/home'
defaults:
_controller: '\Drupal\edlp_home\Controller\HomeController::home'
_title: 'Home'
requirements:
_permission: 'access content'
@@ -0,0 +1,63 @@
<?php
namespace Drupal\edlp_home\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\DrupalDateTime;
use Symfony\Component\HttpFoundation\JsonResponse;
class HomeController extends ControllerBase {
/**
* Display agenda as a page.
*
* @return renderable array
*/
public function home() {
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$contents = array("#theme"=>'edlp_home');
// presentation
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('nid', 5890);
$pres_nid = $query->execute();
$contents["#presentation_node"] = entity_load('node', array_pop($pres_nid));
// TODO: last fil
// $contents["#last_fil_node"] = "Last Fil";
// TODO: last production
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'page')
->condition('field_page_type', array('1168'), 'NOT IN')
->range(0,1)
->sort('created', 'DESC');
$prod = $query->execute();
$contents["#last_production_node"] = entity_load('node', array_pop($prod));
// agenda
$now = new DrupalDateTime('now');
$now->setTimezone(new \DateTimeZone(DATETIME_STORAGE_TIMEZONE));
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'evenement')
->condition('field_date', $now->format(DATETIME_DATETIME_STORAGE_FORMAT), '>=')
->range(0,3)
->sort('field_date');
$events = $query->execute();
$contents['#agenda_items'] = entity_load_multiple('node', $events);
return $contents;
}
}
@@ -0,0 +1,8 @@
{{ presentation }}
{{ last_fil }}
{{ last_production }}
{{ agenda }}