big refactoring of mobile version xhich has now a hamburger menu and a link to collection
This commit is contained in:
@@ -42,6 +42,13 @@ function edlp_corpus_theme($existing, $type, $theme, $path) {
|
||||
'articles_nodes' => NULL,
|
||||
),
|
||||
),
|
||||
'edlp_corpus_collection' => array(
|
||||
// 'render element' => '',
|
||||
'file' => 'includes/edlp_corpus_collection.inc',
|
||||
'variables' => array(
|
||||
'entrees_terms' => NULL,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ edlp_corpus.lastdocsajax:
|
||||
requirements:
|
||||
_permission: 'access content'
|
||||
|
||||
|
||||
edlp_corpus.articlesindex:
|
||||
path: '/articles'
|
||||
defaults:
|
||||
@@ -47,3 +46,19 @@ edlp_corpus.articlesindexajax:
|
||||
_title: 'Articles Index'
|
||||
requirements:
|
||||
_permission: 'access content'
|
||||
|
||||
edlp_corpus.collection:
|
||||
path: '/collection'
|
||||
defaults:
|
||||
_controller: '\Drupal\edlp_corpus\Controller\CorpusController::collection'
|
||||
_title: 'Collection'
|
||||
requirements:
|
||||
_permission: 'access content'
|
||||
|
||||
edlp_corpus.collectionajax:
|
||||
path: '/collection/ajax'
|
||||
defaults:
|
||||
_controller: '\Drupal\edlp_corpus\Controller\CorpusController::collectionjson'
|
||||
_title: 'Collection'
|
||||
requirements:
|
||||
_permission: 'access content'
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Drupal\Core\Url;
|
||||
|
||||
function template_preprocess_edlp_corpus_collection(&$vars){
|
||||
$term_view_builder = \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term');
|
||||
|
||||
if(isset($vars['entrees_terms'])){
|
||||
$entrees = array(
|
||||
'#type'=>"container",
|
||||
// '#attributes' => array(
|
||||
// 'id' => array('collection'),
|
||||
// ),
|
||||
'#prefix' => '<div id="collection"></div>',
|
||||
'title'=>array(
|
||||
'#markup'=>"<h3>".t("Collection")."</h3>",
|
||||
),
|
||||
'list'=> array(
|
||||
'#theme' => 'item_list',
|
||||
'#items' => [],
|
||||
),
|
||||
);
|
||||
foreach($vars['entrees_terms'] as $term){
|
||||
$entrees['list']['#items'][] = $term_view_builder->view($term, 'home_mobile');
|
||||
}
|
||||
$vars['entrees'] = render($entrees);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\workflow\Entity\WorkflowManager;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\File\Entity\File;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
// use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Drupal\Core\Cache\CacheableJsonResponse;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
@@ -251,107 +252,199 @@ class CorpusController extends ControllerBase {
|
||||
// /_/ \_\_| \__|_\__|_\___/__/ |___|_||_\__,_\___/_\_\
|
||||
|
||||
|
||||
private function articlesQuery() {
|
||||
$query = \Drupal::entityQuery('node')
|
||||
->condition('status', 1)
|
||||
->condition('type', 'enregistrement')
|
||||
->condition('body', '', "<>")
|
||||
->sort('created', 'DESC');
|
||||
// ->range(0,20);
|
||||
private function articlesQuery() {
|
||||
$query = \Drupal::entityQuery('node')
|
||||
->condition('status', 1)
|
||||
->condition('type', 'enregistrement')
|
||||
->condition('body', '', "<>")
|
||||
->sort('created', 'DESC');
|
||||
// ->range(0,20);
|
||||
|
||||
$nids = $query->execute();
|
||||
$nodes = entity_load_multiple('node', $nids);
|
||||
$nids = $query->execute();
|
||||
$nodes = entity_load_multiple('node', $nids);
|
||||
|
||||
$current_langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||
$current_langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||
|
||||
$this->articles_nodes = [];
|
||||
$this->articles_nids = [];
|
||||
foreach ($nodes as $node) {
|
||||
// remove masqué
|
||||
$sid = WorkflowManager::getCurrentStateId($node, 'field_workflow');
|
||||
if($sid != 'corpus_documents_publie') continue;
|
||||
$this->articles_nodes = [];
|
||||
$this->articles_nids = [];
|
||||
foreach ($nodes as $node) {
|
||||
// remove masqué
|
||||
$sid = WorkflowManager::getCurrentStateId($node, 'field_workflow');
|
||||
if($sid != 'corpus_documents_publie') continue;
|
||||
|
||||
// TODO: check if article is translated
|
||||
if ($node->getTranslation($current_langcode)->body->isEmpty()) continue;
|
||||
|
||||
$this->articles_nodes[] = $node;
|
||||
// record an array of nids for corpus map filtering
|
||||
$this->articles_nids[] = $node->get('nid')->getString();
|
||||
}
|
||||
// TODO: check if article is translated
|
||||
if ($node->getTranslation($current_langcode)->body->isEmpty()) continue;
|
||||
|
||||
$this->articles_nodes[] = $node;
|
||||
// record an array of nids for corpus map filtering
|
||||
$this->articles_nids[] = $node->get('nid')->getString();
|
||||
}
|
||||
|
||||
private function articlesToRenderable(){
|
||||
$this->articlesQuery();
|
||||
// dpm($this->next_event_node);
|
||||
}
|
||||
|
||||
return array(
|
||||
"#theme"=>'edlp_corpus_articlesindex',
|
||||
'#articles_nodes' => $this->articles_nodes
|
||||
);
|
||||
private function articlesToRenderable(){
|
||||
$this->articlesQuery();
|
||||
// dpm($this->next_event_node);
|
||||
|
||||
}
|
||||
/**
|
||||
* Display lastdocs as a page.
|
||||
*
|
||||
* @return renderable array
|
||||
*/
|
||||
public function articlesindex() {
|
||||
return $this->articlesToRenderable();
|
||||
}
|
||||
return array(
|
||||
"#theme"=>'edlp_corpus_articlesindex',
|
||||
'#articles_nodes' => $this->articles_nodes
|
||||
);
|
||||
|
||||
/**
|
||||
* Get lastdocs data as json through ajax.
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function articlesindexjson() {
|
||||
}
|
||||
/**
|
||||
* Display lastdocs as a page.
|
||||
*
|
||||
* @return renderable array
|
||||
*/
|
||||
public function articlesindex() {
|
||||
return $this->articlesToRenderable();
|
||||
}
|
||||
|
||||
$renderable = $this->articlesToRenderable();
|
||||
// $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);
|
||||
});
|
||||
/**
|
||||
* Get lastdocs data as json through ajax.
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function articlesindexjson() {
|
||||
|
||||
$data = [
|
||||
'rendered'=> $rendered,
|
||||
'title'=>'Articles',
|
||||
'articles' => $this->articles_nids,
|
||||
'documents_lies' => $this->articles_nids,
|
||||
$renderable = $this->articlesToRenderable();
|
||||
// $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'=>'Articles',
|
||||
'articles' => $this->articles_nids,
|
||||
'documents_lies' => $this->articles_nids,
|
||||
];
|
||||
|
||||
// translations links
|
||||
// use Drupal\Core\Url;
|
||||
// use Drupal\Core\Language\LanguageInterface;
|
||||
$route_name = 'edlp_corpus.articlesindex';
|
||||
$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);});
|
||||
|
||||
// translations links
|
||||
// use Drupal\Core\Url;
|
||||
// use Drupal\Core\Language\LanguageInterface;
|
||||
$route_name = 'edlp_corpus.articlesindex';
|
||||
$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-articlesindex-cache']
|
||||
];
|
||||
|
||||
// $response = new JsonResponse();
|
||||
// $response->setData($data);
|
||||
$response = new CacheableJsonResponse($data);
|
||||
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($data));
|
||||
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($renderable));
|
||||
|
||||
return $response;
|
||||
$data['translations_links'] = $translations_rendered;
|
||||
}
|
||||
|
||||
$data['#cache'] = [
|
||||
'max-age' => \Drupal\Core\Cache\Cache::PERMANENT,
|
||||
'tags' => ['edlp-articlesindex-cache']
|
||||
];
|
||||
|
||||
// $response = new JsonResponse();
|
||||
// $response->setData($data);
|
||||
$response = new CacheableJsonResponse($data);
|
||||
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($data));
|
||||
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($renderable));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ___ _ _ _ _
|
||||
// / __|___| | |___ __| |_(_)___ _ _
|
||||
// | (__/ _ \ | / -_) _| _| / _ \ ' \
|
||||
// \___\___/_|_\___\__|\__|_\___/_||_|
|
||||
|
||||
private function collectionQuery(){
|
||||
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||
|
||||
$query = \Drupal::entityQuery('taxonomy_term')
|
||||
// ->sort('weight', 'DESC')
|
||||
// ->sort('name', 'DESC')
|
||||
->condition('vid', 'entrees');
|
||||
|
||||
$tids = $query->execute();
|
||||
// $terms = entity_load_multiple('taxonomy_term', $tids);
|
||||
// $terms = \Drupal::entityManager()->getStorage('taxonomy_term')->loadMultiple($terms);
|
||||
$terms = Term::loadMultiple($tids);
|
||||
|
||||
$ordered_terms = [];
|
||||
foreach ($terms as $term) {
|
||||
// remove masqué
|
||||
$sid = WorkflowManager::getCurrentStateId($term, 'field_workflow');
|
||||
if($sid == 'generique_masque') continue;
|
||||
// translate the term
|
||||
$term = \Drupal::service('entity.repository')->getTranslationFromContext($term, $language);
|
||||
$name = $term->getName();
|
||||
$ordered_trans_terms[$name] = $term;
|
||||
}
|
||||
ksort($ordered_trans_terms);
|
||||
$this->entrees_terms = $ordered_trans_terms;
|
||||
|
||||
}
|
||||
|
||||
private function collectionToRenderable(){
|
||||
$this->collectionQuery();
|
||||
|
||||
return array(
|
||||
"#theme"=>'edlp_corpus_collection',
|
||||
'#entrees_terms' => $this->entrees_terms
|
||||
);
|
||||
}
|
||||
|
||||
public function collection(){
|
||||
return $this->collectionToRenderable();
|
||||
}
|
||||
|
||||
public function collectionjson(){
|
||||
$renderable = $this->collectionToRenderable();
|
||||
// $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'=>'Collection'
|
||||
];
|
||||
|
||||
// translations links
|
||||
// use Drupal\Core\Url;
|
||||
// use Drupal\Core\Language\LanguageInterface;
|
||||
$route_name = 'edlp_corpus.collection';
|
||||
$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-articlesindex-cache']
|
||||
];
|
||||
|
||||
// $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,3 @@
|
||||
{% if entrees %}
|
||||
{{ entrees }}
|
||||
{% endif %}
|
||||
@@ -25,7 +25,8 @@ function edlp_home_theme($existing, $type, $theme, $path) {
|
||||
'promoted_nodes' => array(),
|
||||
'lastdocs_items' => NULL,
|
||||
'agenda_items' => NULL,
|
||||
'entrees_items' => NULL,
|
||||
// 'entrees_items' => NULL,
|
||||
'collection_link' => NULL,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -21,3 +21,11 @@ edlp_home.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'
|
||||
|
||||
@@ -4,7 +4,7 @@ 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');
|
||||
// $term_view_builder = \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term');
|
||||
// dpm($vars);
|
||||
|
||||
// render the promoted_nodes
|
||||
@@ -34,21 +34,6 @@ function template_preprocess_edlp_home(&$vars){
|
||||
}
|
||||
}
|
||||
|
||||
// render the presentation column
|
||||
// $vars["presentation"] = array(
|
||||
// "#type"=>"container",
|
||||
// "pres"=>$node_view_builder->view($vars["presentation_node"], 'default'),
|
||||
// "link"=> array(
|
||||
// '#title' => t('Visiter la collection sonore.'),
|
||||
// '#type' => 'link',
|
||||
// '#url' => Url::fromRoute('<front>', [], array(
|
||||
// 'attributes' => array(
|
||||
// 'class' => ['corpus-link', 'ajax-link']
|
||||
// )
|
||||
// ))
|
||||
// )
|
||||
// );
|
||||
|
||||
// render the last fil column
|
||||
// $vars["last_fil"] = array(
|
||||
// "#type" => "container",
|
||||
@@ -81,21 +66,6 @@ function template_preprocess_edlp_home(&$vars){
|
||||
// // )
|
||||
// );
|
||||
|
||||
// render the last production column
|
||||
// $vars["last_production"] = array(
|
||||
// '#type' => 'container',
|
||||
// 'prod' => $node_view_builder->view($vars['last_production_node'], 'teaser'),
|
||||
// 'link'=> array(
|
||||
// '#title' => t('Voir toutes les productions.'),
|
||||
// '#type' => 'link',
|
||||
// '#url' => Url::fromRoute('edlp_productions.productions', [], array(
|
||||
// 'attributes' => array(
|
||||
// 'class' => ['productions-link', 'ajax-link']
|
||||
// )
|
||||
// ))
|
||||
// )
|
||||
// );
|
||||
|
||||
|
||||
// render the lasts documents of collection as list
|
||||
if(isset($vars['lastdocs_items'])){
|
||||
@@ -156,25 +126,24 @@ function template_preprocess_edlp_home(&$vars){
|
||||
$vars['agenda'] = render($agenda);
|
||||
}
|
||||
|
||||
if(isset($vars['entrees_items'])){
|
||||
$entrees = array(
|
||||
if(isset($vars['collection_link'])){
|
||||
$collection = array(
|
||||
'#type'=>"container",
|
||||
// '#attributes' => array(
|
||||
// 'id' => array('collection'),
|
||||
// ),
|
||||
'#prefix' => '<div id="collection"></div>',
|
||||
'title'=>array(
|
||||
'#markup'=>"<h3>".t("Collection")."</h3>",
|
||||
),
|
||||
'list'=> array(
|
||||
'#theme' => 'item_list',
|
||||
'#items' => [],
|
||||
),
|
||||
'#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'),
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
foreach($vars['entrees_items'] as $term){
|
||||
$entrees['list']['#items'][] = $term_view_builder->view($term, 'home_mobile');
|
||||
}
|
||||
$vars['entrees'] = render($entrees);
|
||||
$vars['collection'] = render($collection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,13 @@ use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\workflow\Entity\WorkflowManager;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
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 {
|
||||
@@ -99,16 +105,17 @@ class HomeController extends ControllerBase {
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display agenda as a page.
|
||||
* Display home mobile as a page.
|
||||
*
|
||||
* @return renderable array
|
||||
*/
|
||||
public function home_mobile() {
|
||||
public function toMobileHomeRenderable() {
|
||||
|
||||
// $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
|
||||
|
||||
$contents = array("#theme"=>'edlp_home');
|
||||
$renderable = array("#theme"=>'edlp_home');
|
||||
|
||||
// first get static pages
|
||||
$query = \Drupal::entityQuery('node')
|
||||
@@ -117,7 +124,7 @@ class HomeController extends ControllerBase {
|
||||
->condition('type', 'static');
|
||||
|
||||
$promoted_nids = $query->execute();
|
||||
$contents["#promoted_nodes"] = entity_load_multiple('node', $promoted_nids);
|
||||
$renderable["#promoted_nodes"] = entity_load_multiple('node', $promoted_nids);
|
||||
|
||||
// then get production pages
|
||||
$query = \Drupal::entityQuery('node')
|
||||
@@ -126,7 +133,7 @@ class HomeController extends ControllerBase {
|
||||
->condition('type', 'page');
|
||||
|
||||
$promoted_nids = $query->execute();
|
||||
$contents["#promoted_nodes"] += entity_load_multiple('node', $promoted_nids);
|
||||
$renderable["#promoted_nodes"] += entity_load_multiple('node', $promoted_nids);
|
||||
|
||||
// last fil
|
||||
// $query = \Drupal::entityQuery('node')
|
||||
@@ -136,8 +143,8 @@ class HomeController extends ControllerBase {
|
||||
// ->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.');
|
||||
// $renderable["#last_fil_node"] = entity_load('node', array_pop($fil));
|
||||
// $renderable["#last_fil_node"] = array('#markup'=>'En développement.');
|
||||
|
||||
// agenda
|
||||
$now = new DrupalDateTime('now');
|
||||
@@ -151,100 +158,79 @@ class HomeController extends ControllerBase {
|
||||
->sort('field_date');
|
||||
|
||||
$events = $query->execute();
|
||||
$contents['#agenda_items'] = entity_load_multiple('node', $events);
|
||||
$renderable['#agenda_items'] = entity_load_multiple('node', $events);
|
||||
|
||||
|
||||
// entrées
|
||||
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||
// 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(),
|
||||
);
|
||||
|
||||
$query = \Drupal::entityQuery('taxonomy_term')
|
||||
// ->sort('weight', 'DESC')
|
||||
// ->sort('name', 'DESC')
|
||||
->condition('vid', 'entrees');
|
||||
|
||||
$tids = $query->execute();
|
||||
// $terms = entity_load_multiple('taxonomy_term', $tids);
|
||||
// $terms = \Drupal::entityManager()->getStorage('taxonomy_term')->loadMultiple($terms);
|
||||
$terms = Term::loadMultiple($tids);
|
||||
|
||||
$ordered_terms = [];
|
||||
foreach ($terms as $term) {
|
||||
// remove masqué
|
||||
$sid = WorkflowManager::getCurrentStateId($term, 'field_workflow');
|
||||
if($sid == 'generique_masque') continue;
|
||||
// translate the term
|
||||
$term = \Drupal::service('entity.repository')->getTranslationFromContext($term, $language);
|
||||
$name = $term->getName();
|
||||
$ordered_trans_terms[$name] = $term;
|
||||
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;
|
||||
}
|
||||
|
||||
ksort($ordered_trans_terms);
|
||||
$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));
|
||||
|
||||
// dsm($terms);
|
||||
// foreach ($ordered_trans_terms as $name => $term) {
|
||||
// $tid = $term->id();
|
||||
//
|
||||
// $entree = array(
|
||||
// 'tid'=>$tid
|
||||
// );
|
||||
|
||||
// term link
|
||||
// $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term'=>$tid]);
|
||||
// $url->setOptions(array(
|
||||
// 'attributes' => array(
|
||||
// 'class' => ['term-'.$tid, 'term-link'],
|
||||
// 'tid'=>$tid,
|
||||
// 'selector' => 'entree-term-link-'.$tid,
|
||||
// 'data-drupal-link-system-path' => $url->getInternalPath()
|
||||
// )
|
||||
// ));
|
||||
// $entree['term_link'] = Link::fromTextAndUrl($name, $url);
|
||||
// index link
|
||||
// $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term'=>$tid]);
|
||||
// $url->setOptions(array(
|
||||
// 'attributes' => array(
|
||||
// 'class' => ['index-link', 'ajax-link'],
|
||||
// 'viewmode'=>'index',
|
||||
// 'tid'=>$tid,
|
||||
// 'selector' => 'entree-index-link-'.$tid,
|
||||
// 'data-drupal-link-system-path' => $url->getInternalPath()
|
||||
// )
|
||||
// ));
|
||||
// $entree['index_link'] = Link::fromTextAndUrl('index', $url);
|
||||
|
||||
// notice-link
|
||||
// $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term'=>$tid]);
|
||||
// $url->setOptions(array(
|
||||
// 'attributes' => array(
|
||||
// 'class' => ['notice-link'],
|
||||
// 'viewmode'=>'notice',
|
||||
// 'tid'=>$tid,
|
||||
// 'selector' => 'entree-notice-link-'.$tid,
|
||||
// 'data-drupal-link-system-path' => $url->getInternalPath()
|
||||
// )
|
||||
// ));
|
||||
// $entree['notice_link'] = Link::fromTextAndUrl('notice', $url);
|
||||
|
||||
// $entree['description'] = $term->get('description')->value;
|
||||
//
|
||||
// $entrees[] = $entree;
|
||||
// }
|
||||
|
||||
$contents['#entrees_items'] = $ordered_trans_terms;
|
||||
|
||||
// = array (
|
||||
// '#theme' => 'blockentrees',
|
||||
// '#entrees_items' => $entrees,
|
||||
// '#attached'=>array(
|
||||
// 'library' => array('edlp_corpus/corpus'),
|
||||
// 'drupalSettings' => array(
|
||||
// 'basepath' => base_path()
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
|
||||
|
||||
return $contents;
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
{{ agenda }}
|
||||
{% endif %}
|
||||
|
||||
{% if entrees %}
|
||||
{{ entrees }}
|
||||
{% if collection %}
|
||||
{{ collection }}
|
||||
{% endif %}
|
||||
|
||||
@@ -116,7 +116,7 @@ function edlp_mobile_page_attachments(array &$attachments) {
|
||||
// we assume that there is only two alias by env (mobile or desktop)
|
||||
foreach ($env_aliases as $env_alias_id => $env_alias) {
|
||||
if($env_alias_id != $alias->id()){
|
||||
// we found the desktop pattern
|
||||
// we found the mobile pattern
|
||||
$mobile_url = $env_alias->getPattern();
|
||||
break;
|
||||
}
|
||||
@@ -128,6 +128,13 @@ function edlp_mobile_page_attachments(array &$attachments) {
|
||||
$is_front = \Drupal::service('path.matcher')->isFrontPage();
|
||||
$current_language = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||
|
||||
// $config->set($domain_id . '.site_frontpage', $site_frontpage);
|
||||
|
||||
// $mobile_home_path = "???";
|
||||
$mobile_home_path = \Drupal::config('domain_site_settings.domainconfigsettings')->get('m_encyclopediedelaparole_org.site_frontpage', FALSE);
|
||||
// $desktop_home_path = "???";
|
||||
$desktop_home_path = \Drupal::config('domain_site_settings.domainconfigsettings')->get('encyclopediedelaparole_org.site_frontpage', FALSE);
|
||||
|
||||
// $redirect = false;
|
||||
$js_str = "var edlp_mobile = {\n
|
||||
current_url:'".$base_root."',\n
|
||||
@@ -136,7 +143,9 @@ function edlp_mobile_page_attachments(array &$attachments) {
|
||||
lang_code:'".$current_language."',\n
|
||||
is_mobile_domain:".($is_mobile_domain ? 'true':'false').",\n
|
||||
mobile_url:'".$mobile_url."',\n
|
||||
mobile_home_path:'".$mobile_home_path."',\n
|
||||
desktop_url:'".$desktop_url."',\n
|
||||
desktop_home_path:'".$desktop_home_path."',\n
|
||||
};";
|
||||
|
||||
$attachments['#attached']['html_head'][] = [
|
||||
|
||||
Reference in New Issue
Block a user