entrees index and notice are ajax loaed and displayed
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user