Skip to content

Commit ba72202

Browse files
committed
Add table_of_contents for chapter articles
Refs #27283
1 parent ddf017a commit ba72202

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

minimal.theme

+19-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,25 @@ function minimal_preprocess_node(&$variables) {
279279
if(\Drupal::routeMatch()->getParameter('node')){
280280
$node = \Drupal::routeMatch()->getParameter('node');
281281
$ntype = $node->getType();
282-
if($ntype == 'blog_post'){
282+
$table_of_contents_map = array(
283+
'article_chapitre' => 'block_3',
284+
'chapitre' => 'block_1',
285+
'livre' => 'block_2',
286+
);
287+
if (array_key_exists($ntype, $table_of_contents_map)) {
288+
$args = [$node->nid->value];
289+
$view = \Drupal\views\Views::getView('table_matieres_article_livre');
290+
// @see https://drupal.stackexchange.com/a/259795
291+
if (is_object($view)) {
292+
$view->setArguments($args);
293+
$view->setDisplay($table_of_contents_map[$ntype]);
294+
$view->preExecute();
295+
$view->execute();
296+
$variables['table_of_contents'] = $view->buildRenderable(
297+
$table_of_contents_map[$ntype], $args);
298+
}
299+
}
300+
if($ntype == 'blog_post'){
283301
//related posts start
284302
//kint($node->field_category);
285303
$tids = array();

templates/node/node--article-chapitre.html.twig

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ set classes = [
138138
</div>
139139
<aside class="sidebar mi-menu fixed-area one-page-menu" data-topscroll="80" style="width: 263px;">
140140
<nav class="sidebar-nav">
141+
{{ table_of_contents }}
141142
TABLE DES MATIÈRES<br />
142143
À VENIR
143144
</nav>

0 commit comments

Comments
 (0)