Skip to content

Commit 6ca1c51

Browse files
committed
FAXE-332 update to use content pages insted of taxonomy pages
1 parent ba5a160 commit 6ca1c51

File tree

1 file changed

+34
-173
lines changed

1 file changed

+34
-173
lines changed

web/themes/custom/fds_faxe_theme/fds_faxe_theme.theme

Lines changed: 34 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ function fds_faxe_theme_preprocess_media(array &$variables) {
226226

227227

228228

229-
function node2box(&$node, $showImages, $incPromoted) {
229+
function node2box(&$node, $showImages) {
230230

231231
$refNode = new stdClass();
232232
$refNode->title = (string) $node->field_os2web_page_heading->value;
@@ -273,93 +273,9 @@ function node2box(&$node, $showImages, $incPromoted) {
273273
}
274274
}
275275

276-
$menu_link_root_entities = \Drupal::entityTypeManager()
277-
->getStorage('menu_link_content')
278-
->loadByProperties([
279-
'link' => ['uri' => 'entity:node/' . $node->id()],
280-
]);
281-
282-
$menu_link_root = reset($menu_link_root_entities);
283-
if ($menu_link_root) {
284-
$menu_links = \Drupal::service('menu.tree_storage')
285-
->loadByProperties([
286-
'parent' => 'menu_link_content:' . $menu_link_root->uuid(),
287-
]) ?: [];
288-
289-
$node_ids = array_map(function ($v) {
290-
return $v['route_parameters']['node'];
291-
}, $menu_links);
292-
293-
foreach ($node_ids as $childId) {
294-
$child = \Drupal\node\Entity\Node::load($childId);
295-
if ($child->getType() == 'os2web_page' && ($incPromoted && $child->isPromoted())) {
296-
$refNode->children[] = (object) [
297-
'title' => $child->getTitle(),
298-
'url' => $child->toUrl()->toString()
299-
];
300-
}
301-
}
302-
}
303-
304-
return $refNode;
305-
}
306-
307-
function tax2box(&$taxonomy, $showImages, $showRelated) {
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-
360276
return $refNode;
361-
362277
}
278+
363279
function fds_faxe_theme_preprocess_paragraph(&$variables) {
364280

365281
$paragraph = $variables['paragraph'];
@@ -368,13 +284,6 @@ function fds_faxe_theme_preprocess_paragraph(&$variables) {
368284

369285
$showImages = ($paragraph->field_os2web_menu_box_vm->value == 'image');
370286
$incPromoted = ($paragraph->field_os2web_menu_links_inc_pr_p->value == 1);
371-
$onlyTaxonomy = ($paragraph->field_only_taxonomy->value == 1);
372-
$showTaxonomyRelated = ($paragraph->field_show_taxonomy_related->value == 1);
373-
374-
$showReferences = null;
375-
if ($paragraph->hasField('field_show_references')) {
376-
$showReferences = ($paragraph->field_show_references->value == 1);
377-
}
378287

379288
$variables['menubox'] = [];
380289
$node = \Drupal::routeMatch()->getParameter('node');
@@ -386,98 +295,50 @@ function fds_faxe_theme_preprocess_paragraph(&$variables) {
386295
$sections = $node->get('field_os2web_page_section')->referencedEntities();
387296
if (count($sections) > 0) {
388297
// there is only one but can be change in future ..
298+
$storage = \Drupal::entityTypeManager()->getStorage('node');
389299
foreach ($sections as $section) {
300+
390301
$children = \Drupal::entityTypeManager()
391302
->getStorage('taxonomy_term')
392303
->loadTree('os2web_sektion', $section->tid->value, 1, true);
393-
394304
foreach( $children AS $child ) {
395-
$variables['menubox'][] = tax2box($child, $showImages, $showTaxonomyRelated);
396-
}
397-
}
398-
}
399-
}
400305

401-
// Get all in section list
402-
$aliasManager = \Drupal::service('path_alias.manager');
403-
foreach ($paragraph->field_sektion->referencedEntities() as $taxonomy) {
404-
$refNode = new stdClass();
405-
$refNode->title = (string) $taxonomy->name->value;
406-
$refNode->url = $aliasManager->getAliasByPath('/taxonomy/term/' . $taxonomy->id());
407-
$refNode->image = null;
408-
$refNode->children = array();
409-
410-
if ($showImages) {
411-
if ($taxonomy->hasField('field_primaryicon')
412-
&& $taxonomy->field_primaryicon instanceof EntityReferenceFieldItemListInterface
413-
&& $taxonomy->field_primaryicon->referencedEntities()
414-
) {
415-
$refNode->image = $taxonomy->field_primaryicon->view([
416-
'label' => 'hidden',
417-
'type' => 'image',
418-
'settings' => [
419-
'image_style' => 'thumbnail'
420-
],
421-
]);
422-
}
423-
elseif ($taxonomy->hasField('field_primaryimage')
424-
&& $taxonomy->field_primaryimage instanceof EntityReferenceFieldItemListInterface
425-
&& $taxonomy->field_primaryimage->referencedEntities()
426-
) {
427-
$refNode->image = $taxonomy->field_primaryimage->view([
428-
'label' => 'hidden',
429-
'type' => 'image',
430-
'settings' => [
431-
'image_style' => 'thumbnail'
432-
],
433-
]);
434-
}
435-
}
436-
437-
if ($incPromoted) {
438-
$child_terms = \Drupal::entityTypeManager()
439-
->getStorage('taxonomy_term')
440-
->loadTree('os2web_sektion', $taxonomy->id(), 1, FALSE);
441-
foreach ($child_terms as $child) {
442-
$refNode->children[] = (object) [
443-
'title' => $child->name,
444-
'url' => $aliasManager->getAliasByPath('/taxonomy/term/' . $child->tid)
445-
];
446-
}
447-
}
448-
449-
$variables['menubox'][] = $refNode;
450-
}
451-
452-
if (!$onlyTaxonomy && $node->hasField('field_link_til_andet_indhold')) {
453-
$refs = $node->get('field_link_til_andet_indhold');
454-
foreach ($refs->referencedEntities() as $idx => $ref) {
455-
if ($ref->getType() == 'os2web_page') {
456-
$variables['menubox'][] = node2box($ref, $showImages, $incPromoted);;
457-
}
458-
}
459-
}
460-
461-
if ($showReferences && $node->hasField('field_os2web_page_section')) {
462-
$sections = $node->get('field_os2web_page_section')->referencedEntities();
463-
if (count( $sections ) > 0) {
464-
// there is only one but can be change in future ..
465-
foreach( $sections AS $section ) {
466-
$refId = $section->tid->value;
467-
$storage = \Drupal::entityTypeManager()->getStorage('node');
468-
$query = $storage->getQuery()->condition('field_os2web_page_section.target_id', $refId);
469-
$references = $query->execute();
470-
if (count( $references ) > 0) {
471-
foreach ($references as $refNodeid) {
472-
if ($node->id() != $refNodeid) {
473-
$refNode = \Drupal\node\Entity\Node::load($refNodeid);
474-
$variables['menubox'][] = node2box($refNode, $showImages, $incPromoted);;
306+
// find primary node for this child
307+
if ($child->hasField('field_primarynode') && !empty($child->field_primarynode->target_id)) {
308+
$primaryNode = \Drupal\node\Entity\Node::load($child->field_primarynode->target_id);
309+
$entry = node2box($primaryNode, $showImages);
310+
311+
// find all node that has this taxonomy in section
312+
$query = $storage->getQuery()
313+
->condition('field_os2web_page_section.target_id', $child->tid->value)
314+
->execute();
315+
if (count($query) > 0) {
316+
foreach ($query as $nodeId) {
317+
$childNode = \Drupal\node\Entity\Node::load($nodeId);
318+
319+
if (
320+
$childNode->getType() == 'os2web_page' &&
321+
$childNode->isPublished() &&
322+
(
323+
!$childNode->isPromoted() ||
324+
($incPromoted && $childNode->isPromoted())
325+
) &&
326+
$childNode->id() !== $primaryNode->id()) {
327+
$entry->children[] = (object) [
328+
'title' => $childNode->getTitle(),
329+
'url' => $childNode->toUrl()->toString()
330+
];
331+
}
332+
}
475333
}
334+
335+
$variables['menubox'][] = $entry;
476336
}
477337
}
478338
}
479339
}
480340
}
341+
481342
}
482343
}
483344

0 commit comments

Comments
 (0)