Sfoglia il codice sorgente

entrees index and notice are ajax loaed and displayed

Bachir Soussi Chiadmi 6 anni fa
parent
commit
6d1b3d33bb

+ 12 - 1
sites/all/modules/figli/edlp_ajax/src/Controller/EdlpAjaxController.php

@@ -53,12 +53,23 @@ class EdlpAjaxController extends ControllerBase {
     $renderable = $this->toRenderable();
     $rendered = render($renderable);
 
+    switch($this->entity_type){
+      case 'node':
+        $bundle = $this->entity->getType();
+        break;
+      case 'taxonomy_term':
+        $bundle = $this->entity->bundle();
+        break;
+      default:
+        $bundle = NULL;
+    }
+
     $response = new JsonResponse();
     $response->setData([
       'test' => 'hello edlp ajax',
       'id' => $this->id,
       'view_mode' => $this->viewmode,
-      'bundle' => $this->entity->getType(),
+      'bundle' => $bundle,
       'entity_type' => $this->entity_type,
       'rendered'=> $rendered,
     ]);

+ 0 - 14
sites/all/modules/figli/edlp_corpus/blockentrees.inc

@@ -15,28 +15,14 @@ function template_preprocess_blockentrees(&$vars){
     $term_link = $entree['term_link']->toRenderable();
     $term_link['#prefix'] = '<span class="oblique-wrapper">';
     $term_link['#suffix'] = "</span>";
-    $term_link["#attributes"] = array(
-      "class" => array('term-'.$tid, 'term-link'),
-      "tid" => $tid
-    );
 
     $index_link = $entree['index_link']->toRenderable();
     $index_link['#prefix'] = '<span class="oblique-wrapper">';
     $index_link['#suffix'] = "</span>";
-    $index_link['#attributes'] = array(
-      'class' => array('index-link'),
-      "tid" => $tid
-    );
-
 
     $notice_link = $entree['notice_link']->toRenderable();
     $notice_link['#prefix'] = '<span class="oblique-wrapper">';
     $notice_link['#suffix'] = "</span>";
-    $notice_link['#attributes'] = array(
-      'class' => array('notice-link'),
-      "tid" => $tid
-    );
-
 
     $entree = array(
       '#wrapper_attributes' => array(

+ 59 - 0
sites/all/modules/figli/edlp_corpus/edlp_corpus.module

@@ -26,6 +26,65 @@ function edlp_corpus_theme($existing, $type, $theme, $path) {
 }
 
 
+/**
+* hook_entity_extra_field_info()
+*
+*/
+function edlp_corpus_entity_extra_field_info(){
+  $extra = [];
+  $extra['taxonomy_term']['entrees']['display']['index'] = [
+    'label' => t('Index'),
+    'description' => 'Display index of all documents tagued with the term',
+    'weight' => 99,
+    'visible' => FALSE,
+  ];
+  return $extra;
+}
+
+
+/**
+ * Implements hook_ENTITY_TYPE_view().
+ * @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8
+ */
+function edlp_corpus_taxonomy_term_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
+  $index_display_settings = $display->getComponent('index');
+  if (!empty($index_display_settings)) {
+    // dpm($entity);
+    // dpm($entity->id());
+    $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
+
+    $query = \Drupal::entityQuery('node')
+      ->condition('status', 1)
+      ->condition('type', 'enregistrement')
+      ->condition('field_entrees', $entity->id());
+
+    $documents_nids = $query->execute();
+    // dpm($documents_nids);
+    $documents = entity_load_multiple('node', $documents_nids);
+
+    $documents_list = array (
+      '#theme' => 'item_list',
+      '#items' => [],
+    );
+    foreach($documents as $doc){
+      $documents_list['#items'][] = $view_builder->view($doc, 'index');
+    }
+
+
+    // And the last step is to actually build the tree.
+    $build['index'] = array(
+      '#type'=>"container",
+      '#attributes'=>array(
+        'class'=>'index'
+      ),
+      'documents'=> $documents_list
+    );
+
+
+
+  }
+}
+
 /**
  * Implements hook_page_attachments().
  * @param array $attachments

+ 32 - 6
sites/all/modules/figli/edlp_corpus/src/Plugin/Block/BlockEntrees.php

@@ -38,14 +38,40 @@ class BlockEntrees extends BlockBase {
         'tid'=>$tid
       );
 
-      $term_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]);
-      $entree['term_link'] = Link::fromTextAndUrl($name, $term_url);
+      // term name
+      $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term'=>$tid]);
+      $url->setOptions(array(
+        'attributes' => array(
+          'class' => ['term-'.$tid, 'term-link'],
+          'tid'=>$tid,
+          'data-drupal-link-system-path' => $url->getInternalPath()
+        )
+      ));
+      $entree['term_link'] = Link::fromTextAndUrl($name, $url);
 
-      $index_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]);
-      $entree['index_link'] = Link::fromTextAndUrl('index', $index_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,
+          'data-drupal-link-system-path' => $url->getInternalPath()
+        )
+      ));
+      $entree['index_link'] = Link::fromTextAndUrl('index', $url);
 
-      $notice_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]);
-      $entree['notice_link'] = Link::fromTextAndUrl('notice', $notice_url);
+      // notice-link
+      $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term'=>$tid]);
+      $url->setOptions(array(
+        'attributes' => array(
+          'class' => ['notice-link', 'ajax-link'],
+          'viewmode'=>'notice',
+          'tid'=>$tid,
+          'data-drupal-link-system-path' => $url->getInternalPath()
+        )
+      ));
+      $entree['notice_link'] = Link::fromTextAndUrl('notice', $url);
 
       $entree['description'] = $term->get('description')->value;
 

+ 25 - 7
sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js

@@ -235,13 +235,22 @@ edlp_vars = {
     // TODO: implement history.js
     function  initAjaxLinks(){
       console.log('initAjaxLinks');
-      $('a', '#block-mainnavigation, #block-footer.menu--footer, #block-productions, article.node h2.node-title, .productions-subtree, .productions-parent').addClass('ajax-link');
+
+      $('a', '#block-mainnavigation')
+        .add('a', '#block-footer.menu--footer')
+        .add('a', '#block-productions')
+        .add('a', 'article.node:not(.node--type-enregistrement) h2.node-title')
+        .add('a', '.productions-subtree')
+        .add('a', '.productions-parent')
+        // .add('a.index-link, a.notice-link', '#block-edlpentreesblock')
+        .addClass('ajax-link');
+
 
       _$ajaxLinks = $('.ajax-link:not(.ajax-enabled)')
         .each(function(i,e){
           var $this = $(this);
           // avoid already ajaxified links
-          // if($this.is('.ajax-enable')) return;
+          if($this.is('.ajax-enable')) return;
           if($this.attr('data-drupal-link-system-path')){
             $this.on('click', onClickAjaxLink).addClass('ajax-enable');
           }
@@ -261,10 +270,19 @@ edlp_vars = {
         backToFrontPage();
         return false;
       }
-      m = ajax_path.match(/^\/?(node\/\d+)$/g);
-      if(m){
-        // convert node link to edlp_ajax_node module links
-        ajax_path = 'edlp/ajax/json/'+m[0];
+
+      // convert node link to edlp_ajax_node module links
+      var node_match = ajax_path.match(/^\/?(node\/\d+)$/g);
+      var term_match = ajax_path.match(/^\/?(taxonomy\/term\/\d+)$/g);
+      if(node_match){
+        ajax_path = 'edlp/ajax/json/'+node_match[0];
+        // check for viewmode attribute
+        if($link.attr('viewmode')){
+          ajax_path += '/'+$link.attr('viewmode');
+        }
+      }else if(term_match){
+        ajax_path = 'edlp/ajax/json/'+term_match[0];
+        ajax_path = ajax_path.replace(/taxonomy\/term/, 'taxonomy_term');
         // check for viewmode attribute
         if($link.attr('viewmode')){
           ajax_path += '/'+$link.attr('viewmode');
@@ -310,7 +328,7 @@ edlp_vars = {
         'view-mode-'+data.view_mode
       ];
       _$body.removeClass().addClass(body_classes.join(' '));
-      
+
       // id node add a generic path-node class to body
       m = sys_path.match(/^\/?(node\/\d+)$/g);
       if(m)

+ 25 - 7
sites/all/themes/custom/edlptheme/assets/scripts/main.js

@@ -212,13 +212,22 @@
     // TODO: implement history.js
     function  initAjaxLinks(){
       console.log('initAjaxLinks');
-      $('a', '#block-mainnavigation, #block-footer.menu--footer, #block-productions, article.node h2.node-title, .productions-subtree, .productions-parent').addClass('ajax-link');
+
+      $('a', '#block-mainnavigation')
+        .add('a', '#block-footer.menu--footer')
+        .add('a', '#block-productions')
+        .add('a', 'article.node:not(.node--type-enregistrement) h2.node-title')
+        .add('a', '.productions-subtree')
+        .add('a', '.productions-parent')
+        // .add('a.index-link, a.notice-link', '#block-edlpentreesblock')
+        .addClass('ajax-link');
+
 
       _$ajaxLinks = $('.ajax-link:not(.ajax-enabled)')
         .each(function(i,e){
           var $this = $(this);
           // avoid already ajaxified links
-          // if($this.is('.ajax-enable')) return;
+          if($this.is('.ajax-enable')) return;
           if($this.attr('data-drupal-link-system-path')){
             $this.on('click', onClickAjaxLink).addClass('ajax-enable');
           }
@@ -238,10 +247,19 @@
         backToFrontPage();
         return false;
       }
-      m = ajax_path.match(/^\/?(node\/\d+)$/g);
-      if(m){
-        // convert node link to edlp_ajax_node module links
-        ajax_path = 'edlp/ajax/json/'+m[0];
+
+      // convert node link to edlp_ajax_node module links
+      var node_match = ajax_path.match(/^\/?(node\/\d+)$/g);
+      var term_match = ajax_path.match(/^\/?(taxonomy\/term\/\d+)$/g);
+      if(node_match){
+        ajax_path = 'edlp/ajax/json/'+node_match[0];
+        // check for viewmode attribute
+        if($link.attr('viewmode')){
+          ajax_path += '/'+$link.attr('viewmode');
+        }
+      }else if(term_match){
+        ajax_path = 'edlp/ajax/json/'+term_match[0];
+        ajax_path = ajax_path.replace(/taxonomy\/term/, 'taxonomy_term');
         // check for viewmode attribute
         if($link.attr('viewmode')){
           ajax_path += '/'+$link.attr('viewmode');
@@ -287,7 +305,7 @@
         'view-mode-'+data.view_mode
       ];
       _$body.removeClass().addClass(body_classes.join(' '));
-      
+
       // id node add a generic path-node class to body
       m = sys_path.match(/^\/?(node\/\d+)$/g);
       if(m)

+ 12 - 0
sites/all/themes/custom/edlptheme/edlptheme.theme

@@ -73,6 +73,18 @@ function edlptheme_preprocess_node__player_cartel(&$vars){
       )
     )
   );
+  // TODO: refacorize the link generator as following :
+  // $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term'=>$tid]);
+  // $url->setOptions(array(
+  //   'attributes' => array(
+  //     'class' => ['index-link', 'ajax-link'],
+  //     'viewmode'=>'index',
+  //     'tid'=>$tid,
+  //     'data-drupal-link-system-path' => $url->getInternalPath()
+  //   )
+  // ));
+  // $entree['index_link'] = Link::fromTextAndUrl('index', $url);
+
   // if article not empty
   $url = Url::fromRoute('entity.node.canonical', ['node'=>$vars['node']->id()], array(
     'attributes' => array(

+ 7 - 0
sites/all/themes/custom/edlptheme/templates/content/edlp-ajax--taxonomy-term--index.html.twig

@@ -0,0 +1,7 @@
+<div class="row">
+  <div class="col small-col-12 med-col-6 large-col-6">
+    <div class="wrapper">
+      {{ content }}
+    </div>
+  </div>
+</div>

+ 7 - 0
sites/all/themes/custom/edlptheme/templates/content/edlp-ajax--taxonomy-term--notice.html.twig

@@ -0,0 +1,7 @@
+<div class="row">
+  <div class="col small-col-12 med-col-6 large-col-6">
+    <div class="wrapper">
+      {{ content }}
+    </div>
+  </div>
+</div>

+ 51 - 0
sites/default/config/sync/core.entity_view_display.node.enregistrement.index.yml

@@ -0,0 +1,51 @@
+uuid: baf35166-581f-4af8-8419-d1f7e68486ef
+langcode: fr
+status: true
+dependencies:
+  config:
+    - core.entity_view_mode.node.index
+    - field.field.node.enregistrement.body
+    - field.field.node.enregistrement.field_collectionneurs
+    - field.field.node.enregistrement.field_description
+    - field.field.node.enregistrement.field_entrees
+    - field.field.node.enregistrement.field_genres
+    - field.field.node.enregistrement.field_langues
+    - field.field.node.enregistrement.field_locuteurs
+    - field.field.node.enregistrement.field_son
+    - field.field.node.enregistrement.field_transcript_trad
+    - field.field.node.enregistrement.field_transcript_vo
+    - field.field.node.enregistrement.field_workflow
+    - node.type.enregistrement
+  module:
+    - text
+    - user
+id: node.enregistrement.index
+targetEntityType: node
+bundle: enregistrement
+mode: index
+content:
+  content_moderation_control:
+    weight: -20
+    region: content
+    settings: {  }
+    third_party_settings: {  }
+  field_description:
+    weight: 0
+    label: hidden
+    settings: {  }
+    third_party_settings: {  }
+    type: text_default
+    region: content
+hidden:
+  body: true
+  field_collectionneurs: true
+  field_entrees: true
+  field_genres: true
+  field_langues: true
+  field_locuteurs: true
+  field_son: true
+  field_transcript_trad: true
+  field_transcript_vo: true
+  field_workflow: true
+  langcode: true
+  links: true

+ 24 - 0
sites/default/config/sync/core.entity_view_display.taxonomy_term.entrees.index.yml

@@ -0,0 +1,24 @@
+uuid: 400850ef-44ad-4af3-b100-530035b8912e
+langcode: fr
+status: true
+dependencies:
+  config:
+    - core.entity_view_mode.taxonomy_term.index
+    - field.field.taxonomy_term.entrees.field_notice
+    - field.field.taxonomy_term.entrees.field_workflow
+    - taxonomy.vocabulary.entrees
+id: taxonomy_term.entrees.index
+targetEntityType: taxonomy_term
+bundle: entrees
+mode: index
+content:
+  index:
+    weight: 0
+    region: content
+    settings: {  }
+    third_party_settings: {  }
+hidden:
+  description: true
+  field_notice: true
+  field_workflow: true
+  langcode: true

+ 27 - 0
sites/default/config/sync/core.entity_view_display.taxonomy_term.entrees.notice.yml

@@ -0,0 +1,27 @@
+uuid: d4954690-a57f-4c44-a8e1-0b3d4c177fc5
+langcode: fr
+status: true
+dependencies:
+  config:
+    - core.entity_view_mode.taxonomy_term.notice
+    - field.field.taxonomy_term.entrees.field_notice
+    - field.field.taxonomy_term.entrees.field_workflow
+    - taxonomy.vocabulary.entrees
+  module:
+    - text
+id: taxonomy_term.entrees.notice
+targetEntityType: taxonomy_term
+bundle: entrees
+mode: notice
+content:
+  field_notice:
+    weight: 0
+    label: above
+    settings: {  }
+    third_party_settings: {  }
+    type: text_default
+    region: content
+hidden:
+  description: true
+  field_workflow: true
+  langcode: true

+ 10 - 0
sites/default/config/sync/core.entity_view_mode.node.index.yml

@@ -0,0 +1,10 @@
+uuid: daef700e-ff46-4cb1-8e3f-2e30724b8381
+langcode: fr
+status: true
+dependencies:
+  module:
+    - node
+id: node.index
+label: 'Index (Document)'
+targetEntityType: node
+cache: true

+ 10 - 0
sites/default/config/sync/core.entity_view_mode.taxonomy_term.index.yml

@@ -0,0 +1,10 @@
+uuid: 045d9598-0caa-41c1-950e-48aab5c209a2
+langcode: fr
+status: true
+dependencies:
+  module:
+    - taxonomy
+id: taxonomy_term.index
+label: Index
+targetEntityType: taxonomy_term
+cache: true

+ 10 - 0
sites/default/config/sync/core.entity_view_mode.taxonomy_term.notice.yml

@@ -0,0 +1,10 @@
+uuid: 3ae686de-495f-4315-bfdf-fd6b114de08e
+langcode: fr
+status: true
+dependencies:
+  module:
+    - taxonomy
+id: taxonomy_term.notice
+label: 'Notice (Entrees)'
+targetEntityType: taxonomy_term
+cache: true