edlp_corpus.module 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. # @Author: Bachir Soussi Chiadmi <bach>
  3. # @Date: 13-12-2017
  4. # @Email: bachir@figureslibres.io
  5. # @Filename: edlp_corpus.routing.yml
  6. # @Last modified by: bach
  7. # @Last modified time: 20-12-2017
  8. # @License: GPL-V3
  9. /**
  10. * Implements hook_theme().
  11. */
  12. function edlp_corpus_theme($existing, $type, $theme, $path) {
  13. // @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
  14. return array(
  15. 'blockentrees' => array(
  16. // 'render element' => '',
  17. 'file' => 'blockentrees.inc',
  18. 'variables' => array(
  19. 'entrees_items' => array(),
  20. ),
  21. ),
  22. );
  23. }
  24. /**
  25. * hook_entity_extra_field_info()
  26. *
  27. */
  28. function edlp_corpus_entity_extra_field_info(){
  29. $extra = [];
  30. $extra['taxonomy_term']['entrees']['display']['index'] = [
  31. 'label' => t('Index'),
  32. 'description' => 'Display index of all documents tagued with the term',
  33. 'weight' => 99,
  34. // 'visible' => FALSE,
  35. ];
  36. return $extra;
  37. }
  38. /**
  39. * Implements hook_ENTITY_TYPE_view().
  40. * @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8
  41. */
  42. function edlp_corpus_taxonomy_term_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
  43. $index_display_settings = $display->getComponent('index');
  44. if (!empty($index_display_settings)) {
  45. // dpm($entity);
  46. // dpm($entity->id());
  47. $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
  48. $query = \Drupal::entityQuery('node')
  49. ->condition('status', 1)
  50. ->condition('type', 'enregistrement')
  51. ->condition('field_entrees', $entity->id());
  52. $documents_nids = $query->execute();
  53. $documents = entity_load_multiple('node', $documents_nids);
  54. $documents_list = array (
  55. '#theme' => 'item_list',
  56. '#items' => [],
  57. );
  58. foreach($documents as $doc){
  59. $documents_list['#items'][] = $view_builder->view($doc, 'index');
  60. }
  61. // And the last step is to actually build the tree.
  62. $build['index'] = array(
  63. '#type'=>"container",
  64. '#attributes'=>array(
  65. 'class'=>'index'
  66. ),
  67. 'label'=>array(
  68. '#type' => 'container',
  69. "#markup"=> t("Index"),
  70. '#attributes'=>array(
  71. 'class'=>'field__label'
  72. ),
  73. ),
  74. 'documents'=> $documents_list
  75. );
  76. }
  77. }
  78. /**
  79. * Implements hook_page_attachments().
  80. * @param array $attachments
  81. */
  82. // function edlp_corpus_page_attachments(array &$attachments) {
  83. // //add here any conditions if you need to limit the pages
  84. // if (\Drupal::service('path.matcher')->isFrontPage()) {
  85. // // $attachments['#attached']['library'][] = 'edlp_corpus/corpus';
  86. // // $attachments['#attached']['drupalSettings']['basepath'] = base_path();
  87. // // $attachments['#attached']['drupalSettings']['pathtoedlpcorpus'] = base_path() . drupal_get_path('module', 'edlp_corpus');
  88. // // $attachments['#attached']['drupalSettings']['pathtotfiles'] = PublicStream::basePath();
  89. // }
  90. // }