edlp_corpus module : created twig template and preprocessor for entrees bloc output
This commit is contained in:
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
function template_preprocess_blockentrees(&$vars){
|
||||||
|
|
||||||
|
$entrees = array (
|
||||||
|
'#theme' => 'item_list',
|
||||||
|
'#items' => array(),
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($vars['entrees_items'] as $entree) {
|
||||||
|
|
||||||
|
$tid = $entree['tid'];
|
||||||
|
|
||||||
|
$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(
|
||||||
|
'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);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,16 +7,35 @@
|
|||||||
# @Last modified time: 20-12-2017
|
# @Last modified time: 20-12-2017
|
||||||
# @License: GPL-V3
|
# @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().
|
* Implements hook_page_attachments().
|
||||||
* @param array $attachments
|
* @param array $attachments
|
||||||
*/
|
*/
|
||||||
function edlp_corpus_page_attachments(array &$attachments) {
|
// function edlp_corpus_page_attachments(array &$attachments) {
|
||||||
//add here any conditions if you need to limit the pages
|
// //add here any conditions if you need to limit the pages
|
||||||
if (\Drupal::service('path.matcher')->isFrontPage()) {
|
// if (\Drupal::service('path.matcher')->isFrontPage()) {
|
||||||
// $attachments['#attached']['library'][] = 'edlp_corpus/corpus';
|
// // $attachments['#attached']['library'][] = 'edlp_corpus/corpus';
|
||||||
// $attachments['#attached']['drupalSettings']['basepath'] = base_path();
|
// // $attachments['#attached']['drupalSettings']['basepath'] = base_path();
|
||||||
// $attachments['#attached']['drupalSettings']['pathtoedlpcorpus'] = base_path() . drupal_get_path('module', 'edlp_corpus');
|
// // $attachments['#attached']['drupalSettings']['pathtoedlpcorpus'] = base_path() . drupal_get_path('module', 'edlp_corpus');
|
||||||
// $attachments['#attached']['drupalSettings']['pathtotfiles'] = PublicStream::basePath();
|
// // $attachments['#attached']['drupalSettings']['pathtotfiles'] = PublicStream::basePath();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -31,76 +31,30 @@ class BlockEntrees extends BlockBase {
|
|||||||
// dsm($terms);
|
// dsm($terms);
|
||||||
foreach ($terms as $term) {
|
foreach ($terms as $term) {
|
||||||
// dpm($term->toArray());
|
// dpm($term->toArray());
|
||||||
|
|
||||||
$tid = $term->id();
|
$tid = $term->id();
|
||||||
$name = $term->getName();
|
$name = $term->getName();
|
||||||
|
|
||||||
$term_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]);
|
$entree = array(
|
||||||
$term_link = Link::fromTextAndUrl($name, $term_url)->toRenderable();
|
'tid'=>$tid
|
||||||
$term_link['#prefix'] = '<span class="oblique-wrapper">';
|
|
||||||
$term_link['#suffix'] = "</span>";
|
|
||||||
$term_link["#attributes"] = array(
|
|
||||||
"class" => array('term-'.$term->id(), 'term-link'),
|
|
||||||
"tid" => $term->id()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$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_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]);
|
||||||
$index_link = Link::fromTextAndUrl('index', $index_url)->toRenderable();
|
$entree['index_link'] = Link::fromTextAndUrl('index', $index_url);
|
||||||
$index_link['#prefix'] = '<span class="oblique-wrapper">';
|
|
||||||
$index_link['#suffix'] = "</span>";
|
|
||||||
$index_link['#attributes'] = array(
|
|
||||||
'class' => array('index-link'),
|
|
||||||
"tid" => $term->id()
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$notice_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]);
|
$notice_url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]);
|
||||||
$notice_link = Link::fromTextAndUrl('notice', $notice_url)->toRenderable();
|
$entree['notice_link'] = Link::fromTextAndUrl('notice', $notice_url);
|
||||||
$notice_link['#prefix'] = '<span class="oblique-wrapper">';
|
|
||||||
$notice_link['#suffix'] = "</span>";
|
|
||||||
$notice_link['#attributes'] = array(
|
|
||||||
'class' => array('notice-link'),
|
|
||||||
"tid" => $term->id()
|
|
||||||
);
|
|
||||||
|
|
||||||
$description = $term->get('description')->value;
|
$entree['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);
|
|
||||||
|
|
||||||
$entrees[] = $entree;
|
$entrees[] = $entree;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array (
|
return array (
|
||||||
'#theme' => 'item_list',
|
'#theme' => 'blockentrees',
|
||||||
'#items' => $entrees,
|
'#entrees_items' => $entrees,
|
||||||
'#attached'=>array(
|
'#attached'=>array(
|
||||||
'library' => array('edlp_corpus/corpus'),
|
'library' => array('edlp_corpus/corpus'),
|
||||||
'drupalSettings' => array(
|
'drupalSettings' => array(
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
{{ entrees }}
|
||||||
Reference in New Issue
Block a user