Skip to content

Commit 95d25d8

Browse files
author
Simon L. Lange
committed
Merge branch 'develop' of github.com:OS2web/os2web8 into develop
2 parents 88ed011 + e1ff882 commit 95d25d8

File tree

2 files changed

+78
-35
lines changed

2 files changed

+78
-35
lines changed

web/themes/custom/fds_faxe_theme/fds_faxe_theme.theme

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,62 @@ function node2box(&$node, $showImages, $incPromoted) {
304304
return $refNode;
305305
}
306306

307+
function tax2box(&$taxonomy, $showImages, $showRelated) {
307308

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+
}
308363
function fds_faxe_theme_preprocess_paragraph(&$variables) {
309364

310365
$paragraph = $variables['paragraph'];
@@ -314,6 +369,7 @@ function fds_faxe_theme_preprocess_paragraph(&$variables) {
314369
$showImages = ($paragraph->field_os2web_menu_box_vm->value == 'image');
315370
$incPromoted = ($paragraph->field_os2web_menu_links_inc_pr_p->value == 1);
316371
$onlyTaxonomy = ($paragraph->field_only_taxonomy->value == 1);
372+
$showTaxonomyRelated = ($paragraph->field_show_taxonomy_related->value == 1);
317373

318374
$showReferences = null;
319375
if ($paragraph->hasField('field_show_references')) {
@@ -323,19 +379,35 @@ function fds_faxe_theme_preprocess_paragraph(&$variables) {
323379
$variables['menubox'] = [];
324380
$node = \Drupal::routeMatch()->getParameter('node');
325381

382+
// if current page is a node
326383
if ($node instanceof \Drupal\node\NodeInterface) {
327384

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
328402
$aliasManager = \Drupal::service('path_alias.manager');
329403
foreach ($paragraph->field_sektion->referencedEntities() as $taxonomy) {
330-
331404
$refNode = new stdClass();
332405
$refNode->title = (string) $taxonomy->name->value;
333406
$refNode->url = $aliasManager->getAliasByPath('/taxonomy/term/' . $taxonomy->id());
334407
$refNode->image = null;
335408
$refNode->children = array();
336409

337410
if ($showImages) {
338-
339411
if ($taxonomy->hasField('field_primaryicon')
340412
&& $taxonomy->field_primaryicon instanceof EntityReferenceFieldItemListInterface
341413
&& $taxonomy->field_primaryicon->referencedEntities()
@@ -378,10 +450,11 @@ function fds_faxe_theme_preprocess_paragraph(&$variables) {
378450
}
379451

380452
if (!$onlyTaxonomy && $node->hasField('field_link_til_andet_indhold')) {
381-
382453
$refs = $node->get('field_link_til_andet_indhold');
383454
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+
}
385458
}
386459
}
387460

@@ -405,7 +478,6 @@ function fds_faxe_theme_preprocess_paragraph(&$variables) {
405478
}
406479
}
407480
}
408-
409481
}
410482
}
411483

web/themes/custom/fds_faxe_theme/templates/paragraph/menu-box-paragraph/paragraph--os2web-menu-box-paragraph.html.twig

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<div class="row">
1212
{% for menu_link in menubox %}
13-
<div class="col-12 col-sm-6 col-md-4">
13+
<div class="col-12 col-sm-6 col-md-3">
1414
<div class="box box--section-link">
1515
<div class="box__heading" >
1616
{% set rendered_content = menu_link.image|render %}
@@ -33,35 +33,6 @@
3333
{% endfor %}
3434
</div>
3535

36-
{# <div class="row">#}
37-
{# {% for menu_link in _context['#menu_links'] %}#}
38-
<div class="col-12 col-sm-6 col-md-4">
39-
<div class="box box--section-link">
40-
<div class="box__heading" >
41-
{% set rendered_content = menu_link.content.field_os2web_icon|render %}
42-
{% if rendered_content %}
43-
{{ rendered_content }}
44-
{% endif %}
45-
</div>
46-
47-
{# <div class="box__body">#}
48-
{# <a href="{{ menu_link.url }}">{{ menu_link.title }}</a>#}
49-
50-
{# {% if menu_link['children']|length %}#}
51-
{# <ul>#}
52-
{# {% for node_link in menu_link['children'] %}#}
53-
{# <li><a href="{{ node_link.url }}">{{ node_link.title }}</a></li>#}
54-
{# {% endfor %}#}
55-
{# </ul>#}
56-
{# {% endif %}#}
57-
{# </div>#}
58-
{# </div>#}
59-
{# </div>#}
60-
{# {% endfor %}#}
61-
{# </div>#}
62-
63-
64-
6536
{% endblock %}
6637
</div>
6738
{% endblock paragraph %}

0 commit comments

Comments
 (0)