@@ -304,7 +304,62 @@ function node2box(&$node, $showImages, $incPromoted) {
304
304
return $refNode;
305
305
}
306
306
307
+ function tax2box(&$taxonomy, $showImages, $showRelated) {
307
308
309
+ $aliasManager = \Drupal::service('path_alias.manager');
310
+
311
+ $refNode = new stdClass();
312
+ $refNode->title = (string) $taxonomy->name->value;
313
+ $refNode->url = $aliasManager->getAliasByPath('/taxonomy/term/' . $taxonomy->id());
314
+ $refNode->image = null;
315
+ $refNode->children = array();
316
+
317
+ if ($showImages) {
318
+ if ($taxonomy->hasField('field_primaryicon')
319
+ && $taxonomy->field_primaryicon instanceof EntityReferenceFieldItemListInterface
320
+ && $taxonomy->field_primaryicon->referencedEntities()
321
+ ) {
322
+ $refNode->image = $taxonomy->field_primaryicon->view([
323
+ 'label' => 'hidden',
324
+ 'type' => 'image',
325
+ 'settings' => [
326
+ 'image_style' => 'thumbnail'
327
+ ],
328
+ ]);
329
+ }
330
+ elseif ($taxonomy->hasField('field_primaryimage')
331
+ && $taxonomy->field_primaryimage instanceof EntityReferenceFieldItemListInterface
332
+ && $taxonomy->field_primaryimage->referencedEntities()
333
+ ) {
334
+ $refNode->image = $taxonomy->field_primaryimage->view([
335
+ 'label' => 'hidden',
336
+ 'type' => 'image',
337
+ 'settings' => [
338
+ 'image_style' => 'thumbnail'
339
+ ],
340
+ ]);
341
+ }
342
+ }
343
+
344
+ if ($showRelated && $taxonomy->hasField('field_os2web_base_field_related')) {
345
+ $relatedes = $taxonomy->get('field_os2web_base_field_related')->referencedEntities();
346
+ if (count($relatedes) > 0) {
347
+ foreach ( $relatedes AS $related ) {
348
+ if ( $related->getType() == 'os2web_page') {
349
+ $relatedNode = \Drupal\node\Entity\Node::load($related->id());
350
+ $refNode->children[] = (object) array(
351
+ 'title' => $relatedNode->getTitle(),
352
+ 'url' => $relatedNode->toUrl()->toString()
353
+ );
354
+ }
355
+ }
356
+ }
357
+ }
358
+
359
+
360
+ return $refNode;
361
+
362
+ }
308
363
function fds_faxe_theme_preprocess_paragraph(&$variables) {
309
364
310
365
$paragraph = $variables['paragraph'];
@@ -314,6 +369,7 @@ function fds_faxe_theme_preprocess_paragraph(&$variables) {
314
369
$showImages = ($paragraph->field_os2web_menu_box_vm->value == 'image');
315
370
$incPromoted = ($paragraph->field_os2web_menu_links_inc_pr_p->value == 1);
316
371
$onlyTaxonomy = ($paragraph->field_only_taxonomy->value == 1);
372
+ $showTaxonomyRelated = ($paragraph->field_show_taxonomy_related->value == 1);
317
373
318
374
$showReferences = null;
319
375
if ($paragraph->hasField('field_show_references')) {
@@ -323,19 +379,35 @@ function fds_faxe_theme_preprocess_paragraph(&$variables) {
323
379
$variables['menubox'] = [];
324
380
$node = \Drupal::routeMatch()->getParameter('node');
325
381
382
+ // if current page is a node
326
383
if ($node instanceof \Drupal\node\NodeInterface) {
327
384
385
+ if ($node->hasField('field_os2web_page_section')) {
386
+ $sections = $node->get('field_os2web_page_section')->referencedEntities();
387
+ if (count($sections) > 0) {
388
+ // there is only one but can be change in future ..
389
+ foreach ($sections as $section) {
390
+ $children = \Drupal::entityTypeManager()
391
+ ->getStorage('taxonomy_term')
392
+ ->loadTree('os2web_sektion', $section->tid->value, 1, true);
393
+
394
+ foreach( $children AS $child ) {
395
+ $variables['menubox'][] = tax2box($child, $showImages, $showTaxonomyRelated);
396
+ }
397
+ }
398
+ }
399
+ }
400
+
401
+ // Get all in section list
328
402
$aliasManager = \Drupal::service('path_alias.manager');
329
403
foreach ($paragraph->field_sektion->referencedEntities() as $taxonomy) {
330
-
331
404
$refNode = new stdClass();
332
405
$refNode->title = (string) $taxonomy->name->value;
333
406
$refNode->url = $aliasManager->getAliasByPath('/taxonomy/term/' . $taxonomy->id());
334
407
$refNode->image = null;
335
408
$refNode->children = array();
336
409
337
410
if ($showImages) {
338
-
339
411
if ($taxonomy->hasField('field_primaryicon')
340
412
&& $taxonomy->field_primaryicon instanceof EntityReferenceFieldItemListInterface
341
413
&& $taxonomy->field_primaryicon->referencedEntities()
@@ -378,10 +450,11 @@ function fds_faxe_theme_preprocess_paragraph(&$variables) {
378
450
}
379
451
380
452
if (!$onlyTaxonomy && $node->hasField('field_link_til_andet_indhold')) {
381
-
382
453
$refs = $node->get('field_link_til_andet_indhold');
383
454
foreach ($refs->referencedEntities() as $idx => $ref) {
384
- $variables['menubox'][] = node2box($ref, $showImages, $incPromoted);;
455
+ if ($ref->getType() == 'os2web_page') {
456
+ $variables['menubox'][] = node2box($ref, $showImages, $incPromoted);;
457
+ }
385
458
}
386
459
}
387
460
@@ -405,7 +478,6 @@ function fds_faxe_theme_preprocess_paragraph(&$variables) {
405
478
}
406
479
}
407
480
}
408
-
409
481
}
410
482
}
411
483
0 commit comments