123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- # @Author: Bachir Soussi Chiadmi <bach>
- # @Date: 13-12-2017
- # @Email: bachir@figureslibres.io
- # @Filename: edlp_corpus.routing.yml
- # @Last modified by: bach
- # @Last modified time: 20-12-2017
- # @License: GPL-V3
- /**
- * Implements hook_theme().
- */
- function edlp_corpus_theme($existing, $type, $theme, $path) {
- // @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
- return array(
- 'blockentrees' => array(
- // 'render element' => '',
- 'file' => 'blockentrees.inc',
- 'variables' => array(
- 'entrees_items' => array(),
- ),
- ),
- );
- }
- /**
- * 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();
- $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'
- ),
- 'label'=>array(
- '#type' => 'container',
- "#markup"=> t("Index"),
- '#attributes'=>array(
- 'class'=>'field__label'
- ),
- ),
- 'documents'=> $documents_list
- );
- }
- }
- /**
- * Implements hook_page_attachments().
- * @param array $attachments
- */
- function edlp_corpus_page_attachments(array &$attachments) {
- // css class
- // :root{
- // --e-col-130:#4B8F7E;
- // }
- // javascript list
- // drupalSettings edlp_corpus{
- // "e_col_130": "rgb(75, 143, 126)",
- // }
- // get all entries
- $query = \Drupal::entityQuery('taxonomy_term')
- ->condition('vid', 'entrees');
- $tids = $query->execute();
- $terms = entity_load_multiple('taxonomy_term', $tids);
- $js_list = [];
- $css_str = ":root{\n";
- foreach ($terms as $term) {
- $tid = $term->id();
- // get the color value
- $color = $term->get('field_color')->color;
- // build colors list
- $css_str .= "\t".'--e-col-'.$tid.':'.$color.";\n";
- $js_list['e_col_'.$tid] = $color;
- }
- $css_str .= '}';
- // attache css
- // we should find a better way
- // https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module
- $attachments['#attached']['html_head'][] = [
- [
- '#type' => 'html_tag',
- '#tag' => 'style',
- '#value' => $css_str,
- ],
- // A key, to make it possible to recognize this HTML element when altering.
- 'edlp_colors',
- ];
- $attachments['#attached']['drupalSettings']['edlp_corpus']['colors'] = $js_list;
- }
|