diff --git a/sites/all/modules/figli/edlp_corpus/blockentrees.inc b/sites/all/modules/figli/edlp_corpus/blockentrees.inc new file mode 100644 index 000000000..414a7ef3f --- /dev/null +++ b/sites/all/modules/figli/edlp_corpus/blockentrees.inc @@ -0,0 +1,73 @@ + 'item_list', + '#items' => array(), + ); + + foreach ($vars['entrees_items'] as $entree) { + + $tid = $entree['tid']; + + $term_link = $entree['term_link']->toRenderable(); + $term_link['#prefix'] = ''; + $term_link['#suffix'] = ""; + $term_link["#attributes"] = array( + "class" => array('term-'.$tid, 'term-link'), + "tid" => $tid + ); + + $index_link = $entree['index_link']->toRenderable(); + $index_link['#prefix'] = ''; + $index_link['#suffix'] = ""; + $index_link['#attributes'] = array( + 'class' => array('index-link'), + "tid" => $tid + ); + + + $notice_link = $entree['notice_link']->toRenderable(); + $notice_link['#prefix'] = ''; + $notice_link['#suffix'] = ""; + $notice_link['#attributes'] = array( + 'class' => array('notice-link'), + "tid" => $tid + ); + + + $entree = array( + '#wrapper_attributes' => array( + 'class' => array('term-'.$tid, 'entree'), + 'tid' => $tid + ), + 'term_link' => $term_link, + 'entree_content' => array( + '#type' => 'container', + '#attributes' => array( + 'class' => 'entree-content' + ), + 'index_link' => $index_link, + 'notice_link' => $notice_link, + 'description' => array( + '#type' => 'container', + '#markup' => $entree['description'], + '#attributes' => array('class'=>'term-description') + ) + ) + ); + + // if (isset($entrees) && count($entrees) == count($terms)-3) { + // $entree['#wrapper_attributes']['class'][] = 'opened'; + // } + + // dpm($entree); + + $entrees['#items'][] = $entree; + } + + $vars['entrees'] = render($entrees); + +} diff --git a/sites/all/modules/figli/edlp_corpus/edlp_corpus.module b/sites/all/modules/figli/edlp_corpus/edlp_corpus.module index 218a862da..3287836c6 100644 --- a/sites/all/modules/figli/edlp_corpus/edlp_corpus.module +++ b/sites/all/modules/figli/edlp_corpus/edlp_corpus.module @@ -7,16 +7,35 @@ # @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(), + ), + ), + ); +} + + /** * Implements hook_page_attachments(). * @param array $attachments */ -function edlp_corpus_page_attachments(array &$attachments) { - //add here any conditions if you need to limit the pages - if (\Drupal::service('path.matcher')->isFrontPage()) { - // $attachments['#attached']['library'][] = 'edlp_corpus/corpus'; - // $attachments['#attached']['drupalSettings']['basepath'] = base_path(); - // $attachments['#attached']['drupalSettings']['pathtoedlpcorpus'] = base_path() . drupal_get_path('module', 'edlp_corpus'); - // $attachments['#attached']['drupalSettings']['pathtotfiles'] = PublicStream::basePath(); - } -} +// function edlp_corpus_page_attachments(array &$attachments) { +// //add here any conditions if you need to limit the pages +// if (\Drupal::service('path.matcher')->isFrontPage()) { +// // $attachments['#attached']['library'][] = 'edlp_corpus/corpus'; +// // $attachments['#attached']['drupalSettings']['basepath'] = base_path(); +// // $attachments['#attached']['drupalSettings']['pathtoedlpcorpus'] = base_path() . drupal_get_path('module', 'edlp_corpus'); +// // $attachments['#attached']['drupalSettings']['pathtotfiles'] = PublicStream::basePath(); +// } +// } diff --git a/sites/all/modules/figli/edlp_corpus/src/Plugin/Block/BlockEntrees.php b/sites/all/modules/figli/edlp_corpus/src/Plugin/Block/BlockEntrees.php index 65f834cb8..44e16d0d4 100644 --- a/sites/all/modules/figli/edlp_corpus/src/Plugin/Block/BlockEntrees.php +++ b/sites/all/modules/figli/edlp_corpus/src/Plugin/Block/BlockEntrees.php @@ -31,76 +31,30 @@ class BlockEntrees extends BlockBase { // dsm($terms); foreach ($terms as $term) { // dpm($term->toArray()); - $tid = $term->id(); $name = $term->getName(); - $term_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]); - $term_link = Link::fromTextAndUrl($name, $term_url)->toRenderable(); - $term_link['#prefix'] = ''; - $term_link['#suffix'] = ""; - $term_link["#attributes"] = array( - "class" => array('term-'.$term->id(), 'term-link'), - "tid" => $term->id() + $entree = array( + 'tid'=>$tid ); + $term_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]); + $entree['term_link'] = Link::fromTextAndUrl($name, $term_url); + $index_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]); - $index_link = Link::fromTextAndUrl('index', $index_url)->toRenderable(); - $index_link['#prefix'] = ''; - $index_link['#suffix'] = ""; - $index_link['#attributes'] = array( - 'class' => array('index-link'), - "tid" => $term->id() - ); - + $entree['index_link'] = Link::fromTextAndUrl('index', $index_url); $notice_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]); - $notice_link = Link::fromTextAndUrl('notice', $notice_url)->toRenderable(); - $notice_link['#prefix'] = ''; - $notice_link['#suffix'] = ""; - $notice_link['#attributes'] = array( - 'class' => array('notice-link'), - "tid" => $term->id() - ); + $entree['notice_link'] = Link::fromTextAndUrl('notice', $notice_url); - $description = $term->get('description')->value; - // dpm($description); - - // TODO: output block through twig and preprocess function - // TODO: load corpus map libraries only with this block - $entree = array( - '#wrapper_attributes' => array( - 'class' => array('term-'.$term->id(), 'entree'), - 'tid' => $term->id() - ), - 'term_link' => $term_link, - 'entree_content' => array( - '#type' => 'container', - '#attributes' => array( - 'class' => 'entree-content' - ), - 'index_link' => $index_link, - 'notice_link' => $notice_link, - 'description' => array( - '#type' => 'container', - '#markup' => $description, - '#attributes' => array('class'=>'term-description') - ) - ) - ); - - // if (isset($entrees) && count($entrees) == count($terms)-3) { - // $entree['#wrapper_attributes']['class'][] = 'opened'; - // } - - // dpm($entree); + $entree['description'] = $term->get('description')->value; $entrees[] = $entree; } return array ( - '#theme' => 'item_list', - '#items' => $entrees, + '#theme' => 'blockentrees', + '#entrees_items' => $entrees, '#attached'=>array( 'library' => array('edlp_corpus/corpus'), 'drupalSettings' => array( diff --git a/sites/all/modules/figli/edlp_corpus/templates/blockentrees.html.twig b/sites/all/modules/figli/edlp_corpus/templates/blockentrees.html.twig new file mode 100644 index 000000000..a0f0f71d0 --- /dev/null +++ b/sites/all/modules/figli/edlp_corpus/templates/blockentrees.html.twig @@ -0,0 +1,2 @@ + +{{ entrees }}