reinstaled drupal core using composer-drupal/drupal-project

This commit is contained in:
2019-04-29 17:50:46 +02:00
parent 1e009f88bf
commit e1f9bb3cd0
5468 changed files with 2488 additions and 395192 deletions
@@ -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,33 @@
<?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' => 'includes/edlp_home.inc',
'variables' => array(
// 'presentation_node' => NULL,
// 'last_fil_node' => NULL,
// 'last_production_node' => NULL,
'promoted_nodes' => array(),
'lastdocs_items' => NULL,
'agenda_items' => NULL,
// 'entrees_items' => NULL,
'collection_link' => NULL,
),
),
);
}
@@ -0,0 +1,31 @@
# @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'
edlp_home.home_mobile:
path: '/home_m'
defaults:
_controller: '\Drupal\edlp_home\Controller\HomeController::home_mobile'
_title: 'Home'
requirements:
_permission: 'access content'
edlp_home.home_mobileajax:
path: '/home_m/ajax'
defaults:
_controller: '\Drupal\edlp_home\Controller\HomeController::home_mobilejson'
_title: 'Home'
requirements:
_permission: 'access content'
@@ -0,0 +1,175 @@
<?php
use Drupal\Core\Url;
function template_preprocess_edlp_home(&$vars){
$node_view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
// $term_view_builder = \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term');
// dpm($vars);
// render the promoted_nodes
$vars['nodes'] = array();
if(isset($vars['promoted_nodes'])){
foreach($vars['promoted_nodes'] as $node){
if($node->hasField('field_view_mode')){
switch($node->get('field_view_mode')->value){
case "1":
$vm = "image_2_columns";
break;
case "2":
$vm = "image_1_columns";
break;
case "3":
$vm = "text_1_column";
break;
};
}else{
$vm = 'default';
}
$vars['nodes'][] = array(
'vm'=>$vm,
'build'=>$node_view_builder->view($node, $vm)
);
}
}
// render the last fil column
// $vars["last_fil"] = array(
// "#type" => "container",
// // 'fil' => $node_view_builder->view($vars['last_fil_node'], 'teaser'),
// 'title'=> array("#markup" => "<h2 class='title'>Dernier Fil</h2>"),
// 'fil' => $vars['last_fil_node'],
// // 'links' => array(
// // '#theme' => 'item_list',
// // '#items' => array(
// // 'link_all' => array(
// // '#title' => t("Voir tous les fils de l'EP."),
// // '#type' => 'link',
// // '#url' => Url::fromRoute('edlp_fils.fils', [], array(
// // 'attributes' => array(
// // 'class' => ['fils-link', 'ajax-link']
// // )
// // ))
// // ),
// // // TODO: link posdcast fils
// // 'link_podcast' => array(
// // '#title' => t("S'abonner au podcast des fils."),
// // '#type' => 'link',
// // '#url' => Url::fromRoute('<front>', [], array(
// // 'attributes' => array(
// // 'class' => ['fils-link']
// // )
// // ))
// // )
// // )
// // )
// );
// render the lasts documents of collection as list
if(isset($vars['lastdocs_items'])){
$lastdocs_url = Url::fromRoute('edlp_corpus.lastdocs');
$lastdocs = array(
'#type'=>"container",
'title'=>array(
'#prefix'=> '<h3>',
'#title' => t("Recently uploaded"),
'#suffix' => '</h3>',
'#type' => 'link',
'#url' => $lastdocs_url,
'#options'=>array(
'attributes' => array(
'data-drupal-link-system-path' => $lastdocs_url->getInternalPath(),
'class' => array('ajax-link'),
)
)
),
'list'=> array(
'#theme' => 'item_list',
'#items' => [],
),
'seeall'=>array(
'#type' => 'link',
'#prefix'=> '<nav>',
'#title' => t("See all"),
'#suffix'=> '</nav>',
'#url' => $lastdocs_url,
'#options'=>array(
'attributes' => array(
'data-drupal-link-system-path' => $lastdocs_url->getInternalPath(),
'class' => array('ajax-link'),
)
)
),
);
foreach($vars['lastdocs_items'] as $node){
$lastdocs['list']['#items'][] = $node_view_builder->view($node, 'search_index');
}
$vars['lastdocs'] = render($lastdocs);
}
// render the next events of agenda as list
if(isset($vars['agenda_items'])){
$agenda_url = Url::fromRoute('edlp_agenda.agenda');
$agenda = array(
'#type'=>"container",
'title'=>array(
'#prefix'=> '<h3>',
'#title' => t("Agenda"),
'#suffix' => '</h3>',
'#type' => 'link',
'#url' => $agenda_url,
'#options'=>array(
'attributes' => array(
'data-drupal-link-system-path' => $agenda_url->getInternalPath(),
'class' => array('ajax-link'),
)
)
),
'list'=> array(
'#theme' => 'item_list',
'#items' => [],
),
'seeall'=>array(
'#type' => 'link',
'#prefix'=> '<nav>',
'#title' => t("See all"),
'#suffix'=> '</nav>',
'#url' => $agenda_url,
'#options'=>array(
'attributes' => array(
'data-drupal-link-system-path' => $agenda_url->getInternalPath(),
'class' => array('ajax-link'),
)
)
),
);
foreach($vars['agenda_items'] as $node){
$agenda['list']['#items'][] = $node_view_builder->view($node, 'teaser');
}
$vars['agenda'] = render($agenda);
}
if(isset($vars['collection_link'])){
$collection = array(
'#type'=>"container",
'title'=>array(
'#prefix'=> '<h3>',
'#title' => t("Collection"),
'#suffix' => '</h3>',
'#type' => 'link',
'#url' => $vars['collection_link']['url'],
'#options'=>array(
'attributes' => array(
'data-drupal-link-system-path' => $vars['collection_link']['internal_path'],
'class' => array('ajax-link'),
)
)
)
);
$vars['collection'] = render($collection);
}
}
@@ -0,0 +1,249 @@
<?php
namespace Drupal\edlp_home\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\taxonomy\Entity\Term;
use Drupal\workflow\Entity\WorkflowManager;
use Drupal\Core\Url;
use Drupal\Core\Language\LanguageInterface;
// use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\core\render\RenderContext;
class HomeController extends ControllerBase {
/**
* Display home as a page.
*
* @return renderable array
*/
public function home() {
// $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$contents = array("#theme"=>'edlp_home');
// first get static pages
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('field_afficher_en_page_d_acceuil', 1)
->condition('type', 'static');
$promoted_nids = $query->execute();
$contents["#promoted_nodes"] = entity_load_multiple('node', $promoted_nids);
// then get production pages
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('field_afficher_en_page_d_acceuil', 1)
->condition('type', 'page');
$promoted_nids = $query->execute();
$contents["#promoted_nodes"] += entity_load_multiple('node', $promoted_nids);
// presentation
// $query = \Drupal::entityQuery('node')
// ->condition('status', 1)
// ->condition('nid', 12242);
// // TODO: présentation nid should be a setting
//
// $pres_nid = $query->execute();
// $contents["#presentation_node"] = entity_load('node', array_pop($pres_nid));
// last fil
// $query = \Drupal::entityQuery('node')
// ->condition('status', 1)
// ->condition('type', 'fil')
// ->sort('created', 'DESC')
// ->range(0,1);
//
// $fil = $query->execute();
// $contents["#last_fil_node"] = entity_load('node', array_pop($fil));
// $contents["#last_fil_node"] = array('#markup'=>'En développement.');
// last production
// $query = \Drupal::entityQuery('node')
// ->condition('status', 1)
// ->condition('type', 'page')
// ->condition('field_page_type', array('1168'), 'NOT IN')
// ->sort('created', 'DESC')
// ->range(0,1);
//
// $prod = $query->execute();
// $contents["#last_production_node"] = entity_load('node', array_pop($prod));
// last documents
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'enregistrement')
->sort('created', 'DESC')
->range(0,50);
$nids = $query->execute();
$nodes = entity_load_multiple('node', $nids);
$lastdocs = [];
$i = 0;
foreach ($nodes as $node) {
// remove masqué
$sid = WorkflowManager::getCurrentStateId($node, 'field_workflow');
if($sid != 'corpus_documents_publie') continue;
$lastdocs[] = $node;
$i++;
if($i>9) break;
}
// $contents["#lastdocs_items"] = entity_load_multiple('node', $lastdocs);
$contents["#lastdocs_items"] = $lastdocs;
// dsm($contents["#lastdocs_items"], "#lastdocs_items");
// 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,5)
->sort('field_date');
$events = $query->execute();
$contents['#agenda_items'] = entity_load_multiple('node', $events);
return $contents;
}
/**
* Display home mobile as a page.
*
* @return renderable array
*/
public function toMobileHomeRenderable() {
// $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$renderable = array("#theme"=>'edlp_home');
// first get static pages
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('field_afficher_en_page_d_acceuil', 1)
->condition('type', 'static');
$promoted_nids = $query->execute();
$renderable["#promoted_nodes"] = entity_load_multiple('node', $promoted_nids);
// then get production pages
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('field_afficher_en_page_d_acceuil', 1)
->condition('type', 'page');
$promoted_nids = $query->execute();
$renderable["#promoted_nodes"] += entity_load_multiple('node', $promoted_nids);
// last fil
// $query = \Drupal::entityQuery('node')
// ->condition('status', 1)
// ->condition('type', 'fil')
// ->sort('created', 'DESC')
// ->range(0,1);
//
// $fil = $query->execute();
// $renderable["#last_fil_node"] = entity_load('node', array_pop($fil));
// $renderable["#last_fil_node"] = array('#markup'=>'En développement.');
// 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,5)
->sort('field_date');
$events = $query->execute();
$renderable['#agenda_items'] = entity_load_multiple('node', $events);
// Collection
// TODO: get the link to mobile collection page
$collection_url = Url::fromRoute('edlp_corpus.collection');
$renderable['#collection_link'] = array(
'url' => $collection_url,
'internal_path' => $collection_url->getInternalPath(),
);
return $renderable;
}
public function home_mobile() {
return $this->toMobileHomeRenderable();
}
/**
* Get home mobile data as json through ajax.
*
* @return json
*/
// NOT NEEDED ANY MORE
public function home_mobilejson() {
$renderable = $this->toMobileHomeRenderable();
// $rendered = render($renderable);
// We can't render directly the entity as it throw an exception with cachable data
//http://blog.dcycle.com/blog/2018-01-24/caching-drupal-8-rest-resource/#the-dreaded-leaked-metadata-error
$rendered = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($renderable) {
return render($renderable);
});
$data = [
'rendered'=> $rendered,
'title'=>'Home Mobile',
];
// translations links
// use Drupal\Core\Url;
// use Drupal\Core\Language\LanguageInterface;
$route_name = 'edlp_home.home_mobile';
$links = \Drupal::languageManager()->getLanguageSwitchLinks(LanguageInterface::TYPE_URL, Url::fromRoute($route_name));
if (isset($links->links)) {
$translations_build = [
'#theme' => 'links__language_block',
'#links' => $links->links,
'#attributes' => ['class' => ["language-switcher-{$links->method_id}",],],
'#set_active_class' => TRUE,
];
$translations_rendered = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($translations_build) {return render($translations_build);});
$data['translations_links'] = $translations_rendered;
}
$data['#cache'] = [
'max-age' => \Drupal\Core\Cache\Cache::PERMANENT,
'tags' => ['edlp-home-cache'],
'contexts' => [
'languages:language_content'
]
];
// $response = new JsonResponse();
// $response->setData($data);
$response = new CacheableJsonResponse($data);
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($data));
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($renderable));
return $response;
}
}
@@ -0,0 +1,21 @@
{# presentation #}
{# last_fil #}
{# last_production #}
{% if nodes %}
{% for node in nodes %}
{{ node.build }}
{% endfor %}
{% endif %}
{% if lastdocs %}
{{ lastdocs }}
{% endif %}
{% if agenda %}
{{ agenda }}
{% endif %}
{% if collection %}
{{ collection }}
{% endif %}